generated from LinbuduLab/starter-collections
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate-package.ts
110 lines (96 loc) · 2.59 KB
/
create-package.ts
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
106
107
108
109
110
import fs from "fs-extra";
import path from "path";
import consola from "consola";
import chalk from "chalk";
import minimist from "minimist";
import prompts from "prompts";
import jsonfile from "jsonfile";
import prettier from "prettier";
const PACKAGE_DIR = "packages";
const getInitialContent = (pkg: string) => `
console.log('pkg');
`;
const BASE_GITHUB_URL =
"https://github.com/LinbuduLab/vscode-extension-monorepo";
const PUBLISHER = "linbudu599";
const getPackageJsonContent = (pkg: string) => ({
name: pkg,
version: "0.0.1",
description: "",
license: "MIT",
scripts: {
build: "tsc",
watch: "tsc --watch",
check: "tsc --noEmit",
pkg: "vsce package",
pub: "vsce publish",
"pub:patch": "vsce publish patch",
"pub:minor": "vsce publish minor",
"pub:major": "vsce publish patch",
},
repository: {
type: "git",
url: `git+${BASE_GITHUB_URL}`,
},
bugs: {
url: `${BASE_GITHUB_URL}/issues`,
},
homepage: `${BASE_GITHUB_URL}#readme`,
main: "./dist/index.js",
authort: PUBLISHER,
publisher: PUBLISHER,
engines: {
vscode: "^1.27.0",
},
categories: ["Other"],
activationEvents: [],
contributes: {
commands: [],
keybindings: [],
menus: {
"editor/title": [],
"editor/title/context": [],
"editor/context": [],
"explorer/context": [],
},
snippets: [],
viewsContainers: [],
views: [],
iconThemes: [],
},
});
const getTSConfigContent = (pkg: string) => ({
extends: "../../tsconfig.base.json",
compilerOptions: {
outDir: "dist",
},
include: ["src/**/*"],
});
(async () => {
const arg = minimist(process.argv.slice(2));
const pkgName = arg["_"][0];
consola.info(`Creating ${pkgName}`);
if (!pkgName) {
throw new Error();
}
const packageDir = path.resolve(PACKAGE_DIR, pkgName);
const initialFile = path.join(packageDir, "src", "index.ts");
const packageFile = path.join(packageDir, "package.json");
const tsconfigFile = path.join(packageDir, "tsconfig.json");
const licenseFile = path.join(packageDir, "LICENSE");
const projectLicenseFile = path.join(process.cwd(), "LICENSE");
fs.ensureDirSync(packageDir);
fs.ensureFileSync(initialFile);
fs.ensureFileSync(licenseFile);
fs.writeFileSync(initialFile, getInitialContent(pkgName));
fs.writeFileSync(
packageFile,
JSON.stringify(getPackageJsonContent(pkgName), null, 2)
);
fs.writeFileSync(
tsconfigFile,
JSON.stringify(getTSConfigContent(pkgName), null, 2)
);
fs.writeFileSync(licenseFile, fs.readFileSync(projectLicenseFile, "utf-8"));
consola.success(`Create ${pkgName}`);
})();