-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathcreate.js
98 lines (88 loc) · 2.81 KB
/
create.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict';
const fs = require('fs');
const copySync = require('fs-extra').copySync;
const path = require('path');
const chalk = require('chalk');
const spawn = require('cross-spawn');
const argv = require('minimist')(process.argv.slice(2));
const commands = argv._;
const isWindows = process.platform === 'win32';
if (commands.length === 0 || commands[0] === '') {
console.log();
console.error('Usage: elm-app create <project-directory>');
process.exit(1);
}
createElmApp(commands[0]);
function createElmApp(name) {
console.log();
console.log('Creating ' + name + ' project...');
console.log();
const appRoot = path.resolve(name.toString());
const template = path.join(__dirname, '../template');
if (!fs.existsSync(name)) {
try {
copySync(template, appRoot);
fs.renameSync(
path.resolve(appRoot, 'gitignore'),
path.resolve(appRoot, '.gitignore')
);
} catch (err) {
console.log(err);
process.exit(1);
}
} else {
console.log('The directory ' + name + ' already exists. Aborting.');
process.exit(1);
}
// Run initial `elm make`
const spawnElmPkgResult = spawn.sync(
path.resolve(__dirname, '../node_modules/.bin/elm'),
// Run elm-make to install the dependencies.
['make', 'src/Main.elm', '--output=/dev/null'],
{ stdio: 'inherit', cwd: appRoot }
);
if (spawnElmPkgResult.status !== 0) {
console.log();
console.log(chalk.red('Failed to install elm packages'));
console.log();
console.log('Please, make sure you have internet connection!');
if (!isWindows) {
console.log();
console.log(
'In case if you are running Unix OS, you might look in to this issue:'
);
console.log();
console.log(' https://github.com/halfzebra/create-elm-app/issues/10');
}
process.exit(1);
}
console.log();
console.log(
chalk.green('Project is successfully created in `' + appRoot + '`.')
);
console.log();
console.log('Inside that directory, you can run several commands:');
console.log();
console.log(chalk.cyan(' elm-app start'));
console.log(' Starts the development server.');
console.log();
console.log(chalk.cyan(' elm-app build'));
console.log(' Bundles the app into static files for production.');
console.log();
console.log(chalk.cyan(' elm-app test'));
console.log(' Starts the test runner.');
console.log();
console.log(chalk.cyan(' elm-app eject'));
console.log(
' Removes this tool and copies build dependencies, configuration files'
);
console.log(
' and scripts into the app directory. If you do this, you can’t go back!'
);
console.log();
console.log('We suggest that you begin by typing:');
console.log();
console.log(chalk.cyan(' cd'), name);
console.log(' ' + chalk.cyan('elm-app start'));
console.log();
}