UNPKG

1.9 kBJavaScriptView Raw
1'use strict';
2
3const path = require('path');
4const chalk = require('chalk');
5
6const input = require('./input');
7const validate = require('./validate');
8const rename = require('./rename');
9const install = require('./install');
10
11
12// 1. Get and validate the project name
13const { projectName, includeEditor } = input.getProjectName();
14validate.checkProjectName(projectName);
15
16
17// 2. Create the directory
18const appRoot = path.resolve(projectName);
19install.createDir(appRoot);
20
21
22// 3. Check for file conflicts
23validate.checkFileConflicts(appRoot);
24console.log(`Creating a new Cloud Block in ${chalk.green(appRoot)}`);
25
26
27// 4. Copy files from the example
28console.log('Extracting example files');
29install.copyExample(appRoot);
30install.addGitIgnore(appRoot);
31
32
33// 5. Rename the project files
34const appName = path.basename(appRoot);
35
36rename.updatePkg(appRoot, projectName, includeEditor);
37rename.updateFiles(appRoot, appName);
38rename.renameBlock(appRoot, appName);
39
40
41// 6. Install packages
42console.log('Installing packages. This might take a couple of minutes.');
43install.runNPM(appRoot);
44
45
46// 7. Cleanup and finish
47console.log(`Success! Created ${chalk.green(projectName)} at ${appRoot}`);
48console.log(`Inside that directory, you can run several commands:`);
49if(includeEditor) {
50 console.log();
51 console.log(` ${chalk.cyan('npm start')}`);
52 console.log(` Starts the development editor (no live reload currently).`);
53}
54console.log();
55console.log(` ${chalk.cyan('npm run build')}`);
56console.log(` Bundles the app into static files for production.`);
57console.log();
58console.log(` ${chalk.cyan('npm publish')}`);
59console.log(` Publish the production static files to NPM.`);
60console.log();
61console.log(`You can start by typing:`);
62console.log(` ${chalk.cyan('cd')} ${chalk.green(projectName)}`);
63if(includeEditor) {
64 console.log(` ${chalk.cyan('npm start')}`);
65}
66console.log();
67console.log('🚀');