Skip to content

Commit

Permalink
feat: CLI now fetch template from NPM
Browse files Browse the repository at this point in the history
  • Loading branch information
emyann committed Sep 28, 2018
1 parent 52a57c7 commit 9d12020
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions packages/cli/createTsLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,37 @@ function createApp(name) {
run(root, appName, originalDirectory);
}

function run(root, appName, originalDirectory) {
const templatePath = path.resolve(__dirname, 'template');
if (fs.existsSync(templatePath)) {
fs.copySync(templatePath, root);
let packageJsonPath = path.join(root, 'package.json');
let packageJson = require(packageJsonPath);
packageJson.name = appName;
packageJson.version = '0.0.1';

fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
console.log('Installing packages. This might take a couple of minutes.');
return install();
} else {
console.error(`Could not locate supplied template: ${chalk.green(templatePath)}`);
return;
async function run(root, appName, originalDirectory) {
function installTemplate(templateName) {
try {
console.log('loading template', templateName);
const res = require('child_process')
.execSync(`npm install ${templateName}`)
.toString()
.trim();
console.log(`${templateName} loaded successfully`);
} catch (e) {
console.log(`${templateName} err`);
}
}
const templateName = '@nobrainr/typescript_universal-webpack-karma_jasmine';
const templatePath = path.resolve(__dirname, 'node_modules', templateName);
if (!fs.existsSync(templatePath)) {
try {
installTemplate(templateName);
} catch (e) {
console.log(e);
}
}
fs.copySync(templatePath, root, { dereference: true });
let packageJsonPath = path.join(root, 'package.json');
let packageJson = require(packageJsonPath);
packageJson.name = appName;
packageJson.version = '0.0.1';

fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
console.log('Installing packages. This might take a couple of minutes.');
return await install();
}

function install() {
Expand Down

0 comments on commit 9d12020

Please sign in to comment.