-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.js
44 lines (34 loc) · 1.29 KB
/
index.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
//--------------------------------------------------------
//-- Grow extension
//--------------------------------------------------------
"use strict";
const chalk = require("chalk");
const figures = require("figures");
const fss = require("@absolunet/fss");
const LOCAL = fss.realpath(".");
const EXTENSION = `${LOCAL}/my-extension`;
const ROOT = fss.realpath(__dirname);
const BOILERPLATE = `${ROOT}/boilerplate`;
const PACKAGE = fss.readJson(`${ROOT}/package.json`);
const echo = console.log; // eslint-disable-line no-console
const error = (message) => {
console.error(chalk.red(`\n ${figures.cross} ${message}`)); // eslint-disable-line no-console
process.exit(); // eslint-disable-line node/no-process-exit, unicorn/no-process-exit
};
class GrowExtension {
cli() {
if (fss.exists(EXTENSION)) {
error(`There is already a 'my-extension' folder`);
}
echo(chalk.blue(`\n${figures.play} Generating extension ${figures.ellipsis}`));
// Duplicate boilerplate
fss.copy(BOILERPLATE, EXTENSION);
fss.rename(`${EXTENSION}/-gitignore`, `${EXTENSION}/.gitignore`);
fss.rename(`${EXTENSION}/-npmignore`, `${EXTENSION}/.npmignore`);
// Confirmation
echo(`
${chalk.green(`${figures.tick} ${chalk.bold(`nwayo ${PACKAGE.version}`)} extension created!`)}
`);
}
}
module.exports = new GrowExtension();