zixulu 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,369 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { createPromptModule } from 'inquirer';
4
+ import { readdirSync, mkdirSync, writeFileSync, statSync, readFileSync } from 'fs';
5
+
6
+ var name = "deep-sea";
7
+ var version = "0.0.1";
8
+ var main = "index.js";
9
+ var license = "MIT";
10
+ var type = "module";
11
+ var bin = "./dist/index.js";
12
+ var scripts = {
13
+ build: "npx rollup -c rollup.config.js"
14
+ };
15
+ var devDependencies = {
16
+ "@rollup/plugin-json": "^6.0.1",
17
+ "@rollup/plugin-typescript": "^11.1.5",
18
+ "@types/inquirer": "^9.0.6",
19
+ "@types/node": "^20.8.9",
20
+ "@types/rollup": "^0.54.0",
21
+ rollup: "^4.1.5",
22
+ tslib: "^2.6.2",
23
+ typescript: "^5.2.2"
24
+ };
25
+ var dependencies = {
26
+ commander: "^11.1.0",
27
+ inquirer: "^9.2.11"
28
+ };
29
+ var pkg = {
30
+ name: name,
31
+ version: version,
32
+ main: main,
33
+ license: license,
34
+ type: type,
35
+ bin: bin,
36
+ scripts: scripts,
37
+ devDependencies: devDependencies,
38
+ dependencies: dependencies
39
+ };
40
+
41
+ const prompt = createPromptModule();
42
+ const packageNameReg = /^[a-z0-9]{1}[-_a-z0-9]{0,213}$/i;
43
+ const JavaScriptTargets = ["ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020", "ES2021", "ES2022", "ES2023", "ESNext"];
44
+ function getBuildJS(answer) {
45
+ const { target, css } = answer;
46
+ if (css) {
47
+ return `import { execSync } from "child_process"
48
+ import { copyFileSync, mkdirSync, readdirSync, rmSync, statSync } from "fs"
49
+ import { join } from "path"
50
+
51
+ try {
52
+ rmSync("./dist", { recursive: true })
53
+ } catch (error) {}
54
+
55
+ execSync("npx tsc --sourceMap -module ${target} -outDir dist/esm && npx tsc --sourceMap -module CommonJS -outDir dist/cjs && npx tsc --declaration --emitDeclarationOnly -outDir dist")
56
+
57
+ const src = "./src"
58
+ const distEsm = "./dist/esm"
59
+ const distCjs = "./dist/cjs"
60
+
61
+ function bundleCSS(...paths) {
62
+ const dir = readdirSync(join(src, ...paths))
63
+ dir.forEach(name => {
64
+ const status = statSync(join(src, ...paths, name))
65
+ if (status.isFile() && name.endsWith(".css")) {
66
+ for (let i = 0; i < paths.length; i++) {
67
+ const d0 = readdirSync(join(distEsm, ...paths.slice(0, i)))
68
+ if (!d0.includes(paths[i]) || !statSync(join(distEsm, ...paths.slice(0, i + 1))).isDirectory()) {
69
+ mkdirSync(join(distEsm, ...paths.slice(0, i + 1)))
70
+ }
71
+ const d1 = readdirSync(join(distCjs, ...paths.slice(0, i)))
72
+ if (!d1.includes(paths[i]) || !statSync(join(distCjs, ...paths.slice(0, i + 1))).isDirectory()) {
73
+ mkdirSync(join(distCjs, ...paths.slice(0, i + 1)))
74
+ }
75
+ }
76
+ copyFileSync(join(src, ...paths, name), join(distEsm, ...paths, name))
77
+ copyFileSync(join(src, ...paths, name), join(distCjs, ...paths, name))
78
+ return
79
+ }
80
+ if (status.isDirectory()) {
81
+ bundleCSS(...paths, name)
82
+ }
83
+ })
84
+ }
85
+
86
+ bundleCSS()
87
+ `;
88
+ }
89
+ return `import { execSync } from "child_process"
90
+ import { rmSync } from "fs"
91
+
92
+ try {
93
+ rmSync("./dist", { recursive: true })
94
+ } catch (error) {}
95
+
96
+ execSync("npx tsc --sourceMap -module ${target} -outDir dist/esm && npx tsc --sourceMap -module CommonJS -outDir dist/cjs && npx tsc --declaration --emitDeclarationOnly -outDir dist")
97
+ `;
98
+ }
99
+ async function getPackageJson(answer) {
100
+ const { name } = answer;
101
+ const response = await fetch("https://registry.npmjs.org/typescript");
102
+ const data = await response.json();
103
+ return `{
104
+ "name": "${name}",
105
+ "version": "0.0.1",
106
+ "main": "dist/cjs/index.js",
107
+ "module": "dist/esm/index.js",
108
+ "types": "dist/index.d.ts",
109
+ "license": "MIT",
110
+ "type": "module",
111
+ "exports": {
112
+ ".": {
113
+ "import": {
114
+ "types": "./dist/index.d.ts",
115
+ "default": "./dist/esm/index.js"
116
+ },
117
+ "require": {
118
+ "types": "./dist/index.d.ts",
119
+ "default": "./dist/cjs/index.js"
120
+ }
121
+ }
122
+ },
123
+ "scripts": {
124
+ "build": "node ./build.js"
125
+ },
126
+ "devDependencies": {
127
+ "typescript": "^${data["dist-tags"].latest}"
128
+ }
129
+ }
130
+ `;
131
+ }
132
+ function getTSConfig(answer) {
133
+ const { react, target } = answer;
134
+ return `{
135
+ "compilerOptions": {
136
+ /* Visit https://aka.ms/tsconfig to read more about this file */
137
+ /* Projects */
138
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
139
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
140
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
141
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
142
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
143
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
144
+ /* Language and Environment */
145
+ "target": "${target}", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
146
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
147
+ ${react ? "" : "// "}"jsx": "react",${react ? " " : ""} /* Specify what JSX code is generated. */
148
+ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
149
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
150
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
151
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
152
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
153
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
154
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
155
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
156
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
157
+ /* Modules */
158
+ // "module": "commonjs", /* Specify what module code is generated. */
159
+ "rootDir": "./src", /* Specify the root folder within your source files. */
160
+ "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
161
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
162
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
163
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
164
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
165
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
166
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
167
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
168
+ // "resolveJsonModule": true, /* Enable importing .json files. */
169
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
170
+ /* JavaScript Support */
171
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
172
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
173
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
174
+ /* Emit */
175
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
176
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
177
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
178
+ "sourceMap": true, /* Create source map files for emitted JavaScript files. */
179
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
180
+ // "outDir": "./dist", /* Specify an output folder for all emitted files. */
181
+ // "removeComments": true, /* Disable emitting comments. */
182
+ // "noEmit": true, /* Disable emitting files from a compilation. */
183
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
184
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
185
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
186
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
187
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
188
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
189
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
190
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
191
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
192
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
193
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
194
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
195
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
196
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
197
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
198
+ /* Interop Constraints */
199
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
200
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
201
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
202
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
203
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
204
+ /* Type Checking */
205
+ "strict": true, /* Enable all strict type-checking options. */
206
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
207
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
208
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
209
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
210
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
211
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
212
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
213
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
214
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
215
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
216
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
217
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
218
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
219
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
220
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
221
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
222
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
223
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
224
+ /* Completeness */
225
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
226
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
227
+ }
228
+ }`;
229
+ }
230
+ function validateName(name) {
231
+ name = name.trim();
232
+ if (!packageNameReg.test(name)) {
233
+ throw new Error("项目名称必须由数字、字母、下划线和中划线构成,且不能以下划线和中划线开头");
234
+ }
235
+ const dir = readdirSync("./");
236
+ if (dir.includes(name) && statSync(`./${name}`).isDirectory() && readdirSync(`./${name}`).length > 0) {
237
+ throw new Error("当前目录下存在同名文件夹,且文件夹非空");
238
+ }
239
+ }
240
+ function validateTarget(target) {
241
+ target = target.trim().toUpperCase();
242
+ if (!JavaScriptTargets.includes(target)) {
243
+ throw new Error("请输入有效的 JavaScript 版本");
244
+ }
245
+ }
246
+ function getProjectAnswer(...exclude) {
247
+ return prompt([
248
+ {
249
+ type: "input",
250
+ name: "name",
251
+ message: "请输入项目名称:",
252
+ default: "my-project",
253
+ validate: (input) => {
254
+ try {
255
+ validateName(input);
256
+ return true;
257
+ }
258
+ catch (error) {
259
+ return String(error);
260
+ }
261
+ }
262
+ },
263
+ {
264
+ type: "list",
265
+ name: "target",
266
+ message: "JavaScript 版本:",
267
+ choices: JavaScriptTargets,
268
+ default: "ES2020"
269
+ },
270
+ {
271
+ type: "confirm",
272
+ name: "react",
273
+ message: "是否为 react 项目:",
274
+ default: false
275
+ },
276
+ {
277
+ type: "confirm",
278
+ name: "css",
279
+ message: "是否打包 CSS:",
280
+ default: true
281
+ },
282
+ {
283
+ type: "confirm",
284
+ name: "esm",
285
+ message: "是否打包 ES Module:",
286
+ default: true
287
+ },
288
+ {
289
+ type: "confirm",
290
+ name: "cjs",
291
+ message: "是否打包 Common JS:",
292
+ default: true
293
+ }
294
+ ].filter(it => exclude.every(i => i !== it.name)));
295
+ }
296
+ const program = new Command();
297
+ program.name("格数科技").version(pkg.version);
298
+ program.option("-v, --version").action(() => {
299
+ console.log(pkg.version);
300
+ });
301
+ program
302
+ .command("create")
303
+ .description("初始化 npm 项目")
304
+ .option("-n --name <name>", "指定项目名称")
305
+ .option("-r --react", "指定为 react 项目")
306
+ .option("-t --target <target>", "指定 JavaScript 版本")
307
+ .option("--no-css", "不打包 CSS")
308
+ .option("--no-esm", "不打包 ES Module")
309
+ .option("--no-cjs", "不打包 Common JS")
310
+ .action(async (options) => {
311
+ const initAnswer = {};
312
+ const exclude = [];
313
+ if ("name" in options) {
314
+ validateName(options.name);
315
+ exclude.push("name");
316
+ initAnswer.name = options.name.trim();
317
+ }
318
+ if ("react" in options) {
319
+ initAnswer.react = true;
320
+ exclude.push("react");
321
+ }
322
+ if ("target" in options) {
323
+ validateTarget(options.target);
324
+ exclude.push("target");
325
+ initAnswer.target = options.target.trim().toUpperCase();
326
+ }
327
+ if (options.css === false) {
328
+ exclude.push("css");
329
+ initAnswer.css = false;
330
+ }
331
+ if (options.esm === false) {
332
+ exclude.push("esm");
333
+ initAnswer.esm = false;
334
+ }
335
+ if (options.cjs === false) {
336
+ exclude.push("cjs");
337
+ initAnswer.cjs = false;
338
+ }
339
+ const answer = { ...initAnswer, ...(await getProjectAnswer(...exclude)) };
340
+ const { name, react } = answer;
341
+ const dir = readdirSync("./");
342
+ if (!dir.includes(name)) {
343
+ mkdirSync(`./${name}`);
344
+ }
345
+ mkdirSync(`./${name}/src`);
346
+ writeFileSync(`./${name}/src/index.${react ? "tsx" : "ts"}`, "");
347
+ writeFileSync(`./${name}/build.js`, getBuildJS(answer));
348
+ writeFileSync(`./${name}/package.json`, await getPackageJson(answer));
349
+ writeFileSync(`./${name}/tsconfig.json`, getTSConfig(answer));
350
+ });
351
+ program
352
+ .command("build")
353
+ .description("更改打包命令")
354
+ .option("--no-css", "不打包 CSS")
355
+ .action(options => {
356
+ const { css } = options;
357
+ const dir = readdirSync("./");
358
+ if (!dir.includes("package.json") || !statSync("./package.json").isFile()) {
359
+ throw new Error("当前目录下不存在 package.json 文件");
360
+ }
361
+ const info = JSON.parse(readFileSync("./package.json", "utf-8"));
362
+ info.scripts ?? (info.scripts = {});
363
+ info.scripts.build = "node build.js";
364
+ writeFileSync("./package.json", JSON.stringify(info, null, 4), "utf-8");
365
+ const config = readFileSync("./tsconfig.json", "utf-8");
366
+ const target = config.match(/"target":[ ]*?"(.+?)"/i)[1].toUpperCase();
367
+ writeFileSync("./build.js", getBuildJS({ target, css }));
368
+ });
369
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "zixulu",
3
+ "version": "0.0.1",
4
+ "main": "index.js",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": "./dist/index.js",
8
+ "scripts": {
9
+ "build": "npx rollup -c rollup.config.js"
10
+ },
11
+ "devDependencies": {
12
+ "@rollup/plugin-json": "^6.0.1",
13
+ "@rollup/plugin-typescript": "^11.1.5",
14
+ "@types/inquirer": "^9.0.6",
15
+ "@types/node": "^20.8.9",
16
+ "@types/rollup": "^0.54.0",
17
+ "rollup": "^4.1.5",
18
+ "tslib": "^2.6.2",
19
+ "typescript": "^5.2.2"
20
+ },
21
+ "dependencies": {
22
+ "commander": "^11.1.0",
23
+ "inquirer": "^9.2.11"
24
+ }
25
+ }
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from "rollup"
2
+ import typescript from "@rollup/plugin-typescript"
3
+ import json from "@rollup/plugin-json"
4
+
5
+ export default defineConfig({
6
+ input: "./src/index.ts",
7
+ output: {
8
+ file: "./dist/index.js",
9
+ format: "esm"
10
+ },
11
+ plugins: [typescript(), json()]
12
+ })
package/src/index.ts ADDED
@@ -0,0 +1,362 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from "commander"
4
+ import pkg from "../package.json"
5
+ import { createPromptModule } from "inquirer"
6
+ import { mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "fs"
7
+
8
+ const prompt = createPromptModule()
9
+
10
+ const packageNameReg = /^[a-z0-9]{1}[-_a-z0-9]{0,213}$/i
11
+
12
+ type JavaScriptTarget = "ES2015" | "ES2016" | "ES2017" | "ES2018" | "ES2019" | "ES2020" | "ES2021" | "ES2022" | "ES2023" | "ESNext"
13
+
14
+ interface ProjectAnswer {
15
+ name: string
16
+ target: JavaScriptTarget
17
+ react: boolean
18
+ css: boolean
19
+ esm: boolean
20
+ cjs: boolean
21
+ }
22
+
23
+ const JavaScriptTargets: JavaScriptTarget[] = ["ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020", "ES2021", "ES2022", "ES2023", "ESNext"]
24
+
25
+ function getBuildJS(answer: Pick<ProjectAnswer, "target" | "css">) {
26
+ const { target, css } = answer
27
+ if (css) {
28
+ return `import { execSync } from "child_process"
29
+ import { copyFileSync, mkdirSync, readdirSync, rmSync, statSync } from "fs"
30
+ import { join } from "path"
31
+
32
+ try {
33
+ rmSync("./dist", { recursive: true })
34
+ } catch (error) {}
35
+
36
+ execSync("npx tsc --sourceMap -module ${target} -outDir dist/esm && npx tsc --sourceMap -module CommonJS -outDir dist/cjs && npx tsc --declaration --emitDeclarationOnly -outDir dist")
37
+
38
+ const src = "./src"
39
+ const distEsm = "./dist/esm"
40
+ const distCjs = "./dist/cjs"
41
+
42
+ function bundleCSS(...paths) {
43
+ const dir = readdirSync(join(src, ...paths))
44
+ dir.forEach(name => {
45
+ const status = statSync(join(src, ...paths, name))
46
+ if (status.isFile() && name.endsWith(".css")) {
47
+ for (let i = 0; i < paths.length; i++) {
48
+ const d0 = readdirSync(join(distEsm, ...paths.slice(0, i)))
49
+ if (!d0.includes(paths[i]) || !statSync(join(distEsm, ...paths.slice(0, i + 1))).isDirectory()) {
50
+ mkdirSync(join(distEsm, ...paths.slice(0, i + 1)))
51
+ }
52
+ const d1 = readdirSync(join(distCjs, ...paths.slice(0, i)))
53
+ if (!d1.includes(paths[i]) || !statSync(join(distCjs, ...paths.slice(0, i + 1))).isDirectory()) {
54
+ mkdirSync(join(distCjs, ...paths.slice(0, i + 1)))
55
+ }
56
+ }
57
+ copyFileSync(join(src, ...paths, name), join(distEsm, ...paths, name))
58
+ copyFileSync(join(src, ...paths, name), join(distCjs, ...paths, name))
59
+ return
60
+ }
61
+ if (status.isDirectory()) {
62
+ bundleCSS(...paths, name)
63
+ }
64
+ })
65
+ }
66
+
67
+ bundleCSS()
68
+ `
69
+ }
70
+ return `import { execSync } from "child_process"
71
+ import { rmSync } from "fs"
72
+
73
+ try {
74
+ rmSync("./dist", { recursive: true })
75
+ } catch (error) {}
76
+
77
+ execSync("npx tsc --sourceMap -module ${target} -outDir dist/esm && npx tsc --sourceMap -module CommonJS -outDir dist/cjs && npx tsc --declaration --emitDeclarationOnly -outDir dist")
78
+ `
79
+ }
80
+
81
+ async function getPackageJson(answer: ProjectAnswer) {
82
+ const { name } = answer
83
+ const response = await fetch("https://registry.npmjs.org/typescript")
84
+ const data = await response.json()
85
+ return `{
86
+ "name": "${name}",
87
+ "version": "0.0.1",
88
+ "main": "dist/cjs/index.js",
89
+ "module": "dist/esm/index.js",
90
+ "types": "dist/index.d.ts",
91
+ "license": "MIT",
92
+ "type": "module",
93
+ "exports": {
94
+ ".": {
95
+ "import": {
96
+ "types": "./dist/index.d.ts",
97
+ "default": "./dist/esm/index.js"
98
+ },
99
+ "require": {
100
+ "types": "./dist/index.d.ts",
101
+ "default": "./dist/cjs/index.js"
102
+ }
103
+ }
104
+ },
105
+ "scripts": {
106
+ "build": "node ./build.js"
107
+ },
108
+ "devDependencies": {
109
+ "typescript": "^${data["dist-tags"].latest}"
110
+ }
111
+ }
112
+ `
113
+ }
114
+
115
+ function getTSConfig(answer: ProjectAnswer) {
116
+ const { react, target } = answer
117
+ return `{
118
+ "compilerOptions": {
119
+ /* Visit https://aka.ms/tsconfig to read more about this file */
120
+ /* Projects */
121
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
122
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
123
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
124
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
125
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
126
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
127
+ /* Language and Environment */
128
+ "target": "${target}", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
129
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
130
+ ${react ? "" : "// "}"jsx": "react",${react ? " " : ""} /* Specify what JSX code is generated. */
131
+ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
132
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
133
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
134
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
135
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
136
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
137
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
138
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
139
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
140
+ /* Modules */
141
+ // "module": "commonjs", /* Specify what module code is generated. */
142
+ "rootDir": "./src", /* Specify the root folder within your source files. */
143
+ "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
144
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
145
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
146
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
147
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
148
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
149
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
150
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
151
+ // "resolveJsonModule": true, /* Enable importing .json files. */
152
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
153
+ /* JavaScript Support */
154
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
155
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
156
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
157
+ /* Emit */
158
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
159
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
160
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
161
+ "sourceMap": true, /* Create source map files for emitted JavaScript files. */
162
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
163
+ // "outDir": "./dist", /* Specify an output folder for all emitted files. */
164
+ // "removeComments": true, /* Disable emitting comments. */
165
+ // "noEmit": true, /* Disable emitting files from a compilation. */
166
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
167
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
168
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
169
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
170
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
171
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
172
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
173
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
174
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
175
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
176
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
177
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
178
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
179
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
180
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
181
+ /* Interop Constraints */
182
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
183
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
184
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
185
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
186
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
187
+ /* Type Checking */
188
+ "strict": true, /* Enable all strict type-checking options. */
189
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
190
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
191
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
192
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
193
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
194
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
195
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
196
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
197
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
198
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
199
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
200
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
201
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
202
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
203
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
204
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
205
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
206
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
207
+ /* Completeness */
208
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
209
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
210
+ }
211
+ }`
212
+ }
213
+
214
+ function validateName(name: string) {
215
+ name = name.trim()
216
+ if (!packageNameReg.test(name)) {
217
+ throw new Error("项目名称必须由数字、字母、下划线和中划线构成,且不能以下划线和中划线开头")
218
+ }
219
+ const dir = readdirSync("./")
220
+ if (dir.includes(name) && statSync(`./${name}`).isDirectory() && readdirSync(`./${name}`).length > 0) {
221
+ throw new Error("当前目录下存在同名文件夹,且文件夹非空")
222
+ }
223
+ }
224
+
225
+ function validateTarget(target: string) {
226
+ target = target.trim().toUpperCase()
227
+ if (!JavaScriptTargets.includes(target as JavaScriptTarget)) {
228
+ throw new Error("请输入有效的 JavaScript 版本")
229
+ }
230
+ }
231
+
232
+ function getProjectAnswer<T extends keyof ProjectAnswer>(...exclude: T[]): Promise<Omit<ProjectAnswer, T>> {
233
+ return prompt<Omit<ProjectAnswer, T>>(
234
+ [
235
+ {
236
+ type: "input",
237
+ name: "name",
238
+ message: "请输入项目名称:",
239
+ default: "my-project",
240
+ validate: (input: string) => {
241
+ try {
242
+ validateName(input)
243
+ return true
244
+ } catch (error) {
245
+ return String(error)
246
+ }
247
+ }
248
+ },
249
+ {
250
+ type: "list",
251
+ name: "target",
252
+ message: "JavaScript 版本:",
253
+ choices: JavaScriptTargets,
254
+ default: "ES2020"
255
+ },
256
+ {
257
+ type: "confirm",
258
+ name: "react",
259
+ message: "是否为 react 项目:",
260
+ default: false
261
+ },
262
+ {
263
+ type: "confirm",
264
+ name: "css",
265
+ message: "是否打包 CSS:",
266
+ default: true
267
+ },
268
+ {
269
+ type: "confirm",
270
+ name: "esm",
271
+ message: "是否打包 ES Module:",
272
+ default: true
273
+ },
274
+ {
275
+ type: "confirm",
276
+ name: "cjs",
277
+ message: "是否打包 Common JS:",
278
+ default: true
279
+ }
280
+ ].filter(it => exclude.every(i => i !== it.name))
281
+ )
282
+ }
283
+
284
+ const program = new Command()
285
+
286
+ program.name("格数科技").version(pkg.version)
287
+
288
+ program.option("-v, --version").action(() => {
289
+ console.log(pkg.version)
290
+ })
291
+
292
+ program
293
+ .command("create")
294
+ .description("初始化 npm 项目")
295
+ .option("-n --name <name>", "指定项目名称")
296
+ .option("-r --react", "指定为 react 项目")
297
+ .option("-t --target <target>", "指定 JavaScript 版本")
298
+ .option("--no-css", "不打包 CSS")
299
+ .option("--no-esm", "不打包 ES Module")
300
+ .option("--no-cjs", "不打包 Common JS")
301
+ .action(async (options: Partial<ProjectAnswer>) => {
302
+ const initAnswer: Partial<ProjectAnswer> = {}
303
+ const exclude: (keyof ProjectAnswer)[] = []
304
+ if ("name" in options) {
305
+ validateName(options.name!)
306
+ exclude.push("name")
307
+ initAnswer.name = options.name!.trim()
308
+ }
309
+ if ("react" in options) {
310
+ initAnswer.react = true
311
+ exclude.push("react")
312
+ }
313
+ if ("target" in options) {
314
+ validateTarget(options.target!)
315
+ exclude.push("target")
316
+ initAnswer.target = options.target!.trim().toUpperCase() as JavaScriptTarget
317
+ }
318
+ if (options.css === false) {
319
+ exclude.push("css")
320
+ initAnswer.css = false
321
+ }
322
+ if (options.esm === false) {
323
+ exclude.push("esm")
324
+ initAnswer.esm = false
325
+ }
326
+ if (options.cjs === false) {
327
+ exclude.push("cjs")
328
+ initAnswer.cjs = false
329
+ }
330
+ const answer = { ...initAnswer, ...(await getProjectAnswer(...exclude)) } as ProjectAnswer
331
+ const { name, react } = answer
332
+ const dir = readdirSync("./")
333
+ if (!dir.includes(name)) {
334
+ mkdirSync(`./${name}`)
335
+ }
336
+ mkdirSync(`./${name}/src`)
337
+ writeFileSync(`./${name}/src/index.${react ? "tsx" : "ts"}`, "")
338
+ writeFileSync(`./${name}/build.js`, getBuildJS(answer))
339
+ writeFileSync(`./${name}/package.json`, await getPackageJson(answer))
340
+ writeFileSync(`./${name}/tsconfig.json`, getTSConfig(answer))
341
+ })
342
+
343
+ program
344
+ .command("build")
345
+ .description("更改打包命令")
346
+ .option("--no-css", "不打包 CSS")
347
+ .action(options => {
348
+ const { css } = options
349
+ const dir = readdirSync("./")
350
+ if (!dir.includes("package.json") || !statSync("./package.json").isFile()) {
351
+ throw new Error("当前目录下不存在 package.json 文件")
352
+ }
353
+ const info = JSON.parse(readFileSync("./package.json", "utf-8"))
354
+ info.scripts ??= {}
355
+ info.scripts.build = "node build.js"
356
+ writeFileSync("./package.json", JSON.stringify(info, null, 4), "utf-8")
357
+ const config = readFileSync("./tsconfig.json", "utf-8")
358
+ const target = config.match(/"target":[ ]*?"(.+?)"/i)![1].toUpperCase() as JavaScriptTarget
359
+ writeFileSync("./build.js", getBuildJS({ target, css }))
360
+ })
361
+
362
+ program.parse()
package/tsconfig.json ADDED
@@ -0,0 +1,101 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig to read more about this file */
4
+ /* Projects */
5
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
6
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
7
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
8
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
9
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
10
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
11
+ /* Language and Environment */
12
+ "target": "ES2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
13
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
14
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
15
+ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
16
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
17
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
18
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
19
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
20
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
21
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
22
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
23
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
24
+ /* Modules */
25
+ "module": "NodeNext", /* Specify what module code is generated. */
26
+ // "rootDir": "./", /* Specify the root folder within your source files. */
27
+ "moduleResolution": "NodeNext", /* Specify how TypeScript looks up a file from a given module specifier. */
28
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
29
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
30
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
31
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
32
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
33
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
34
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
35
+ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
36
+ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
37
+ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
38
+ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
39
+ "resolveJsonModule": true, /* Enable importing .json files. */
40
+ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
41
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
42
+ /* JavaScript Support */
43
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
44
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
45
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
46
+ /* Emit */
47
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
48
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
49
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
50
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
51
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
52
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
53
+ // "outDir": "./", /* Specify an output folder for all emitted files. */
54
+ // "removeComments": true, /* Disable emitting comments. */
55
+ // "noEmit": true, /* Disable emitting files from a compilation. */
56
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
57
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
58
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
59
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
60
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
61
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
62
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
63
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
64
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
65
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
66
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
67
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
68
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
69
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
70
+ /* Interop Constraints */
71
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
72
+ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
73
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
74
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
75
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
76
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
77
+ /* Type Checking */
78
+ "strict": true, /* Enable all strict type-checking options. */
79
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
80
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
81
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
82
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
83
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
84
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
85
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
86
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
87
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
88
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
89
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
90
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
91
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
92
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
93
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
94
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
95
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
96
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
97
+ /* Completeness */
98
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
99
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
100
+ }
101
+ }
package/typing.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ // declare module "*.json" {
2
+ // var pkg: any
3
+ // export default pkg
4
+ // }