-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
82 lines (65 loc) · 2.21 KB
/
setup.js
File metadata and controls
82 lines (65 loc) · 2.21 KB
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
/**
* @module babel-base/setup
* @author Nate Ferrero
*/
var fs = require('fs');
var path = require('path');
var readlineSync = require('readline-sync');
var print = function () {
console.log.apply(console, Array.prototype.slice.call(arguments));
};
var ask = function (what) {
return readlineSync.question(what + ' ');
};
var conditionallyCreateItem = function (selection, number, file, dir, contents) {
if (!(number in selection)) {
return;
}
var fullpath = path.join(process.cwd(), file);
if (fs.existsSync(fullpath)){
print('[#1] - The ./#2 #3 already exists, skipping!'
.replace('#1', number)
.replace('#2', file)
.replace('#3', dir ? 'directory' : 'file'));
}
else {
print('[#1] - Ok, creating the ./#2 #3'
.replace('#1', number)
.replace('#2', file)
.replace('#3', dir ? 'directory' : 'file'));
if (dir) {
fs.mkdirSync(fullpath);
}
else {
contents = Array.isArray(contents) ? contents.concat('').join('\n') : contents;
fs.writeFileSync(fullpath, contents);
}
print(' ...done!');
}
print();
}
print('Welcome to the babel-base setup utility!');
print();
print('Current directory:', '"' + process.cwd() + '"');
print();
print('I\'ll setup some directories and files to get you started:');
print();
print(' [1] - The ./src directory, containing your project source files');
print(' [2] - The ./gulpfile.js file, containing gulp configuration');
print(' [3] - The ./.gitignore file, to ignore the dist folder created by gulp');
print();
var selection = {};
selection[ask('Proceed? (y/n, or enter a number from the above list to run only that step)')] = true;
if ('y' in selection) {
selection['1'] = true;
selection['2'] = true;
selection['3'] = true;
}
print();
conditionallyCreateItem(selection, '1', 'src', true);
conditionallyCreateItem(selection, '2', 'gulpfile.js', false,
['var gulpInit = require(\'babel-base/module/gulp-init\');',
'var gulp = gulpInit();']);
conditionallyCreateItem(selection, '3', '.gitignore', false,
['node_modules', 'dist']);
print('Nothing else to do, goodbye!');