Skip to content

Commit

Permalink
Merge pull request #35 from nobrainr/feat/template-as-npm-package
Browse files Browse the repository at this point in the history
Feat/template as npm package
  • Loading branch information
emyann authored Sep 28, 2018
2 parents 3c480dc + cfef19c commit 44208b6
Show file tree
Hide file tree
Showing 18 changed files with 15,241 additions and 6,673 deletions.
4 changes: 2 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"ignoreChanges": ["*.npmrc"]
}
},
"packages": ["packages/*"],
"version": "0.3.1"
"packages": ["packages/cli", "packages/e2e", "packages/templates/*"],
"version": "independent"
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "typescript-webpack-starter",
"version": "0.2.0",
"description": "A damn simple starter for Typescript and Webpack",
"description": "",
"private": true,
"main": "src/index.ts",
"scripts": {
"build": "lerna bootstrap",
"update-cli-in-e2e": "lerna add create-ts-lib packages/e2e",
"update-cli-in-e2e": "lerna add create-ts-lib --scope=e2e --dev --exact",
"test": "cd packages/e2e && npm test",
"publish": "lerna run publish-cli"
},
Expand Down
50 changes: 35 additions & 15 deletions packages/cli/createTsLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,42 @@ 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,
filter: function(path) {
return path.indexOf(`${templateName}/node_modules`) === -1;
}
});
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
Loading

0 comments on commit 44208b6

Please sign in to comment.