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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"webpack": "^2.3.3",
"webpack-dev-server": "^2.4.5",
"webpack-plugin-replace": "^1.1.1",
"which": "^1.2.14",
"yargs": "^8.0.1"
}
}
34 changes: 32 additions & 2 deletions src/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ora from 'ora';
import promisify from 'es6-promisify';
import spawn from 'cross-spawn-promise';
import path from 'path';
import which from 'which';

const TEMPLATES = {
default: 'examples/full',
Expand Down Expand Up @@ -148,9 +149,11 @@ export default asyncCommand({
]);

spinner.succeed('Done!\n');

await initializeVersionControl(target);
}

return `
return trimLeft(`
To get started, cd into the new directory:
\u001b[32mcd ${path.relative(process.cwd(), target)}\u001b[39m

Expand All @@ -162,9 +165,36 @@ export default asyncCommand({

To start a production HTTP/2 server:
\u001b[32mnpm run serve\u001b[39m
`.trim().replace(/^\t+/gm, '') + '\n';
`) + '\n';
}
});

const trimLeft = (string) => string.trim().replace(/^\t+/gm, '');

const npm = (cwd, args) => spawn('npm', args, { cwd, stdio: 'ignore' });

// Initializes the folder using `git init` and a proper `.gitignore` file
// if `git` is present in the $PATH.
async function initializeVersionControl(target) {
let git;
try {
git = await promisify(which)('git');
} catch (e) {}
if (git) {
const gitignore = trimLeft(`
node_modules
/build
/*.log
`) + '\n';
const gitignorePath = path.resolve(target, '.gitignore');
await fs.writeFile(gitignorePath, gitignore);

const cwd = target;

await spawn('git', ['init'], { cwd });
await spawn('git', ['add', '-A'], { cwd });

const gitUser = 'Preact CLI<[email protected]>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh - I am wondering if this will spam me with notifications 😆

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of dear !! That sure will. Good luck with that !!

await spawn('git', ['commit', '--author', gitUser, '-m', 'initial commit from Preact CLI'], { cwd });
}
}