-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·105 lines (98 loc) · 3.11 KB
/
Copy pathindex.js
File metadata and controls
executable file
·105 lines (98 loc) · 3.11 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env node
import chalk from 'chalk';
import gulp from 'gulp';
import inquirer from 'inquirer';
import iniparser from 'iniparser';
import rename from 'gulp-rename';
import shell from 'gulp-shell';
import tap from 'gulp-tap';
import template from 'gulp-template';
import filter from 'gulp-filter';
import fs from 'fs';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const handleDefaults = answers => answers;
const defaults = (() => {
const homeDir = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
const workingDirName = process.cwd().split('/').pop().split('\\').pop();
const osUserName = (homeDir && homeDir.split('/').pop()) || 'root';
const configFile = `${homeDir}/.gitconfig`;
let user = {};
if (fs.existsSync(configFile)) {
user = iniparser.parseSync(configFile).user;
} // end if
return {
appName: workingDirName,
userName: user.name || osUserName,
authorEmail: user.email || ''
};
})();
inquirer.prompt([
{
name: 'name',
message: 'Give your app a name',
default: defaults.appName
}, {
name: 'appVersion',
message: 'What is the version of your project?',
default: '0.1.0'
}, {
name: 'appDescription',
message: 'What is a description of your project?',
default: 'n/a'
}, {
name: 'authorName',
message: 'What is the author name?',
default: defaults.userName
}, {
name: 'authorEmail',
message: 'What is the author email?',
default: defaults.authorEmail
}, {
name: 'userName',
message: 'What is the github username?',
default: defaults.userName
}, {
type: 'confirm',
name: 'moveon',
message: 'Continue?'
}
])
.then(answers => {
if (!answers.moveon) return;
const unsafeExtensions = ['*', '!*.png', '!*.txt', '!*.ico'];
const publicFolderFilter = filter(unsafeExtensions, { restore: true });
answers.file = { relative: '<%= file.relative %>' };
answers = handleDefaults(answers);
answers.year = (new Date()).getFullYear();
const stream = gulp.src([`${__dirname}/templates/app/**`])
.pipe(publicFolderFilter)
.pipe(template(answers, { interpolate: /<%=\s([\s\S]+?)%>/g }))
.pipe(rename(file => {
if (file.basename[0] === '_' && file.basename[1] === '_') {
file.basename = file.basename.slice(1);
} else if (file.basename[0] === '_') {
file.basename = '.' + file.basename.slice(1);
} // end if
}))
.pipe(publicFolderFilter.restore)
.pipe(tap(file => {
console.log(
chalk.gray('[') +
chalk.black(new Date().toLocaleTimeString()) +
chalk.gray('] [') +
chalk.cyan('conflict') +
chalk.gray('] ') +
chalk.white('Creating ') +
chalk.magenta(file.relative || file.dirname)
);
}))
.pipe(gulp.dest('./'));
stream.on('end', () => {
console.log(chalk.green('Files created successfully.'));
console.log(chalk.gray('Installing npm modules...'));
shell.task('npm i')();
});
});