Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions 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
4 changes: 4 additions & 0 deletions 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
30 changes: 30 additions & 0 deletions src/commands/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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);
repos = await repos.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);
}
}
});
4 changes: 4 additions & 0 deletions 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
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
10 changes: 6 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,11 @@ yargs
.command(build)
.command(watch)
.command(serve)
.option('cwd', {
description: 'A directory to use instead of $PWD.',
defaultDescription: '.'
})
.command(list)
// .option('cwd', {
// description: 'A directory to use instead of $PWD.',
// defaultDescription: '.'
// })
.usage(logo(`\n\npreact-cli ${pkg.version}`) + `\nFor help with a specific command, enter:\n preact help [command]`)
.help()
.alias('h', 'help')
Expand Down