Skip to content
Open
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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*]
indent_size = 2
indent_style = space
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/dist
/node_modules
/test
/yarn-error.log
/.Ds_Store
yarn.lock
package-lock.json
30 changes: 21 additions & 9 deletions dist/createApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ var child_process_1 = require("child_process");
var chalk_1 = require("chalk");
var configTargets_1 = require("./configTargets");
var errorApp_1 = require("./errorApp");
var hasYarn = function () {
try {
child_process_1.execSync('yarnpkg --version', { stdio: 'ignore' });
return true;
}
catch (e) {
return false;
}
};
exports.createApp = function (_a) {
var name = _a.name, target = _a.target;
if (!name) {
Expand All @@ -24,21 +33,21 @@ exports.createApp = function (_a) {
};
var installPackages = function (name, dependency) {
var command = 'npm';
var args = [
'install',
'--save-dev'
].concat(dependency);
var useYarn = hasYarn();
if (useYarn) {
command = 'yarn';
}
var config = {
stdio: 'inherit',
shell: true
};
console.log('');
console.log('Installing packages for your application');
var child = child_process_1.spawn(command, args, config);
var child = child_process_1.spawn(command, ['install'], config);
child.on('close', function () {
console.log('');
console.log("Project " + chalk_1.default.green(name) + " created!");
console.log("use: cd " + chalk_1.default.green(name) + " and " + chalk_1.default.green('npm start'));
console.log("use: cd " + chalk_1.default.green(name) + " and " + (useYarn ? chalk_1.default.green('yarn dev') : chalk_1.default.green('npm run dev')));
console.log('');
});
};
Expand All @@ -49,15 +58,18 @@ var validationAppName = function (appName) {
if (!results.validForNewPackages) {
console.error("Could not create project named: " + chalk_1.default.red(appName));
console.log('please correct:');
results.errors.forEach(function (error) {
results.errors && results.errors.forEach(function (error) {
console.log(" " + chalk_1.default.red('*') + " " + error);
});
results.warnings && results.warnings.forEach(function (error) {
console.log(" " + chalk_1.default.red('*') + " " + error);
});
process.exit(1);
process.exit();
}
if (dependency.indexOf(appName) !== -1) {
console.error("Could not create project named " + chalk_1.default.red(appName) + ".");
console.error('Please change the name of the application, a dependency has the same name.');
process.exit(1);
process.exit();
}
};
var copyPackage = function (name, templateDir, root) {
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ inquirer
{
type: 'list',
name: 'target',
message: 'What config webpack?',
message: 'Which Webpack configuration?',
choices: configKeys.map(function (key) { return configTargets_1.configTargets[key].message; })
},
{
type: 'input',
name: 'name',
message: 'Name you project'
message: 'Name your project'
}
])
.then(function (response) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-webpack-application",
"version": "0.1.22",
"version": "0.1.23",
"description": "Easily create a basic webpack application",
"bin": {
"create-webpack-application": "./dist/index.js",
Expand Down
53 changes: 35 additions & 18 deletions src/createApp.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { resolve, basename, join } from 'path';
import { copySync, ensureDirSync } from 'fs-extra';
import { writeFileSync, readFileSync } from 'fs';
import { spawn } from 'child_process';
import { spawn, execSync } from 'child_process';
import chalk from 'chalk';
import { configTargets } from './configTargets';
import { errorApp } from './errorApp';

const hasYarn = (): boolean => {
try {
execSync('yarnpkg --version', { stdio: 'ignore' });
return true;
} catch(e) {
return false;
}
};

export const createApp = ({ name, target }): void => {
if(!name) {
errorApp(name);
Expand All @@ -22,24 +31,25 @@ export const createApp = ({ name, target }): void => {
}

const installPackages = (name:string, dependency: string[]): void => {
let command: string = 'npm';
let args: string[] = [
'install',
'--save-dev'
].concat(dependency);

let command = 'npm';
const useYarn = hasYarn();

if(useYarn) {
command = 'yarn';
}

let config = {
stdio: 'inherit',
shell: true
stdio: 'inherit',
shell: true
};

console.log('');
console.log('Installing packages for your application');
const child = spawn(command, args, config);
const child = spawn(command, ['install'], config as any);
child.on('close', () => {
console.log('');
console.log(`Project ${chalk.green(name)} created!`);
console.log(`use: cd ${chalk.green(name)} and ${chalk.green('npm start')}`);
console.log(`use: cd ${chalk.green(name)} and ${useYarn ? chalk.green('yarn dev'): chalk.green('npm run dev')}`);
console.log('');
});
}
Expand All @@ -48,18 +58,25 @@ const validationAppName = (appName: string): void => {
const validateProjectName = require( 'validate-npm-package-name');
let results = validateProjectName(appName);
let dependency = ['webpack', 'webpack-dev-server'];

if(!results.validForNewPackages){
console.error(`Could not create project named: ${chalk.red(appName)}`);
console.log('please correct:');
results.errors.forEach(error => {
console.log(` ${chalk.red('*')} ${error}`);
});
process.exit(1);
console.error(`Could not create project named: ${chalk.red(appName)}`);
console.log('please correct:');

results.errors && results.errors.forEach(error => {
console.log(` ${chalk.red('*')} ${error}`);
});

results.warnings && results.warnings.forEach(error => {
console.log(` ${chalk.red('*')} ${error}`);
});
process.exit();
}

if(dependency.indexOf(appName) !== -1){
console.error(`Could not create project named ${chalk.red(appName)}.`);
console.error('Please change the name of the application, a dependency has the same name.');
process.exit(1);
process.exit();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ inquirer
{
type: 'list',
name: 'target',
message: 'What config webpack?',
message: 'Which Webpack configuration?',
choices: configKeys.map(key => configTargets[key].message)
},
{
type: 'input',
name: 'name',
message: 'Name you project'
message: 'Name your project'
}
])
.then(response => {
Expand All @@ -28,4 +28,4 @@ inquirer
}
}
createApp(response);
});
});
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"src/**/*"
],
"exclude": [
"./node_modules",
"./node_modules"
]
}
}
Loading