Skip to content

Commit

Permalink
feat: 支持自动生成 UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
yanranxiaoxi committed Nov 1, 2024
1 parent c107c16 commit 1309106
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 位于中国大陆网络环境的用户,可以取消下行的注释,以获得更快的 NPM 安装速度
# registry=https://registry.npmmirror.com
37 changes: 37 additions & 0 deletions build/packaged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,47 @@ function multiLineStrToArray(str: string): Array<string> {
return str.split(/[\r\n]+/);
}

/**
* 检查 UUID 是否合法
*
* @param uuid - UUID
* @returns 是否合法
*/
function testUuid(uuid?: string): uuid is string {
const regExp = /^[a-z0-9]{32}$/g;
if (uuid && uuid !== '00000000000000000000000000000000') {
return regExp.test(uuid.trim());
} else {
return false;
}
}

/**
* 获取正确的 UUID
*
* @param uuid - UUID
* @returns UUID
*/
function fixUuid(uuid?: string): string {
uuid = uuid?.trim() || undefined;
if (testUuid(uuid)) {
return uuid.trim();
} else {
return crypto.randomUUID().replaceAll('-', '');
}
}

/**
* 主逻辑方法
*/
function main() {
if (!testUuid(extensionConfig.uuid)) {
const newExtensionConfig = { ...extensionConfig };
// @ts-ignore
delete newExtensionConfig.default;
newExtensionConfig.uuid = fixUuid(extensionConfig.uuid);
fs.writeJsonSync(__dirname + '/../extension.json', newExtensionConfig, { spaces: '\t', EOL: '\n', encoding: 'utf-8' });
}
const filepathListWithoutFilter = fs.readdirSync(__dirname + '/../', { encoding: 'utf-8', recursive: true });
const edaignoreListWithoutResolve = multiLineStrToArray(fs.readFileSync(__dirname + '/../.edaignore', { encoding: 'utf-8' }));
const edaignoreList: Array<string> = [];
Expand Down
4 changes: 2 additions & 2 deletions extension.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "pro-api-sdk",
"uuid": "00000000000000000000000000000000",
"uuid": "",
"displayName": "PRO API SDK",
"description": "嘉立创EDA & EasyEDA 专业版扩展 API 开发工具",
"version": "1.0.0",
"publisher": "JLCEDA <[email protected]>",
"engines": {
"eda": "^2.2.20"
"eda": "^2.2.32"
},
"license": "MIT License",
"repository": {
Expand Down
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* 入口文件
*
* 本文件为默认扩展入口文件,如果你想要配置其它文件作为入口文件,
* 请修改 `extension.json` 中的 `entry` 字段;
*
* 请在此处使用 `export` 导出所有你希望在 `headerMenus` 中引用的方法,
* 方法通过方法名与 `headerMenus` 关联。
*
* 如需了解更多开发细节,请阅读:
* https://prodocs.lceda.cn/cn/api/guide/
*/
import * as extensionConfig from '../extension.json';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down

0 comments on commit 1309106

Please sign in to comment.