Skip to content

Commit

Permalink
调整结构,区分不同环境的包
Browse files Browse the repository at this point in the history
  • Loading branch information
chenbimo committed Dec 1, 2024
1 parent 22ac3c8 commit bc54df4
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 136 deletions.
4 changes: 3 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
registry=https://registry.npmmirror.com
# registry=https://registry.npmjs.org
# registry=https://registry.npmjs.org
proxy=http://127.0.0.1:7890
https-proxy=http://127.0.0.1:7890
65 changes: 0 additions & 65 deletions eslint.config.js

This file was deleted.

81 changes: 41 additions & 40 deletions generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,50 @@ import { basename, resolve } from 'node:path';
import { readJsonSync } from 'fs-extra/esm';

const categories = {};
const dirPath = 'lib';

const fileData = [];
const libNames = [];
const dirNames = [];
['lib', 'libNode', 'libBrowser'].forEach((dirPath) => {
const fileData = [];
// const libNames = [];
const dirNames = [];

// 自动生成导出和单文件
readdirSync(dirPath).forEach((dir) => {
dirNames.push(dir);
const metaFile = resolve(dirPath, dir, '_meta.json');
const metaData = readJsonSync(metaFile);
categories[dir] = { displayName: metaData.name };
const files = readdirSync(resolve(dirPath, dir));
files.forEach((file) => {
if (file === '_meta.json') return;
if (file.endsWith('.test.js')) return;
const stat = statSync(resolve(dirPath, dir, file));
if (stat.isFile() && file.endsWith('.js')) {
const fileName = basename(file, '.js');
const filePath = resolve(dirPath, dir, file);
libNames.push(`yd_${dir}_${fileName}`);
fileData.push(
//
`export { default as yd_${dir}_${fileName} } from './${dirPath}/${dir}/${file}';\r\n`
);
// 判断是否有相关标签
const fileData2 = readFileSync(filePath, { encoding: 'utf8' });
if (!fileData2.includes('@author')) {
console.log(`${filePath} 文件缺少 [作者]`);
// 自动生成导出和单文件
readdirSync(dirPath).forEach((dir) => {
dirNames.push(dir);
const metaFile = resolve(dirPath, dir, '_meta.json');
const metaData = readJsonSync(metaFile);
categories[dir] = { displayName: metaData.name };
const files = readdirSync(resolve(dirPath, dir));
files.forEach((file) => {
if (file === '_meta.json') return;
if (file.endsWith('.test.js')) return;
const stat = statSync(resolve(dirPath, dir, file));
if (stat.isFile() && file.endsWith('.js')) {
const fileName = basename(file, '.js');
const filePath = resolve(dirPath, dir, file);
// libNames.push(`yd_${dir}_${fileName}`);
fileData.push(
//
`export { default as yd_${dir}_${fileName} } from './${dirPath}/${dir}/${file}';\r\n`
);
// 判断是否有相关标签
const fileData2 = readFileSync(filePath, { encoding: 'utf8' });
if (!fileData2.includes('@author')) {
console.log(`${filePath} 文件缺少 [作者]`);
}
if (!fileData2.includes('@category')) {
console.log(`${filePath} 文件缺少 [分类]`);
}
if (!fileData2.includes('@alias')) {
console.log(`${filePath} 文件缺少 [别名]`);
}
} else {
console.log(`${dir}/${file}不是一个函数文件`);
}
if (!fileData2.includes('@category')) {
console.log(`${filePath} 文件缺少 [分类]`);
}
if (!fileData2.includes('@alias')) {
console.log(`${filePath} 文件缺少 [别名]`);
}
} else {
console.log(`${dir}/${file}不是一个函数文件`);
}
});
});
});

writeFileSync(`./${dirPath}.js`, fileData.join(''));
writeFileSync(`./${dirPath}Names.js`, `export const ${dirPath}Names = ${JSON.stringify(libNames)};`);
console.log(`${dirPath} 数据生成完毕`);
writeFileSync(`./${dirPath}.js`, fileData.join(''));
// writeFileSync(`./${dirPath}Names.js`, `export const ${dirPath}Names = ${JSON.stringify(libNames)};`);
console.log(`${dirPath} 数据生成完毕`);
});
writeFileSync('./categories.json', JSON.stringify(categories));
4 changes: 4 additions & 0 deletions libBrowser/url/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "url",
"describe": "链接解析、验证等url相关的处理函数"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions libNode/crypto/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "加密解密",
"describe": "md5、base64、sha1等加密和解密函数"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions libNode/number/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "数字",
"describe": "数字解析、转化、随机、验证等工具函数"
}
File renamed without changes.
30 changes: 9 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "yidash",
"type": "module",
"version": "1.11.0",
"version": "1.12.1",
"private": false,
"license": "MIT",
"description": "yidash(易大师)一万个JavaScript实用方法库",
Expand All @@ -23,52 +23,40 @@
],
"exports": {
".": "./lib.js",
"./libNames": "./libNames.js"
"./node": "./libNode.js",
"./browser": "./libBrowser.js"
},
"files": [
"config/",
"lib/",
"libNode/",
"libBrowser/",
"index.js",
"LICENSE",
"package.json",
"README.md",
"lib.js",
"libNames.js"
"libNode.js",
"libBrowser.js"
],
"scripts": {
"gen": "node generate.js",
"docs": "del-cli docs & jsdoc -c jsdoc.json",
"test": "vitest",
"test-ui": "vitest --ui",
"lint": "eslint ./lib",
"lint:fix": "eslint ./lib --fix",
"format": "prettier --write .",
"inspect": "eslint --inspect-config"
"docs": "del-cli docs & jsdoc -c jsdoc.json"
},
"dependencies": {
"date-fns": "^4.1.0",
"es-toolkit": "^1.27.0"
},
"devDependencies": {
"@eslint/config-inspector": "^0.5.6",
"@eslint/js": "^9.15.0",
"@vitest/ui": "^2.1.6",
"colorette": "^2.0.20",
"del-cli": "^6.0.0",
"docdash-extended-chensuiyi": "^1.1.1",
"eslint": "^9.15.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jsdoc": "^50.6.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-regexp": "^2.7.0",
"fs-extra": "^11.2.0",
"globals": "^15.12.0",
"jsdoc": "^4.0.4",
"lint-staged": "^15.2.10",
"log-symbols": "^7.0.0",
"prettier": "^3.4.1",
"simple-git-hooks": "^2.11.1",
"vitest": "^2.1.6"
"simple-git-hooks": "^2.11.1"
},
"simple-git-hooks": {
"pre-commit": "pnpm exec lint-staged"
Expand Down
9 changes: 0 additions & 9 deletions vitest.config.mjs

This file was deleted.

0 comments on commit bc54df4

Please sign in to comment.