forked from postmanlabs/postman-code-generators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboilerplate.js
29 lines (24 loc) · 951 Bytes
/
boilerplate.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
var exec = require('shelljs').exec,
fs = require('fs'),
chalk = require('chalk'),
codegens,
path = require('path'),
getSubfolders = (folder) => {
return fs.readdirSync(folder)
.map((subfolder) => { return subfolder; });
};
const args = process.argv,
BOILERPLATE = path.resolve(__dirname, '../npm/boilerplate'),
CODEGEN_FOLDER = path.resolve(__dirname, '../codegens') + '/';
codegens = getSubfolders(CODEGEN_FOLDER);
if (!args[2]) {
console.log(chalk.red('Please provide a name for the codegen.'));
return;
}
if (codegens.includes(args[2])) {
console.log(chalk.red('Codegen with the same name already exits. Please choose a unique name.\n'));
return;
}
exec('cp -a ' + BOILERPLATE + '/. ' + CODEGEN_FOLDER + args[2] + '/'); // cp -a /source/. /destination/
console.log(chalk.yellow('A folder named ' + args[2] +
' has been added to /codegens. This folder contains the basic structure of a code-generator.\n'));