1 | 'use strict';
|
2 |
|
3 | const Listr = require('listr');
|
4 | const path = require('path');
|
5 | const chalk = require('chalk');
|
6 | const pathExists = require('path-exists');
|
7 | const stage = require('./stage');
|
8 |
|
9 | const npm = require('./npm');
|
10 |
|
11 | function rootTasks(projectName, template) {
|
12 | let projectPath;
|
13 |
|
14 | const tasks = new Listr([
|
15 | {
|
16 | title: 'Create your Project',
|
17 | task : () => {
|
18 | const project = path.resolve(projectName);
|
19 |
|
20 | if (!pathExists.sync(project)) {
|
21 | projectPath = stage.createProject(project);
|
22 | process.chdir(projectPath);
|
23 | }
|
24 | else {
|
25 | throw new Error(`${projectName} already exists ;(`);
|
26 | }
|
27 | }
|
28 | },
|
29 | {
|
30 | title: 'Install packages of the template',
|
31 | task : () => npm.installTemplates(template.url)
|
32 | },
|
33 | {
|
34 | title: 'Make the template',
|
35 | task : () => stage.copyTemplate(template.url)
|
36 | },
|
37 | {
|
38 | title: 'Rename ignorefile',
|
39 | task : () => stage.renameIgnoreFile()
|
40 | },
|
41 | {
|
42 | title: 'Create package.json',
|
43 | task : () => npm.createPackageJSON(projectName, projectPath, template.url)
|
44 | },
|
45 | {
|
46 | title: 'Install packages',
|
47 | task : () => npm.installPackages(template.url)
|
48 | },
|
49 | {
|
50 | title: 'Delete templates from node_modules',
|
51 | task : () => npm.uninstallTemplates(template.url)
|
52 | }
|
53 | ]);
|
54 |
|
55 | tasks
|
56 | .run()
|
57 | .then(() => {
|
58 | console.log();
|
59 | console.log(`$ cd ${projectName}`);
|
60 | console.log('$ npm start');
|
61 | console.log();
|
62 | console.log(chalk.green('Have a nice time :)'));
|
63 | })
|
64 | .catch((err) => {
|
65 | console.error(chalk.red(err));
|
66 | });
|
67 | }
|
68 |
|
69 | module.exports = rootTasks;
|