This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
forked from marekbrainhub/hadron-collider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·64 lines (50 loc) · 1.93 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
const inquirer = require('inquirer');
const camelCase = require('camelcase');
const fs = require('fs-extra');
const path = require('path');
const {
createDirectoryContents,
clearEmptyFiles,
runPackageManager,
runLinter,
} = require('./utils');
const questions = require('./questions');
const pwd = process.cwd();
inquirer.prompt(questions).then(async answers => {
answers.camelCasePackages = answers.packages.map(el => camelCase(el));
console.log('Creating the project directory...');
let projectPath = path.resolve(pwd, answers.projectName);
fs.mkdirSync(projectPath);
if (answers.babel) {
projectPath = path.resolve(projectPath, 'src');
fs.mkdirSync(projectPath);
}
console.log('Copying template files into the project directory...');
createDirectoryContents(path.resolve(__dirname, 'templates'), projectPath, answers);
console.log('Removing residual files...');
clearEmptyFiles(projectPath);
if (answers.babel) {
console.log('Unpacking babel...');
projectPath = path.resolve(projectPath, '..');
const babelPath = path.resolve(__dirname, 'babel-templates');
const filesToCreate = fs.readdirSync(babelPath);
filesToCreate.forEach(file => {
fs.copyFileSync(path.resolve(babelPath, file), path.resolve(projectPath, file));
});
fs.moveSync(path.resolve(projectPath, 'src', 'package.json'), path.resolve(projectPath, 'package.json'));
}
if (answers.packageManager !== 'none') {
console.log('Running pacakge manager...\n');
await runPackageManager(answers.packageManager, answers.projectName);
}
if (answers.linter !== 'none' && answers.packageManager !== 'none') {
console.log('Runing linter...');
await runLinter(answers.projectName);
}
console.log('\nDone!\n');
console.log('You can now enter your project and start development:\n');
console.log(` cd ${answers.projectName}`);
console.log(' npm run dev');
console.log('\n');
});