create-a-npm 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -17,4 +17,4 @@ npm create a-npm
17
17
 
18
18
  ## Other languages
19
19
 
20
- [English](https://github.com/lmssee/ismi/blob/main/README.md) [中文](https://github.com/lmssee/ismi/blob/main/自述文件.md)
20
+ [English](https://github.com/lmssee/createANpm/blob/main/README.md) [中文](https://github.com/lmssee/createANpm/blob/main/自述文件.md)
package/bin/index.js CHANGED
File without changes
package/mjs/index.mjs CHANGED
@@ -2,6 +2,13 @@ import askForName from './src/askForName.mjs';
2
2
  import { createNpm } from './src/createNpm.mjs';
3
3
  import custom from './src/custom.mjs';
4
4
 
5
+ /****************************************************************************
6
+ * @Author lmssee
7
+ * @Email lmssee@outlook.com
8
+ * @FileName index.ts
9
+ * @Date 周三 08/28/2024
10
+ * @Description 包源文件的跟文件,该文件暴露相应的接口
11
+ ****************************************************************************/
5
12
  /// 设定包名
6
13
  await askForName();
7
14
  /// 参看是否自定义包的内容,这里会自定义是否使用 eslint 等相关内容
@@ -1,5 +1,13 @@
1
1
  import { Command } from 'a-command';
2
2
 
3
+ /****************************************************************************
4
+ * @Author lmssee
5
+ * @Email lmssee@outlook.com
6
+ * @ProjectName create-a-npm
7
+ * @FileName command.ts
8
+ * @CreateDate 周五 08/30/2024
9
+ * @Description 一个由 `a-command` 创建的 command 对象
10
+ ****************************************************************************/
3
11
  const command = new Command('create-a-npm');
4
12
  /** 暂未配置自定义项,后续会跟上 */
5
13
  // command.bind({ 'custom <cm> (自定义)': [] });
@@ -5,6 +5,15 @@ import { packageIndex } from './package/index.mjs';
5
5
  import { testFile } from './test/index.mjs';
6
6
  import { src } from './library/index.mjs';
7
7
 
8
+ /****************************************************************************
9
+ * @Author lmssee
10
+ * @Email lmssee@outlook.com
11
+ * @ProjectName crate-a-npm
12
+ * @FileName createNpm.ts
13
+ * @CreateDate 周五 08/30/2024
14
+ * @Description 创建 npm 主要内容
15
+ * 该操作出现在命名完成后
16
+ ****************************************************************************/
8
17
  /**
9
18
  *
10
19
  * 开始根据数据创建包 */
@@ -1,12 +1,39 @@
1
1
  import './command.mjs';
2
- import 'a-node-tools';
2
+ import { runOtherCode, cursorMoveUp } from 'a-node-tools';
3
3
 
4
+ /****************************************************************************
5
+ * @Author lmssee
6
+ * @Email lmssee@outlook.com
7
+ * @FileName custom.ts
8
+ * @Date 周三 08/28/2024
9
+ * @Description
10
+ ****************************************************************************/
4
11
  /*** 自定义插件的安装 */
12
+ // import { homedir } from 'node:os';
13
+ /** TODO
14
+ *
15
+ * 后期这里要添加 配置文件的读取和配置
16
+ *
17
+ * 思路:
18
+ * - 从 node:os 的 homedir 获取用户的文件夹目录
19
+ *
20
+ */
5
21
  /**
6
22
  *
7
23
  * 自定义
8
24
  */
9
- async function custom () {
25
+ async function custom() {
26
+ const { data } = await runOtherCode({ code: 'git config user.name' });
27
+ console.log(data?.replace(/(.*)\n$/, '$1'));
28
+ cursorMoveUp(3);
29
+ /** 用户文件的根目录 */
30
+ // const userDir: string = homedir();
31
+ /** 判断当前文件是否存在(应该是存在的吧,这里验证有点多此一举) */
32
+ // const testDir = dirEmpty(userDir) > -1;
33
+ // if (testDir) {
34
+ // console.log(userDir);
35
+ // console.log(dirEmpty(userDir));
36
+ // }
10
37
  return;
11
38
  }
12
39
 
package/mjs/src/data.mjs CHANGED
@@ -1,6 +1,15 @@
1
1
  import { initializeFile, getDirectoryBy, readFileToJsonSync, pathJoin } from 'a-node-tools';
2
2
  import { basename } from 'node:path';
3
3
 
4
+ /****************************************************************************
5
+ * @Author lmssee
6
+ * @Email lmssee@outlook.com
7
+ * @ProjectName create-a-npm
8
+ * @FileName data.ts
9
+ * @CreateDate 周五 08/30/2024
10
+ * @Description 数据中心
11
+ * 当配置包名时,后自动创建包的工作路径
12
+ ****************************************************************************/
4
13
  /** 初始化当前工作文件路径 */
5
14
  const [__dirname] = initializeFile();
6
15
  /** 根据当前被调用文件查找当前包的 package.json 文件配置 */
@@ -1,19 +1,26 @@
1
1
  import data from '../data.mjs';
2
2
  import { pathJoin } from 'a-node-tools';
3
- import { writeFileSync, mkdirSync } from 'node:fs';
3
+ import { mkdirSync } from 'node:fs';
4
+ import { indexTs } from './indexTs.mjs';
5
+ import { srcIndexTs } from './srcIndexTs.mjs';
4
6
 
7
+ /****************************************************************************
8
+ * @Author lmssee
9
+ * @Email lmssee@outlook.com
10
+ * @FileName index.ts
11
+ * @Date 周三 08/28/2024
12
+ * @Description 生成 sec 文件夹,并导入其他生成项目文件的模块
13
+ ****************************************************************************/
5
14
  /**
6
15
  * 导出生成 src 的主文件
7
16
  */
8
17
  function src() {
9
- /// index.ts
10
- writeFileSync(data.fileName('index.ts'), `import { _p } from 'a-node-tools';\n _p('hello world');`);
11
- // 创建文件
18
+ // 创建 src 文件夹
12
19
  mkdirSync(pathJoin(data.cwd, 'src'));
20
+ /// index.ts
21
+ indexTs();
13
22
  //
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}\`)`);
23
+ srcIndexTs();
17
24
  }
18
25
 
19
26
  export { src };
@@ -0,0 +1,23 @@
1
+ import { writeFileSync } from 'node:fs';
2
+ import data from '../data.mjs';
3
+
4
+ /** 导出生成 index.ts 文件 */
5
+ function indexTs() {
6
+ /// index.ts
7
+ writeFileSync(data.fileName('index.ts'), `import './src/index';
8
+ /** 测试函数
9
+ *
10
+ * 仅做初始化后测试用
11
+ *
12
+ * @returns {@link undefined}
13
+ */
14
+ export function testFunction() {
15
+ console.log('**********************');
16
+ console.log('测试函数打印内容');
17
+ console.log('**********************');
18
+ return;
19
+ }
20
+ `);
21
+ }
22
+
23
+ export { indexTs };
@@ -0,0 +1,14 @@
1
+ import { writeFileSync } from 'node:fs';
2
+ import data from '../data.mjs';
3
+
4
+ /** */
5
+ function srcIndexTs() {
6
+ writeFileSync(data.fileName('src/index.ts'), `import { _p } from 'a-node-tools';
7
+
8
+ // print 'hello ${data.name} on the terminal'
9
+ // 向终端输出 "你好 ${data.name}"
10
+ _p('welcome ${data.name}');
11
+ `);
12
+ }
13
+
14
+ export { srcIndexTs };
@@ -1,6 +1,15 @@
1
1
  import data from '../data.mjs';
2
2
  import { writeToJsonFile } from '../tools.mjs';
3
3
 
4
+ /****************************************************************************
5
+ * @Author lmssee
6
+ * @Email lmssee@outlook.com
7
+ * @FileName package.ts
8
+ * @Date 周三 08/28/2024
9
+ * @Description 生成 package.json 文件内容
10
+ *
11
+ * 每次调用时都会访问本地的 npm 信息并返回,每一次版本更新都会导致包的更新
12
+ ****************************************************************************/
4
13
  /**
5
14
  * 这里之前返回的是一个对象,导致 js 在预编译的时候直接生成一个静态数据
6
15
  * 而无法在调用 packageJson 的时候真正的将 data 的最新值带入
@@ -16,12 +25,14 @@ const initData = () => ({
16
25
  typings: 'types/index.d.ts',
17
26
  author: '___ <___@___.___> (https://___.___)',
18
27
  description: 'here is the project description, please change the content with double underline',
19
- script: {
28
+ scripts: {
20
29
  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',
30
+ build: 'npx ixxx rm dist run b',
31
+ diff: 'npx ixxx pkg diff',
32
+ eslint: 'npx ixxx cls && eslint src',
33
+ beautify: 'npm run prettier',
34
+ prettier: 'npx ixxx cls && prettier . --write',
35
+ test: 'npx ixxx cls && rollup --config rollup.config.test.js && node test/out/test/index.mjs',
25
36
  },
26
37
  files: ['mjs', 'cjs', 'types'],
27
38
  exports: {
@@ -2,18 +2,33 @@ import { writeFileSync } from 'node:fs';
2
2
  import data from '../data.mjs';
3
3
  import { writeToJsonFile } from '../tools.mjs';
4
4
 
5
+ /****************************************************************************
6
+ * @Author lmssee
7
+ * @Email lmssee@outlook.com
8
+ * @FileName prettier.ts
9
+ * @Date 周三 08/28/2024
10
+ * @Description 生成 prettier 规则的文件
11
+ *
12
+ * 包含:
13
+ * - .prettierignore prettier 执行忽略文件
14
+ * - .prettierrc prettier 配置文件
15
+ ****************************************************************************/
5
16
  /**
6
17
  * 导出 prettier 的相关配置文件
18
+ *
19
+ * 生成包含:
20
+ * - .prettierignore prettier 执行忽略文件
21
+ * - .prettierrc prettier 配置文件
7
22
  */
8
23
  function prettier() {
9
24
  // 写入 prettier ignore 忽略规则
10
- writeFileSync(data.fileName('.prettierignore'), `node_modules/*
25
+ writeFileSync(data.fileName('.prettierignore'), `node_modules
11
26
 
12
- */node_modules
27
+ **/node_modules
13
28
 
14
29
  ## 打包文件
15
30
 
16
- list
31
+ dist
17
32
 
18
33
  test/out
19
34
 
@@ -22,13 +22,13 @@ function readme() {
22
22
  /// LICENSE
23
23
  license();
24
24
  /// 生成 .gitignore 文件
25
- writeFileSync(data.fileName('.gitignore'), `node_modules/*
25
+ writeFileSync(data.fileName('.gitignore'), `node_modules
26
26
 
27
- */node_modules
27
+ **/node_modules
28
28
 
29
29
  ## 打包文件
30
30
 
31
- list
31
+ dist
32
32
 
33
33
  test/out
34
34
 
@@ -1,6 +1,7 @@
1
1
  import { pathJoin } from 'a-node-tools';
2
2
  import { mkdirSync, writeFileSync } from 'node:fs';
3
3
  import data from '../data.mjs';
4
+ import { testFunction } from './testFunction.mjs';
4
5
 
5
6
  /**
6
7
  *
@@ -8,13 +9,23 @@ import data from '../data.mjs';
8
9
  *
9
10
  * 及其下面的 index.ts 文件
10
11
  */
12
+ console.log('====================================');
13
+ console.log(999999);
14
+ console.log('====================================');
11
15
  /** 创建 test 及相关的文件 */
12
16
  function testFile() {
17
+ createIndexTs();
18
+ // 创建 test testFunction 文件
19
+ testFunction();
20
+ }
21
+ function createIndexTs() {
13
22
  const testCwd = pathJoin(data.cwd, 'test');
23
+ console.log('====================================');
24
+ console.log(data.cwd);
25
+ console.log('====================================');
14
26
  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');`);
27
+ /** 写入测试跟文件 */
28
+ writeFileSync(pathJoin(testCwd, 'index.ts'), "import './testTestFunction';");
18
29
  }
19
30
 
20
31
  export { testFile };
@@ -0,0 +1,25 @@
1
+ import { pathJoin } from 'a-node-tools';
2
+ import { writeFileSync } from 'node:fs';
3
+ import data from '../data.mjs';
4
+
5
+ /****************************************************************************
6
+ * @Author lmssee
7
+ * @Email lmssee@outlook.com
8
+ * @FileName testFunction.ts
9
+ * @Date 周三 08/28/2024
10
+ * @Description 测试函数的测试文件,仅做测试用
11
+ * 倘若后期删除 `testFunction` 测试函数,该文件亦当移除
12
+ ****************************************************************************/
13
+ function testFunction() {
14
+ /** 写入 */
15
+ writeFileSync(pathJoin(data.cwd, 'test/testTestFunction.ts'), `import test from 'node:test';
16
+ import assert from 'node:assert';
17
+ import { testFunction } from '../index';
18
+
19
+
20
+ test('测试测试函数', () => {
21
+ assert.equal(testFunction(), undefined ,'当两者不相等的我会被打印出来');
22
+ })`);
23
+ }
24
+
25
+ export { testFunction };
package/mjs/src/tools.mjs CHANGED
@@ -1,6 +1,17 @@
1
1
  import { writeJsonFile } from 'a-node-tools';
2
2
  import data from './data.mjs';
3
3
 
4
+ /****************************************************************************
5
+ * @Author lmssee
6
+ * @Email lmssee@outlook.com
7
+ * @ProjectName create-a-npm
8
+ * @FileName tools.ts
9
+ * @Date 周三 08/28/2024
10
+ * @Description 工具函数文件
11
+ *
12
+ * - printSome 打印彩色信息
13
+ * - writeToJsonFile 将 json 写入新的文件
14
+ ****************************************************************************/
4
15
  /**
5
16
  * 向文件写入 json 数据
6
17
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-a-npm",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.3",
5
5
  "author": "lmssee <lmssee@outlook.com> (https://lmssee.com)",
6
6
  "description": "a cli for create a node package module(一个一键生成一个符合特定规则 <就是一个简单的代码模板库> 的 npm 包",
7
7
  "scripts": {
@@ -40,18 +40,18 @@
40
40
  "registry": "https://registry.npmjs.org/"
41
41
  },
42
42
  "devDependencies": {
43
- "@eslint/js": "^9.8.0",
43
+ "@eslint/js": "^9.9.1",
44
44
  "@rollup/plugin-commonjs": "^25.0.8",
45
45
  "@rollup/plugin-json": "^6.1.0",
46
46
  "@rollup/plugin-node-resolve": "^15.2.3",
47
47
  "@rollup/plugin-terser": "^0.4.4",
48
48
  "@rollup/plugin-typescript": "^11.1.6",
49
- "@types/node": "^20.14.13",
49
+ "@types/node": "^20.16.2",
50
50
  "eslint": "^8.57.0",
51
51
  "eslint-config-prettier": "^9.1.0",
52
52
  "globals": "^15.9.0",
53
53
  "prettier": "^3.3.3",
54
- "rollup": "^4.19.2",
54
+ "rollup": "^4.21.1",
55
55
  "rollup-plugin-cleanup": "^3.2.1",
56
56
  "rollup-plugin-copy": "^3.5.0",
57
57
  "typescript": "^5.5.4",
@@ -63,6 +63,6 @@
63
63
  "dependencies": {
64
64
  "a-command": "^0.0.4",
65
65
  "a-js-tools": "^0.0.0",
66
- "a-node-tools": "^0.0.4"
66
+ "a-node-tools": "^0.0.5"
67
67
  }
68
68
  }
@@ -1,3 +1,11 @@
1
+ /****************************************************************************
2
+ * @Author lmssee
3
+ * @Email lmssee@outlook.com
4
+ * @ProjectName create-a-npm
5
+ * @FileName command.ts
6
+ * @CreateDate 周五 08/30/2024
7
+ * @Description 一个由 `a-command` 创建的 command 对象
8
+ ****************************************************************************/
1
9
  import { Command } from 'a-command';
2
10
  declare const command: Command;
3
11
  export { command };
@@ -1,6 +1,21 @@
1
+ /****************************************************************************
2
+ * @Author lmssee
3
+ * @Email lmssee@outlook.com
4
+ * @FileName custom.ts
5
+ * @Date 周三 08/28/2024
6
+ * @Description
7
+ ****************************************************************************/
1
8
  /*** 自定义插件的安装 */
9
+ /** TODO
10
+ *
11
+ * 后期这里要添加 配置文件的读取和配置
12
+ *
13
+ * 思路:
14
+ * - 从 node:os 的 homedir 获取用户的文件夹目录
15
+ *
16
+ */
2
17
  /**
3
18
  *
4
19
  * 自定义
5
20
  */
6
- export default function (): Promise<void>;
21
+ export default function custom(): Promise<void>;
@@ -0,0 +1,7 @@
1
+ /****************************************************************************
2
+ * @Author lmssee
3
+ * @Email lmssee@outlook.com
4
+ * @FileName testFunction.ts
5
+ * @Date 周三 08/28/2024
6
+ * @Description 测试函数添加
7
+ ****************************************************************************/
@@ -1,4 +1,8 @@
1
1
  /**
2
2
  * 导出 prettier 的相关配置文件
3
+ *
4
+ * 生成包含:
5
+ * - .prettierignore prettier 执行忽略文件
6
+ * - .prettierrc prettier 配置文件
3
7
  */
4
8
  export declare function prettier(): void;
@@ -0,0 +1,9 @@
1
+ /****************************************************************************
2
+ * @Author lmssee
3
+ * @Email lmssee@outlook.com
4
+ * @FileName testFunction.ts
5
+ * @Date 周三 08/28/2024
6
+ * @Description 测试函数的测试文件,仅做测试用
7
+ * 倘若后期删除 `testFunction` 测试函数,该文件亦当移除
8
+ ****************************************************************************/
9
+ export declare function testFunction(): void;
@@ -2,8 +2,9 @@
2
2
  * 打印一些内容
3
3
  *
4
4
  * @param message {@link String} 将要打印的信息
5
+ * @returns void
5
6
  */
6
- export declare function printSome(message: string): void;
7
+ export declare function printSome(message: string): undefined;
7
8
  /**
8
9
  * 向文件写入 json 数据
9
10
  *