create-a-npm 0.0.0 → 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/LICENSE CHANGED
@@ -1,13 +1,13 @@
1
- Copyright (c) <2024> <letmiseesee>
2
-
3
- Permission to use, copy, modify, and/or distribute this software for any
4
- purpose with or without fee is hereby granted, provided that the above
5
- copyright notice and this permission notice appear in all copies.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1
+ Copyright (c) <2024> <letmiseesee>
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,26 +1,20 @@
1
- # is mi
2
-
3
- long long ago, in i'm a child.
4
-
5
- At that time, I was still in school and my English class was terrible.
6
-
7
- In class, the foreign language teacher asked me to go to the podium to write English words.
8
-
9
- and I wrote "This is mi" .
10
-
11
- My classmates laughed uncontrollably when they saw it,
12
-
13
- and then they called me 'is mi'
14
-
15
- ## install
16
-
17
- ```sh
18
- npm install -g ismi
19
- ```
20
-
21
- ## Other languages
22
-
23
- <table><tr>
24
- <td><a href="https://github.com/lmssee/ismi/blob/main/README.md" target="_self">English</a></td>
25
- <td><a href="https://github.com/lmssee/ismi/blob/main/自述文件.md" target="_self">中文</a></td>
26
- </tr></table>
1
+ # create a node package module
2
+
3
+ This package is used to generate a node package based on `typescript`, built using `rollup`, formatted using `prettier`, and checked using `eslint`
4
+
5
+ ## install
6
+
7
+ ```sh
8
+ npm install -g create-a-npm
9
+ ```
10
+
11
+ ## use
12
+
13
+ ```sh
14
+ # Non essential installation
15
+ npm create a-npm
16
+ ```
17
+
18
+ ## Other languages
19
+
20
+ [English](https://github.com/lmssee/ismi/blob/main/README.md) [中文](https://github.com/lmssee/ismi/blob/main/自述文件.md)
package/mjs/index.mjs ADDED
@@ -0,0 +1,10 @@
1
+ import askForName from './src/askForName.mjs';
2
+ import { createNpm } from './src/createNpm.mjs';
3
+ import custom from './src/custom.mjs';
4
+
5
+ /// 设定包名
6
+ await askForName();
7
+ /// 参看是否自定义包的内容,这里会自定义是否使用 eslint 等相关内容
8
+ await custom();
9
+ /// 开始包创建
10
+ await createNpm();
@@ -0,0 +1,90 @@
1
+ import { command } from './command.mjs';
2
+ import data from './data.mjs';
3
+ import { _p, Color, dirEmpty, cursorMoveUp, cursorAfterClear } from 'a-node-tools';
4
+ import { mkdirSync } from 'node:fs';
5
+
6
+ /** Inquire about the current package name \
7
+ * 查看是否当前有项目名
8
+ */
9
+ async function askForName() {
10
+ /** The name of the package to be created \
11
+ * 将创建的包的名称
12
+ */
13
+ let commandName = await command.question({
14
+ text: '您即将创建的包名',
15
+ tip: '请使用空格/连字符(-)做分隔符',
16
+ private: true,
17
+ });
18
+ /** Clean up spaces and convert hyphens
19
+ *
20
+ * 清理空格即转换连字符 */
21
+ commandName = commandName.trim().replace(/\s+/gm, '-');
22
+ /** */
23
+ if (commandName.length == 0 || commandName[0].match(/[^a-z]/)) {
24
+ _p(Color.fromRgb('您的输入为空或首字符非法 \n', '#ff0'));
25
+ await aslForAgainOrQuit('您的输入有误,请重试', '重试或退出');
26
+ return;
27
+ }
28
+ const dirIsEmpty = dirEmpty(commandName);
29
+ /** Detected that the current directory contains a package with the same name
30
+ *
31
+ * 检测出当前目录下包含同名包且不为空
32
+ */
33
+ if (dirIsEmpty == 0) {
34
+ _p(Color.fromRgb('当前目录下存在非空同名文件夹 \n', '#ff0'));
35
+ await aslForAgainOrQuit('更换为其他名称', '更换为其他的名称或退出');
36
+ /**
37
+ *
38
+ * 当前任务已完成,避免数据污染,需要 return 结束
39
+ */
40
+ return;
41
+ }
42
+ /** 先进行赋值 */
43
+ data.name = commandName;
44
+ /*** 根据刚才的判断参看是否为非 */
45
+ if (dirIsEmpty == -1) {
46
+ /** In the current state,
47
+ * it indicates that there is no folder with the same name in the working directory.
48
+ * In this case, create an empty folder
49
+ *
50
+ * 当前状态下表明该工作目录下并没有同名文件夹,这时候创建一个空的文件夹 */
51
+ mkdirSync(commandName, { recursive: true });
52
+ }
53
+ }
54
+ /**
55
+ *
56
+ * 问询当前不符合的情况下是否要重试或直接退出
57
+ *
58
+ * @param askMessage {@link String} 询问的文本
59
+ *
60
+ * @param [text=''] {@link String} 展示的文本
61
+ *
62
+ * @returns Promise<void>> {@link Promise} 没有返回值
63
+ */
64
+ async function aslForAgainOrQuit(askMessage, text = '') {
65
+ const tip = [askMessage, '退出'];
66
+ text = text == '' ? `${askMessage}或退出` : text;
67
+ const select = await command.question({
68
+ text,
69
+ tip,
70
+ private: true,
71
+ }, true);
72
+ // Cover the printed information on top
73
+ // 覆盖上面的打印信息
74
+ cursorMoveUp(2);
75
+ cursorAfterClear();
76
+ // If the user chooses to exit
77
+ // 倘若用户选择了退出
78
+ if (select === tip[1]) {
79
+ // _p('好的,即将退出');
80
+ command.end;
81
+ }
82
+ else {
83
+ // The user calls himself to restart the query after selecting Continue
84
+ // 用户选择了继续后调用自己重新开始问询
85
+ await askForName();
86
+ return;
87
+ }
88
+ }
89
+
90
+ export { askForName as default };
@@ -0,0 +1,9 @@
1
+ import { Command } from 'a-command';
2
+
3
+ const command = new Command('create-a-npm');
4
+ /** 暂未配置自定义项,后续会跟上 */
5
+ // command.bind({ 'custom <cm> (自定义)': [] });
6
+ // 执行,并在触发 -h、-v 时直接结束应用
7
+ command.run().isEnd.end;
8
+
9
+ export { command };
@@ -0,0 +1,29 @@
1
+ import askForName from './askForName.mjs';
2
+ import custom from './custom.mjs';
3
+ import data from './data.mjs';
4
+ import { packageIndex } from './package/index.mjs';
5
+ import { testFile } from './test/index.mjs';
6
+ import { src } from './library/index.mjs';
7
+
8
+ /**
9
+ *
10
+ * 开始根据数据创建包 */
11
+ async function createNpm() {
12
+ /**
13
+ *
14
+ * 检测是否遗漏了询问包名
15
+ *
16
+ * 倘若并没有配置 name 属性值,则
17
+ * */
18
+ if (data.name == '') {
19
+ await askForName();
20
+ await custom();
21
+ await createNpm();
22
+ return;
23
+ }
24
+ packageIndex();
25
+ src();
26
+ testFile();
27
+ }
28
+
29
+ export { createNpm };
@@ -0,0 +1,13 @@
1
+ import './command.mjs';
2
+ import 'a-node-tools';
3
+
4
+ /*** 自定义插件的安装 */
5
+ /**
6
+ *
7
+ * 自定义
8
+ */
9
+ async function custom () {
10
+ return;
11
+ }
12
+
13
+ export { custom as default };
@@ -0,0 +1,56 @@
1
+ import { initializeFile, getDirectoryBy, readFileToJsonSync, pathJoin } from 'a-node-tools';
2
+ import { basename } from 'node:path';
3
+
4
+ /** 初始化当前工作文件路径 */
5
+ const [__dirname] = initializeFile();
6
+ /** 根据当前被调用文件查找当前包的 package.json 文件配置 */
7
+ let cwd = getDirectoryBy('package.json', 'file', __dirname);
8
+ /** 这里好像难以避免 cwd 为 undefined */
9
+ if (cwd == undefined) {
10
+ cwd = process.cwd();
11
+ }
12
+ /** 读取当前包的 package.json 文件内容 */
13
+ const packageJsonData = readFileToJsonSync(pathJoin(cwd, 'package.json'));
14
+ /** 导出构建数据 */
15
+ var data = {
16
+ /** 工作目录 */
17
+ cwd: '',
18
+ /** 创建文件的路径 */
19
+ fileName(str) {
20
+ return pathJoin(this.cwd, str);
21
+ },
22
+ /** 项目名称
23
+ *
24
+ * 该值在 askForName 中进行赋值
25
+ */
26
+ get name() {
27
+ return this.package.name;
28
+ },
29
+ set name(name) {
30
+ let finalName;
31
+ /** 将创建路径储存起来 */
32
+ this.cwd = name;
33
+ /** 查看创建路径和基础根路径是否相同 */
34
+ if (basename(name) == name) {
35
+ finalName = name;
36
+ }
37
+ else {
38
+ finalName = basename(name);
39
+ }
40
+ this.package.name = finalName;
41
+ },
42
+ /** 是否携带 npx 指令
43
+ * 该值将在 custom 过程中进行赋值 */
44
+ bin: false,
45
+ /** 包中需要的内容 */
46
+ package: {
47
+ /**包名称 */
48
+ name: '',
49
+ /** 依赖 */
50
+ dependencies: packageJsonData.dependencies || {},
51
+ /** 开发依赖 */
52
+ devDependencies: packageJsonData.devDependencies || {},
53
+ },
54
+ };
55
+
56
+ export { data as default };
@@ -0,0 +1,19 @@
1
+ import data from '../data.mjs';
2
+ import { pathJoin } from 'a-node-tools';
3
+ import { writeFileSync, mkdirSync } from 'node:fs';
4
+
5
+ /**
6
+ * 导出生成 src 的主文件
7
+ */
8
+ function src() {
9
+ /// index.ts
10
+ writeFileSync(data.fileName('index.ts'), `import { _p } from 'a-node-tools';\n _p('hello world');`);
11
+ // 创建文件
12
+ mkdirSync(pathJoin(data.cwd, 'src'));
13
+ //
14
+ writeFileSync(data.fileName('src/index.ts'), `import { _p } from 'a-node-tools';
15
+ // print 'hello ${data.name} on the terminal'
16
+ _p(\`hello , ${data.name}\`)`);
17
+ }
18
+
19
+ export { src };
@@ -0,0 +1,24 @@
1
+ import { writeFileSync } from 'node:fs';
2
+ import data from '../data.mjs';
3
+
4
+ /**
5
+ * eslint 配置
6
+ *
7
+ */
8
+ function eslintConfig() {
9
+ writeFileSync(data.fileName('eslint.config.js'), `import globals from 'globals';
10
+ import pluginJs from '@eslint/js';
11
+ import tseslint from 'typescript-eslint';
12
+ import eslintConfigPrettier from 'eslint-config-prettier';
13
+
14
+ export default [
15
+ { files: ['**/*.{js,mjs,cjs,ts}'] },
16
+ { languageOptions: { globals: globals.browser } },
17
+ pluginJs.configs.recommended,
18
+ ...tseslint.configs.recommended,
19
+ eslintConfigPrettier,
20
+ ];
21
+ `);
22
+ }
23
+
24
+ export { eslintConfig };
@@ -0,0 +1,21 @@
1
+ import { eslintConfig } from './eslint.mjs';
2
+ import { packageJson } from './package.mjs';
3
+ import { prettier } from './prettier.mjs';
4
+ import { readme } from './readme.mjs';
5
+ import { rollup } from './rollup.mjs';
6
+ import { tsconfigJson } from './tsconfig.mjs';
7
+
8
+ /**
9
+ *
10
+ * 导出 package 的主文件
11
+ */
12
+ function packageIndex() {
13
+ packageJson();
14
+ tsconfigJson();
15
+ rollup();
16
+ readme();
17
+ eslintConfig();
18
+ prettier();
19
+ }
20
+
21
+ export { packageIndex };
@@ -0,0 +1,63 @@
1
+ import data from '../data.mjs';
2
+ import { writeToJsonFile } from '../tools.mjs';
3
+
4
+ /**
5
+ * 这里之前返回的是一个对象,导致 js 在预编译的时候直接生成一个静态数据
6
+ * 而无法在调用 packageJson 的时候真正的将 data 的最新值带入
7
+ * 这便是现在以函数的形式进行返回,能够在调用时直接获取 data 的最新值
8
+ *
9
+ */
10
+ /** 除了 data 中提供的数据以外的数据 */
11
+ const initData = () => ({
12
+ name: '',
13
+ type: 'module',
14
+ version: '0.0.0',
15
+ main: 'cjs/index.cjs',
16
+ typings: 'types/index.d.ts',
17
+ author: '___ <___@___.___> (https://___.___)',
18
+ description: 'here is the project description, please change the content with double underline',
19
+ script: {
20
+ b: 'rollup --config rollup.config.js && tsc -p tsconfig.types.json',
21
+ build: 'ixxx rm dist run b',
22
+ diff: 'ixxx pkg diff',
23
+ prettier: 'ixxx cls && prettier . --write',
24
+ test: 'rollup --config rollup.config.test.js',
25
+ },
26
+ files: ['mjs', 'cjs', 'types'],
27
+ exports: {
28
+ '.': {
29
+ import: {
30
+ default: './mjs/index.mjs',
31
+ types: './types/index.d.ts',
32
+ },
33
+ require: {
34
+ default: './cjs/index.cjs',
35
+ types: './types/index.d.ts',
36
+ },
37
+ },
38
+ },
39
+ keywords: [data.name],
40
+ license: 'ISC',
41
+ homepage: 'https://___.___',
42
+ bugs: {
43
+ url: `https://github.com/__/${data.name}/issues`,
44
+ email: '__@__.__',
45
+ },
46
+ repository: {
47
+ type: 'git',
48
+ url: `git+https://github.com/___/${data.name}.git')`,
49
+ },
50
+ publishConfig: {
51
+ access: 'public',
52
+ registry: 'https://registry.npmjs.org/',
53
+ },
54
+ });
55
+ /** 生成 package.json 文件内容 */
56
+ function packageJson() {
57
+ const bin = {};
58
+ bin[``] = 'bin/index.js';
59
+ const finalData = Object.assign(initData(), data.package, { bin });
60
+ writeToJsonFile('package.json', finalData);
61
+ }
62
+
63
+ export { packageJson };
@@ -0,0 +1,38 @@
1
+ import { writeFileSync } from 'node:fs';
2
+ import data from '../data.mjs';
3
+ import { writeToJsonFile } from '../tools.mjs';
4
+
5
+ /**
6
+ * 导出 prettier 的相关配置文件
7
+ */
8
+ function prettier() {
9
+ // 写入 prettier ignore 忽略规则
10
+ writeFileSync(data.fileName('.prettierignore'), `node_modules/*
11
+
12
+ */node_modules
13
+
14
+ ## 打包文件
15
+
16
+ list
17
+
18
+ test/out
19
+
20
+ .DS_Store`);
21
+ /// 写入规则
22
+ writeToJsonFile('.prettierrc', {
23
+ // 屏幕单行的宽度
24
+ printWidth: 80,
25
+ // tab 宽度,默认是 2 ,但是我觉得不太明显
26
+ tabWidth: 2,
27
+ useTabs: false,
28
+ semi: true,
29
+ // 单引号
30
+ singleQuote: true,
31
+ trailingComma: 'all',
32
+ bracketSpacing: true,
33
+ arrowParens: 'avoid',
34
+ endOfLine: 'auto',
35
+ });
36
+ }
37
+
38
+ export { prettier };
@@ -0,0 +1,54 @@
1
+ import { writeFileSync } from 'node:fs';
2
+ import data from '../data.mjs';
3
+
4
+ /** 当前的时间 */
5
+ const now = new Date();
6
+ /** 月份 */
7
+ const month = now.getMonth() + 1;
8
+ /** 日期 */
9
+ const day = now.getDate();
10
+ /** 年份 */
11
+ const year = now.getFullYear();
12
+ /**
13
+ * 导出生成一些琐碎而又必须的文件
14
+ */
15
+ function readme() {
16
+ /// readme.md
17
+ writeFileSync(data.fileName('README.md'), `# ${data.name}`);
18
+ /// 自述文件.md
19
+ writeFileSync(data.fileName('自述文件.md'), `# ${data.name}`);
20
+ /// changeLog.md
21
+ writeFileSync(data.fileName('CHANGELOG.md'), `# ${data.name}\n\n## 0.0.0 (${month} 月 ${day} ${year} 年)\n\n- 初始化项目`);
22
+ /// LICENSE
23
+ license();
24
+ /// 生成 .gitignore 文件
25
+ writeFileSync(data.fileName('.gitignore'), `node_modules/*
26
+
27
+ */node_modules
28
+
29
+ ## 打包文件
30
+
31
+ list
32
+
33
+ test/out
34
+
35
+ .DS_Store`);
36
+ }
37
+ /** 导出生成 license 文件 */
38
+ function license() {
39
+ writeFileSync(data.fileName('LICENSE'), `Copyright (c) <${year}> <${data.name}>
40
+
41
+ Permission to use, copy, modify, and/or distribute this software for any
42
+ purpose with or without fee is hereby granted, provided that the above
43
+ copyright notice and this permission notice appear in all copies.
44
+
45
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
46
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
47
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
48
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
49
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
50
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
51
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.`);
52
+ }
53
+
54
+ export { license, readme };
@@ -0,0 +1,116 @@
1
+ import { writeFileSync } from 'node:fs';
2
+ import data from '../data.mjs';
3
+
4
+ /**
5
+ * 生成 rollup 打包工具的配置文件信息
6
+ */
7
+ function rollup() {
8
+ rollupJs();
9
+ rollupConfigTestJs();
10
+ }
11
+ /** 导出生成 rollup.config.js 文件 */
12
+ function rollupJs() {
13
+ writeFileSync(data.fileName('rollup.config.js'), `import typescript from '@rollup/plugin-typescript';
14
+ import resolve from '@rollup/plugin-node-resolve';
15
+ import commonjs from '@rollup/plugin-commonjs';
16
+ import json from '@rollup/plugin-json';
17
+ // import terser from '@rollup/plugin-terser';
18
+ import cleanup from 'rollup-plugin-cleanup';
19
+ import copy from 'rollup-plugin-copy';
20
+
21
+ export default {
22
+ input: './index.ts',
23
+ output: [
24
+ {
25
+ format: 'es',
26
+ entryFileNames: '[name].mjs',
27
+ preserveModules: true,
28
+ sourcemap: false,
29
+ exports: 'named',
30
+ dir: 'dist/mjs',
31
+ },
32
+ // 若是生成 \`bin\` 类型,或是生成的文件不包含 commonJs,下面导出 commonJs 的配置可是删除
33
+ {
34
+ format: 'cjs',
35
+ entryFileNames: '[name].cjs',
36
+ preserveModules: true,
37
+ sourcemap: false,
38
+ exports: 'named',
39
+ dir: 'dist/cjs',
40
+ },
41
+ ],
42
+ // 配置需要排除的包
43
+ external: id =>
44
+ /^(node:)|^(tslib)|^(a-js-tools)|^(a-node-tools)|^(a-command)/.test(id),
45
+ plugins: [
46
+ resolve(),
47
+ commonjs(),
48
+ // 可打包 json 内容
49
+ json(),
50
+ typescript({
51
+ // compilerOptions: {},
52
+ // exclude: ["./node_modules", "./test"],
53
+ }),
54
+ // 打包压缩,自动去注释
55
+ // terser(),
56
+ // 去除无用代码
57
+ cleanup(),
58
+ copy({
59
+ targets: [
60
+ { src: 'package.json', dest: 'dist' },
61
+ { src: 'README.md', dest: 'dist' },
62
+ { src: 'LICENSE', dest: 'dist' },
63
+ // 若是生成 bin 类型的包,可以将下面的代码打开
64
+ // { src: 'bin', dest: 'dist' },
65
+ ],
66
+ }),
67
+ ],
68
+ };`);
69
+ }
70
+ /** 导出配置 rollup.config.test.js 文件 */
71
+ function rollupConfigTestJs() {
72
+ writeFileSync(data.fileName('rollup.config.test.js'), `import typescript from '@rollup/plugin-typescript';
73
+ import resolve from '@rollup/plugin-node-resolve';
74
+ import commonjs from '@rollup/plugin-commonjs';
75
+ import json from '@rollup/plugin-json';
76
+ import cleanup from 'rollup-plugin-cleanup';
77
+
78
+ /** 配置需要不打包进生产包的包名配置 */
79
+ const externalList = [
80
+ 'nodejs',
81
+ 'tslib',
82
+ 'a-js-tools',
83
+ 'a-node-tools',
84
+ 'a-command',
85
+ ];
86
+
87
+ export default {
88
+ input: 'test/index.ts',
89
+ output: [
90
+ {
91
+ format: 'es',
92
+ entryFileNames: '[name].mjs',
93
+ preserveModules: true,
94
+ sourcemap: false,
95
+ exports: 'named',
96
+ dir: 'test/out',
97
+ },
98
+ ],
99
+ // 配置需要排除的包
100
+ external: id => externalList.some(i => id.startsWith(i)),
101
+ plugins: [
102
+ resolve(),
103
+ commonjs(),
104
+ // 打包压缩,自动去注释
105
+ // terser(),
106
+ // 可打包 json 内容
107
+ json(),
108
+ typescript({}),
109
+ // 去除无用代码
110
+ cleanup(),
111
+ ],
112
+ };
113
+ `);
114
+ }
115
+
116
+ export { rollup, rollupConfigTestJs, rollupJs };
@@ -0,0 +1,48 @@
1
+ import { writeToJsonFile } from '../tools.mjs';
2
+
3
+ /** 将创建三个 tsconfig 文件的方法合并 */
4
+ function tsconfigJson() {
5
+ tsconfigBaseJson();
6
+ _tsconfigJson();
7
+ tsconfigTypesJson();
8
+ }
9
+ /** 导出生成 tsconfig.base.json 文件 */
10
+ function tsconfigBaseJson() {
11
+ writeToJsonFile('tsconfig.base.json', {
12
+ compilerOptions: {
13
+ baseUrl: '.',
14
+ jsx: 'preserve',
15
+ strict: true,
16
+ target: 'ESNext',
17
+ module: 'ESNext',
18
+ skipLibCheck: true,
19
+ esModuleInterop: true,
20
+ moduleResolution: 'Bundler',
21
+ allowSyntheticDefaultImports: true,
22
+ lib: ['ESNext', 'DOM'],
23
+ sourceMap: false,
24
+ },
25
+ });
26
+ }
27
+ /** 导出生成 tsconfig.json 配置文件 */
28
+ function _tsconfigJson() {
29
+ writeToJsonFile('tsconfig.json', {
30
+ extends: './tsconfig.base.json',
31
+ include: ['index.ts', 'src/**/*.ts', '**.d.ts', 'test/**/*.ts'],
32
+ exclude: ['node_modules', 'dist'],
33
+ });
34
+ }
35
+ /** 导出生成的生产环境的 .d.ts 文件的 tsconfig 配置 */
36
+ function tsconfigTypesJson() {
37
+ writeToJsonFile('tsconfig.types.json', {
38
+ extends: './tsconfig.base.json',
39
+ compilerOptions: {
40
+ emitDeclarationOnly: true,
41
+ declaration: true,
42
+ declarationDir: 'dist/types',
43
+ },
44
+ exclude: ['node_modules', 'test', 'dist'],
45
+ });
46
+ }
47
+
48
+ export { _tsconfigJson, tsconfigBaseJson, tsconfigJson, tsconfigTypesJson };
@@ -0,0 +1,20 @@
1
+ import { pathJoin } from 'a-node-tools';
2
+ import { mkdirSync, writeFileSync } from 'node:fs';
3
+ import data from '../data.mjs';
4
+
5
+ /**
6
+ *
7
+ * 添加 test 文件夹
8
+ *
9
+ * 及其下面的 index.ts 文件
10
+ */
11
+ /** 创建 test 及相关的文件 */
12
+ function testFile() {
13
+ const testCwd = pathJoin(data.cwd, 'test');
14
+ mkdirSync(testCwd);
15
+ writeFileSync(pathJoin(testCwd, 'index.ts'), `import { _p } from 'a-node-tools';
16
+ // print 'hello world' on the terminal
17
+ _p('hello world');`);
18
+ }
19
+
20
+ export { testFile };
@@ -0,0 +1,14 @@
1
+ import { writeJsonFile } from 'a-node-tools';
2
+ import data from './data.mjs';
3
+
4
+ /**
5
+ * 向文件写入 json 数据
6
+ *
7
+ * @param fileName {@link string} 写入的文件名
8
+ * @param jsonData 写入的数据
9
+ */
10
+ function writeToJsonFile(fileName, jsonData) {
11
+ writeJsonFile(data.fileName(fileName), jsonData);
12
+ }
13
+
14
+ export { writeToJsonFile };
package/package.json CHANGED
@@ -1,62 +1,68 @@
1
- {
2
- "name": "create-a-npm",
3
- "type": "module",
4
- "version": "0.0.0",
5
- "author": "lmssee <lmssee@outlook.com> (https://lmssee.com)",
6
- "description": "a cli for create a node package module",
7
- "scripts": {
8
- "b": "rollup --config rollup.config.js && tsc -p tsconfig.types.json",
9
- "build": "npx ixxx rm dist run b",
10
- "clean": "npx ixxx up -d rm dist node_modules run npm install run b",
11
- "diff": "npx ixxx pkg diff",
12
- "test": "echo 'welcome to see mi, yes , is mi'"
13
- },
14
- "files": [
15
- "out",
16
- "types"
17
- ],
18
- "keywords": [
19
- "create-a-npm",
20
- "create-a-node-package-module"
21
- ],
22
- "license": "ISC",
23
- "repository": {
24
- "type": "git",
25
- "url": "git+https://github.com/lmssee/.git"
26
- },
27
- "homepage": "https://lmssee.github.io/ismi",
28
- "bugs": {
29
- "url": "https://github.com/lmssee/ismi/issues",
30
- "email": "lmssee@outlook.com"
31
- },
32
- "publishConfig": {
33
- "access": "public",
34
- "registry": "https://registry.npmjs.org/"
35
- },
36
- "dependencies": {
37
- "ismi-command": "^0.0.13",
38
- "ismi-js-tools": "^0.0.4",
39
- "ismi-node-tools": "^0.0.14"
40
- },
41
- "devDependencies": {
42
- "@eslint/js": "^9.6.0",
43
- "@rollup/plugin-commonjs": "^25.0.8",
44
- "@rollup/plugin-json": "^6.1.0",
45
- "@rollup/plugin-node-resolve": "^15.2.3",
46
- "@rollup/plugin-terser": "^0.4.4",
47
- "@rollup/plugin-typescript": "^11.1.6",
48
- "@types/node": "^20.14.10",
49
- "eslint": "^8.57.0",
50
- "eslint-config-prettier": "^9.1.0",
51
- "globals": "^15.8.0",
52
- "prettier": "^3.3.2",
53
- "rollup": "^4.18.1",
54
- "rollup-plugin-cleanup": "^3.2.1",
55
- "rollup-plugin-copy": "^3.5.0",
56
- "typescript": "^5.5.3",
57
- "typescript-eslint": "^7.16.0"
58
- },
59
- "bin": {
60
- "create-a-npm": "bin/index.js"
61
- }
62
- }
1
+ {
2
+ "name": "create-a-npm",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "author": "lmssee <lmssee@outlook.com> (https://lmssee.com)",
6
+ "description": "a cli for create a node package module(一个一键生成一个符合特定规则 <就是一个简单的代码模板库> 的 npm 包",
7
+ "scripts": {
8
+ "b": "rollup --config rollup.config.js && tsc -p tsconfig.types.json",
9
+ "build": "npx ixxx rm dist run b",
10
+ "clean": "npx ixxx up -d rm dist node_modules run npm install run b",
11
+ "diff": "npx ixxx pkg diff",
12
+ "prettier": "npx prettier . --write",
13
+ "beautify": "npm run prettier",
14
+ "eslint": "npx eslint src",
15
+ "test": "npx ixxx rm test/out && rollup --config rollup.config.test.js && npx ixxx cls && node --trace-warnings test/out/test/index.mjs cm -i",
16
+ "versionPatch": "npm version patch --force --no-git-tag-version --allow-same-version=true",
17
+ "up": "npm run versionPatch && npm run build && cd dist && npm publish && cd ../"
18
+ },
19
+ "files": [
20
+ "bin/",
21
+ "mjs/",
22
+ "types/"
23
+ ],
24
+ "keywords": [
25
+ "create-a-npm",
26
+ "create-a-node-package-module"
27
+ ],
28
+ "license": "ISC",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/lmssee/createANpm.git"
32
+ },
33
+ "homepage": "https://lmssee.github.io/createANpm",
34
+ "bugs": {
35
+ "url": "https://github.com/lmssee/createANpm/issues",
36
+ "email": "lmssee@outlook.com"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "registry": "https://registry.npmjs.org/"
41
+ },
42
+ "devDependencies": {
43
+ "@eslint/js": "^9.8.0",
44
+ "@rollup/plugin-commonjs": "^25.0.8",
45
+ "@rollup/plugin-json": "^6.1.0",
46
+ "@rollup/plugin-node-resolve": "^15.2.3",
47
+ "@rollup/plugin-terser": "^0.4.4",
48
+ "@rollup/plugin-typescript": "^11.1.6",
49
+ "@types/node": "^20.14.13",
50
+ "eslint": "^8.57.0",
51
+ "eslint-config-prettier": "^9.1.0",
52
+ "globals": "^15.9.0",
53
+ "prettier": "^3.3.3",
54
+ "rollup": "^4.19.2",
55
+ "rollup-plugin-cleanup": "^3.2.1",
56
+ "rollup-plugin-copy": "^3.5.0",
57
+ "typescript": "^5.5.4",
58
+ "typescript-eslint": "^7.18.0"
59
+ },
60
+ "bin": {
61
+ "create-a-npm": "bin/index.js"
62
+ },
63
+ "dependencies": {
64
+ "a-command": "^0.0.4",
65
+ "a-js-tools": "^0.0.0",
66
+ "a-node-tools": "^0.0.4"
67
+ }
68
+ }
@@ -0,0 +1,4 @@
1
+ /** Inquire about the current package name \
2
+ * 查看是否当前有项目名
3
+ */
4
+ export default function askForName(): Promise<void>;
@@ -0,0 +1,3 @@
1
+ import { Command } from 'a-command';
2
+ declare const command: Command;
3
+ export { command };
@@ -0,0 +1,4 @@
1
+ /**
2
+ *
3
+ * 开始根据数据创建包 */
4
+ export declare function createNpm(): Promise<void>;
@@ -0,0 +1,6 @@
1
+ /*** 自定义插件的安装 */
2
+ /**
3
+ *
4
+ * 自定义
5
+ */
6
+ export default function (): Promise<void>;
@@ -0,0 +1,25 @@
1
+ /** 导出构建数据 */
2
+ declare const _default: {
3
+ /** 工作目录 */
4
+ cwd: string;
5
+ /** 创建文件的路径 */
6
+ fileName(str: string): string;
7
+ /** 项目名称
8
+ *
9
+ * 该值在 askForName 中进行赋值
10
+ */
11
+ name: string;
12
+ /** 是否携带 npx 指令
13
+ * 该值将在 custom 过程中进行赋值 */
14
+ bin: boolean;
15
+ /** 包中需要的内容 */
16
+ package: {
17
+ /**包名称 */
18
+ name: string;
19
+ /** 依赖 */
20
+ dependencies: any;
21
+ /** 开发依赖 */
22
+ devDependencies: any;
23
+ };
24
+ };
25
+ export default _default;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 导出生成 src 的主文件
3
+ */
4
+ export declare function src(): void;
@@ -0,0 +1,2 @@
1
+ /** 导出生成 index.ts 文件 */
2
+ export declare function indexTs(): void;
@@ -0,0 +1,2 @@
1
+ /** */
2
+ export declare function srcIndexTs(): void;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * eslint 配置
3
+ *
4
+ */
5
+ export declare function eslintConfig(): void;
@@ -0,0 +1,5 @@
1
+ /**
2
+ *
3
+ * 导出 package 的主文件
4
+ */
5
+ export declare function packageIndex(): void;
@@ -0,0 +1,2 @@
1
+ /** 生成 package.json 文件内容 */
2
+ export declare function packageJson(): void;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 导出 prettier 的相关配置文件
3
+ */
4
+ export declare function prettier(): void;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 导出生成一些琐碎而又必须的文件
3
+ */
4
+ export declare function readme(): void;
5
+ /** 导出生成 license 文件 */
6
+ export declare function license(): void;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 生成 rollup 打包工具的配置文件信息
3
+ */
4
+ export declare function rollup(): void;
5
+ /** 导出生成 rollup.config.js 文件 */
6
+ export declare function rollupJs(): void;
7
+ /** 导出配置 rollup.config.test.js 文件 */
8
+ export declare function rollupConfigTestJs(): void;
@@ -0,0 +1,8 @@
1
+ /** 将创建三个 tsconfig 文件的方法合并 */
2
+ export declare function tsconfigJson(): void;
3
+ /** 导出生成 tsconfig.base.json 文件 */
4
+ export declare function tsconfigBaseJson(): void;
5
+ /** 导出生成 tsconfig.json 配置文件 */
6
+ export declare function _tsconfigJson(): void;
7
+ /** 导出生成的生产环境的 .d.ts 文件的 tsconfig 配置 */
8
+ export declare function tsconfigTypesJson(): void;
@@ -0,0 +1,8 @@
1
+ /**
2
+ *
3
+ * 添加 test 文件夹
4
+ *
5
+ * 及其下面的 index.ts 文件
6
+ */
7
+ /** 创建 test 及相关的文件 */
8
+ export declare function testFile(): void;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 打印一些内容
3
+ *
4
+ * @param message {@link String} 将要打印的信息
5
+ */
6
+ export declare function printSome(message: string): void;
7
+ /**
8
+ * 向文件写入 json 数据
9
+ *
10
+ * @param fileName {@link string} 写入的文件名
11
+ * @param jsonData 写入的数据
12
+ */
13
+ export declare function writeToJsonFile(fileName: string, jsonData: unknown): void;