Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export default asyncCommand({
desc: 'Create a production build in build/',

builder: {
cwd: {
description: 'A directory to use instead of $PWD.',
default: '.'
},
src: {
description: 'Entry file (index.js)',
default: 'src'
Expand Down Expand Up @@ -49,7 +53,7 @@ export default asyncCommand({
},

async handler(argv) {
let cwd = argv.cwd ? resolve(argv.cwd) : process.cwd();
let cwd = resolve(argv.cwd);
let modules = resolve(cwd, 'node_modules');

if (!isDir(modules)) {
Expand Down
6 changes: 5 additions & 1 deletion src/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default asyncCommand({
desc: 'Create a new application.',

builder: {
cwd: {
description: 'A directory to use instead of $PWD.',
default: '.'
},
name: {
description: 'The application\'s name'
},
Expand Down Expand Up @@ -52,8 +56,8 @@ export default asyncCommand({
Object.assign(argv, response);
}

let cwd = resolve(argv.cwd);
let isYarn = argv.yarn && hasCommand('yarn');
let cwd = argv.cwd ? resolve(argv.cwd) : process.cwd();
let target = argv.dest && resolve(cwd, argv.dest);
let exists = target && isDir(target);

Expand Down
29 changes: 29 additions & 0 deletions src/commands/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import fetch from 'isomorphic-unfetch';
import { bold, magenta } from 'chalk';
import { error, info } from '../util';
import asyncCommand from '../lib/async-command';

const REPOS_URL = "https://api.github.com/users/preactjs-templates/repos";

export default asyncCommand({
command: 'list',

desc: 'List all official templates',

async handler() {
try {
let repos = await fetch(REPOS_URL).then(r => r.json());

process.stdout.write('\n');
info('Available official templates: \n');

repos.map(repo => {
process.stdout.write(` ⭐️ ${bold(magenta(repo.name))} - ${repo.description} \n`);
});

process.stdout.write('\n');
} catch (err) {
error(err, 1);
}
}
});
6 changes: 5 additions & 1 deletion src/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default asyncCommand({
desc: 'Start an HTTP2 static fileserver.',

builder: {
cwd: {
description: 'A directory to use instead of $PWD.',
default: '.'
},
dir: {
description: 'Directory root to serve static files from.',
default: 'build'
Expand Down Expand Up @@ -52,7 +56,7 @@ export default asyncCommand({
* @param {number|string} [options.port] Port to start the http server on
*/
async function serve(options) {
let dir = path.resolve(options.cwd || process.cwd(), options.dir || '.');
let dir = path.resolve(options.cwd, options.dir || '.');

// Allow overriding default hosting config via `--config firebase.json`:
let configFile = options.config ? options.config : path.resolve(__dirname, '../resources/static-app.json');
Expand Down
4 changes: 4 additions & 0 deletions src/commands/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export default asyncCommand({
desc: 'Start a development live-reload server.',

builder: {
cwd: {
description: 'A directory to use instead of $PWD.',
default: '.'
},
src: {
description: 'Entry file (index.js)',
default: 'src'
Expand Down
6 changes: 2 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import create from './commands/create';
import build from './commands/build';
import watch from './commands/watch';
import serve from './commands/serve';
import list from './commands/list';
import installHooks from './lib/output-hooks';
import pkg from '../package.json';
import logo from './lib/logo';
Expand All @@ -24,10 +25,7 @@ yargs
.command(build)
.command(watch)
.command(serve)
.option('cwd', {
description: 'A directory to use instead of $PWD.',
defaultDescription: '.'
})
.command(list)
.usage(logo(`\n\npreact-cli ${pkg.version}`) + `\nFor help with a specific command, enter:\n preact help [command]`)
.help()
.alias('h', 'help')
Expand Down