forked from intuit/auto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-plugin.js
executable file
·53 lines (43 loc) · 1.25 KB
/
create-plugin.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
#!/usr/bin/env node
const copy = require("copy-template-dir");
const path = require("path");
const log = require("signale");
const fs = require("fs");
const changeCase = require("change-case");
const { titleCase } = require("title-case");
const [, , name, description] = process.argv;
const { version } = JSON.parse(
fs.readFileSync(path.join(__dirname, "../lerna.json"), "utf8")
);
const inDir = path.join(__dirname, "./template-plugin");
const kebab = changeCase.paramCase(name);
const outDir = path.join(__dirname, "../plugins", kebab);
const TSCONFIG = path.join(__dirname, "../tsconfig.dev.json");
fs.mkdirSync(outDir);
const vars = {
description,
version,
title: titleCase(name),
kebab,
pascal: changeCase.pascalCase(name),
};
copy(inDir, outDir, vars, (err, createdFiles) => {
if (err) {
throw err;
}
createdFiles.forEach((filePath) =>
log.info(`Created ${path.relative(outDir, filePath)}`)
);
log.success(`Created @auto-it/${kebab} plugin!`);
});
fs.readFile(TSCONFIG, "utf8", (err, data) => {
if (err) {
throw err;
}
const json = JSON.parse(data);
json.references.push({
path: `plugins/${kebab}`,
});
fs.writeFileSync(TSCONFIG, JSON.stringify(json, null, 2));
log.success(`Updated tsconfig.dev.json!`);
});