@any-listen/extension-kit 0.1.0 → 0.1.2

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
@@ -46,7 +46,7 @@ const config: ExtensionConfig = {
46
46
  author: 'Your Name',
47
47
  homepage: 'https://example.com',
48
48
  license: 'MIT',
49
- target_engine: 'any-listen',
49
+ target_engine: '1.0.0',
50
50
  categories: ['music'],
51
51
  tags: ['example'],
52
52
  grant: ['internet'],
package/dist/bin.js CHANGED
@@ -9,8 +9,8 @@ var { values } = parseArgs({
9
9
  publish: { type: "boolean" }
10
10
  }
11
11
  });
12
- if (values.build) import("./build-CUKFiHZ-.js");
13
- else if (values.publish) import("./publish-BUpufhVY.js");
12
+ if (values.build) import("./build-cwRtaFpY.js");
13
+ else if (values.publish) import("./publish-WfB8QiEk.js");
14
14
  else console.log("Please specify a command: build or publish");
15
15
  //#endregion
16
16
 
package/dist/bin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bin.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { argv } from 'node:process'\nimport { parseArgs } from 'node:util'\n\nconst { values } = parseArgs({\n args: argv.slice(2),\n options: {\n build: {\n type: 'boolean',\n },\n publish: {\n type: 'boolean',\n },\n },\n})\n\nif (values.build) {\n void import('./build')\n} else if (values.publish) {\n void import('./publish')\n} else {\n console.log('Please specify a command: build or publish')\n}\n"],"mappings":";;;;AAKA,IAAM,EAAE,WAAW,UAAU;CAC3B,MAAM,KAAK,MAAM,EAAE;CACnB,SAAS;EACP,OAAO,EACL,MAAM,WACP;EACD,SAAS,EACP,MAAM,WACP;EACF;CACF,CAAC;AAEF,IAAI,OAAO,MACJ,QAAO;SACH,OAAO,QACX,QAAO;IAEZ,SAAQ,IAAI,6CAA6C"}
1
+ {"version":3,"file":"bin.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { argv } from 'node:process'\nimport { parseArgs } from 'node:util'\n\nconst { values } = parseArgs({\n args: argv.slice(2),\n options: {\n build: {\n type: 'boolean',\n },\n publish: {\n type: 'boolean',\n },\n },\n})\n\nif (values.build) {\n void import('./build')\n} else if (values.publish) {\n void import('./publish')\n} else {\n console.log('Please specify a command: build or publish')\n}\n"],"mappings":";;;;AAKA,IAAM,EAAE,WAAW,UAAU;CAC3B,MAAM,KAAK,MAAM,EAAE;CACnB,SAAS;EACP,OAAO,EACL,MAAM,WACP;EACD,SAAS,EACP,MAAM,WACP;EACF;CACF,CAAC;AAEF,IAAI,OAAO,OACT,OAAY;KACP,IAAI,OAAO,SAChB,OAAY;KAEZ,QAAQ,IAAI,6CAA6C"}
@@ -95,7 +95,6 @@ var pack = async (config) => {
95
95
  };
96
96
  //#endregion
97
97
  //#region src/vite.config.ts
98
- var isProd = process.env.NODE_ENV == "production";
99
98
  var createBuildConfig = (name, filePath) => {
100
99
  return defineConfig({
101
100
  base: "./",
@@ -106,7 +105,6 @@ var createBuildConfig = (name, filePath) => {
106
105
  target: "esnext",
107
106
  emptyOutDir: true,
108
107
  minify: false,
109
- watch: isProd ? null : { buildDelay: 500 },
110
108
  outDir: state.distDir,
111
109
  rolldownOptions: {
112
110
  external: ["any-listen"],
@@ -139,4 +137,4 @@ var run = async () => {
139
137
  run();
140
138
  //#endregion
141
139
 
142
- //# sourceMappingURL=build-CUKFiHZ-.js.map
140
+ //# sourceMappingURL=build-cwRtaFpY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-cwRtaFpY.js","names":[],"sources":["../src/cpResources.ts","../src/mainifest.ts","../src/pack.ts","../src/vite.config.ts","../src/build.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { state } from './state'\n\nexport const cpResources = async () => {\n const sourcePath = state.resourcesDir\n const targetPath = path.join(state.distDir, 'resources')\n const sourceI18nPath = state.i18nDir\n const targetI18nPath = path.join(state.distDir, 'i18n')\n\n await Promise.all([\n fs.promises.cp(sourcePath, targetPath, { recursive: true }),\n fs.promises.cp(sourceI18nPath, targetI18nPath, { recursive: true }),\n ])\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { EXTENSION } from './constants'\nimport { state } from './state'\nimport type { ExtensionConfig } from './types/build'\n\nexport const createMainifest = async (config: ExtensionConfig) => {\n const mainifest = {\n id: config.id,\n name: config.name,\n description: config.description,\n icon: config.icon,\n version: config.version,\n target_engine: config.target_engine,\n author: config.author,\n homepage: config.homepage,\n license: config.license,\n categories: config.categories,\n tags: config.tags,\n grant: config.grant,\n contributes: config.contributes,\n main: EXTENSION.entryFileName,\n }\n\n await fs.promises.writeFile(path.join(state.distDir, EXTENSION.mainifestName), JSON.stringify(mainifest, null, 2), 'utf8')\n}\n","import crypto from 'node:crypto'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { EXTENSION } from './constants'\nimport { state } from './state'\nimport type { ExtensionConfig } from './types/build'\nimport { buildPackageName } from './utils'\n\nconst buildPublicKey = (publicKey: string) => {\n if (!publicKey.includes('-----BEGIN PUBLIC KEY-----')) {\n return `-----BEGIN PUBLIC KEY-----\\n${publicKey}\\n-----END PUBLIC KEY-----`\n }\n return publicKey\n}\n\nconst signData = (data: Buffer, privateKey: string) => {\n const sign = crypto.createSign('SHA256')\n sign.update(data)\n sign.end()\n const signature = sign.sign(privateKey, 'hex')\n return signature\n}\nconst verifySignature = (data: Buffer, publicKey: string, signature: string) => {\n const verify = crypto.createVerify('SHA256')\n verify.update(data)\n verify.end()\n const isValid = verify.verify(publicKey, signature, 'hex')\n return isValid\n}\n\nconst packFile = async ({ gzip, cwd, files, dist }: { gzip: boolean; cwd: string; files: string[]; dist: string }) => {\n const { c } = await import('tar')\n return new Promise<void>((resolve, reject) => {\n c(\n {\n gzip,\n cwd,\n },\n files\n )\n .pipe(fs.createWriteStream(dist))\n .on('finish', () => {\n resolve()\n })\n .on('error', reject)\n })\n}\n\nexport const pack = async (config: ExtensionConfig) => {\n let privateKey = process.env.PRI_KEY?.trim()\n let publicKey = process.env.PUB_KEY?.trim()\n if (!privateKey || !publicKey) throw new Error('Missing private key or public key')\n if (!privateKey.includes('-----BEGIN PRIVATE KEY-----')) {\n privateKey = `-----BEGIN PRIVATE KEY-----\\n${privateKey}\\n-----END PRIVATE KEY-----`\n }\n\n const unpackedDir = path.join(state.outputDir, 'unpacked')\n await fs.promises.rm(unpackedDir, { recursive: true }).catch(() => {})\n await fs.promises.mkdir(unpackedDir, { recursive: true }).catch(() => {})\n const extBundleFilePath = path.join(unpackedDir, EXTENSION.extBundleFileName)\n await packFile({\n gzip: true,\n cwd: state.distDir,\n files: [EXTENSION.entryFileName, EXTENSION.mainifestName, 'resources', 'i18n'],\n dist: extBundleFilePath,\n })\n const buf = await fs.promises.readFile(extBundleFilePath)\n const signature = signData(buf, privateKey)\n if (!verifySignature(buf, buildPublicKey(publicKey), signature)) {\n throw new Error('Signature is valid, please check your public key')\n }\n await fs.promises.writeFile(path.join(unpackedDir, EXTENSION.signFileName), `${signature}\\n${publicKey}`)\n await packFile({\n gzip: true,\n cwd: unpackedDir,\n files: [EXTENSION.extBundleFileName, EXTENSION.signFileName],\n dist: path.join(state.outputDir, buildPackageName(config)),\n })\n}\n","import { defineConfig } from 'vite'\n\nimport { EXTENSION } from './constants'\nimport { state } from './state'\n\nconst createBuildConfig = (name: string, filePath: string) => {\n return defineConfig({\n base: './',\n mode: process.env.NODE_ENV,\n publicDir: false,\n resolve: {\n alias: {\n '@': state.srcDir,\n },\n },\n build: {\n target: 'esnext',\n emptyOutDir: true,\n minify: false,\n outDir: state.distDir,\n rolldownOptions: {\n external: ['any-listen'],\n input: {\n [name]: filePath,\n },\n output: {\n entryFileNames: '[name]',\n format: 'iife',\n },\n },\n },\n })\n}\n\nexport default (isIsolateMode?: boolean) => {\n const inputs = isIsolateMode\n ? {\n [EXTENSION.entryFileName]: state.mainEntry,\n 'resources/isolate-preload.js': state.isolatePreloadEntry,\n }\n : {\n [EXTENSION.entryFileName]: state.mainEntry,\n }\n return Object.entries(inputs).map(([name, filePath]) => createBuildConfig(name, filePath))\n}\n","import { cpResources } from './cpResources'\nimport { createMainifest } from './mainifest'\nimport { pack } from './pack'\nimport { state } from './state'\nimport { build, getConfig, loadEnvFile } from './utils'\nimport createConfigs from './vite.config'\n\nconst run = async () => {\n await loadEnvFile()\n const config = await getConfig()\n const appConfigs = createConfigs(state.isIsolateMode)\n await Promise.all(appConfigs.map(async (appConfig) => build(appConfig)))\n await Promise.all([cpResources(), createMainifest(config)])\n await pack(config)\n}\n\nvoid run()\n"],"mappings":";;;;;;AAKA,IAAa,cAAc,YAAY;CACrC,MAAM,aAAa,MAAM;CACzB,MAAM,aAAa,KAAK,KAAK,MAAM,SAAS,YAAY;CACxD,MAAM,iBAAiB,MAAM;CAC7B,MAAM,iBAAiB,KAAK,KAAK,MAAM,SAAS,OAAO;CAEvD,MAAM,QAAQ,IAAI,CAChB,GAAG,SAAS,GAAG,YAAY,YAAY,EAAE,WAAW,MAAM,CAAC,EAC3D,GAAG,SAAS,GAAG,gBAAgB,gBAAgB,EAAE,WAAW,MAAM,CAAC,CACpE,CAAC;;;;ACPJ,IAAa,kBAAkB,OAAO,WAA4B;CAChE,MAAM,YAAY;EAChB,IAAI,OAAO;EACX,MAAM,OAAO;EACb,aAAa,OAAO;EACpB,MAAM,OAAO;EACb,SAAS,OAAO;EAChB,eAAe,OAAO;EACtB,QAAQ,OAAO;EACf,UAAU,OAAO;EACjB,SAAS,OAAO;EAChB,YAAY,OAAO;EACnB,MAAM,OAAO;EACb,OAAO,OAAO;EACd,aAAa,OAAO;EACpB,MAAM,UAAU;EACjB;CAED,MAAM,GAAG,SAAS,UAAU,KAAK,KAAK,MAAM,SAAS,UAAU,cAAc,EAAE,KAAK,UAAU,WAAW,MAAM,EAAE,EAAE,OAAO;;;;AChB5H,IAAM,kBAAkB,cAAsB;CAC5C,IAAI,CAAC,UAAU,SAAS,6BAA6B,EACnD,OAAO,+BAA+B,UAAU;CAElD,OAAO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AW,IAAI,OAAO,cAAc,QAAM,UAAU,CAAC,CAAC;CACxE,MAAM,QAAQ,IAAI,CAAC,aAAa,EAAE,gBAAgB,OAAO,CAAC,CAAC;CAC3D,MAAM,KAAK,OAAO;;AAGf,KAAK"}
@@ -22,7 +22,8 @@ var run = async () => {
22
22
  version: "",
23
23
  download_url: "",
24
24
  log: "",
25
- date: (/* @__PURE__ */ new Date()).toISOString()
25
+ date: (/* @__PURE__ */ new Date()).toISOString(),
26
+ history: []
26
27
  };
27
28
  versionInfo.version = config.version;
28
29
  if (config.download_url_template) versionInfo.download_url = `${config.download_url_template.replaceAll("{version}", config.version)}/${buildPackageName(config)}`;
@@ -37,4 +38,4 @@ var run = async () => {
37
38
  run();
38
39
  //#endregion
39
40
 
40
- //# sourceMappingURL=publish-BUpufhVY.js.map
41
+ //# sourceMappingURL=publish-WfB8QiEk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-WfB8QiEk.js","names":[],"sources":["../src/publish.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport type { VersionInfo } from './types/build'\nimport { buildPackageName, getConfig, ROOT_DIR } from './utils'\n\nexport const run = async () => {\n const config = await getConfig()\n const filePath = path.join(ROOT_DIR, 'publish/version.json')\n let versionInfo = await fs.promises\n .readFile(filePath, 'utf-8')\n .then((d) => JSON.parse(d) as VersionInfo)\n .catch(() => null)\n if (versionInfo) {\n if (versionInfo.version === config.version) {\n console.warn(`Version (v${config.version}) already published`)\n process.exit(1)\n }\n versionInfo.history ||= []\n versionInfo.history.push({\n version: versionInfo.version,\n download_url: versionInfo.download_url,\n log: versionInfo.log,\n date: versionInfo.date,\n })\n } else {\n versionInfo = { version: '', download_url: '', log: '', date: new Date().toISOString(), history: [] }\n }\n versionInfo.version = config.version\n if (config.download_url_template) {\n versionInfo.download_url = `${config.download_url_template.replaceAll('{version}', config.version)}/${buildPackageName(config)}`\n }\n versionInfo.log = await fs.promises\n .readFile(path.join(ROOT_DIR, 'publish/changeLog.md'), 'utf-8')\n .then((d) => d.toString().trim())\n .catch(() => '')\n versionInfo.date = new Date().toISOString()\n\n await fs.promises.rm(filePath, { recursive: true, force: true })\n await fs.promises.writeFile(filePath, JSON.stringify(versionInfo))\n}\n\nvoid run()\n"],"mappings":";;;;AAMA,IAAa,MAAM,YAAY;CAC7B,MAAM,SAAS,MAAM,WAAW;CAChC,MAAM,WAAW,KAAK,KAAK,UAAU,uBAAuB;CAC5D,IAAI,cAAc,MAAM,GAAG,SACxB,SAAS,UAAU,QAAQ,CAC3B,MAAM,MAAM,KAAK,MAAM,EAAE,CAAgB,CACzC,YAAY,KAAK;CACpB,IAAI,aAAa;EACf,IAAI,YAAY,YAAY,OAAO,SAAS;GAC1C,QAAQ,KAAK,aAAa,OAAO,QAAQ,qBAAqB;GAC9D,QAAQ,KAAK,EAAE;;EAEjB,YAAY,YAAY,EAAE;EAC1B,YAAY,QAAQ,KAAK;GACvB,SAAS,YAAY;GACrB,cAAc,YAAY;GAC1B,KAAK,YAAY;GACjB,MAAM,YAAY;GACnB,CAAC;QAEF,cAAc;EAAE,SAAS;EAAI,cAAc;EAAI,KAAK;EAAI,uBAAM,IAAI,MAAM,EAAC,aAAa;EAAE,SAAS,EAAE;EAAE;CAEvG,YAAY,UAAU,OAAO;CAC7B,IAAI,OAAO,uBACT,YAAY,eAAe,GAAG,OAAO,sBAAsB,WAAW,aAAa,OAAO,QAAQ,CAAC,GAAG,iBAAiB,OAAO;CAEhI,YAAY,MAAM,MAAM,GAAG,SACxB,SAAS,KAAK,KAAK,UAAU,uBAAuB,EAAE,QAAQ,CAC9D,MAAM,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,CAChC,YAAY,GAAG;CAClB,YAAY,wBAAO,IAAI,MAAM,EAAC,aAAa;CAE3C,MAAM,GAAG,SAAS,GAAG,UAAU;EAAE,WAAW;EAAM,OAAO;EAAM,CAAC;CAChE,MAAM,GAAG,SAAS,UAAU,UAAU,KAAK,UAAU,YAAY,CAAC;;AAG/D,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils-BN85b34y.js","names":[],"sources":["../src/state.ts","../src/constants.ts","../src/utils.ts"],"sourcesContent":["export const state = {\n srcDir: '',\n distDir: '',\n outputDir: '',\n i18nDir: '',\n resourcesDir: '',\n isIsolateMode: false,\n mainEntry: '',\n isolatePreloadEntry: '',\n}\n","export const EXTENSION = {\n pkgExtName: 'alix',\n mainifestName: 'manifest.json',\n signFileName: 'sig',\n extBundleFileName: 'ext.tgz',\n entryFileName: 'main.js',\n versionInfoName: 'version.json',\n}\n","import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport { build as viteBuild, type UserConfig } from 'vite'\n\nimport { EXTENSION } from './constants'\nimport { state } from './state'\nimport type { ExtensionConfig } from './types/build'\n\nexport const ROOT_DIR = path.join(import.meta.dirname.split('node_modules')[0])\n\nconst buildPath = (subPath: string) => {\n if (path.isAbsolute(subPath)) return subPath\n return path.join(ROOT_DIR, subPath)\n}\n\nexport const getConfig = async () => {\n const configPath = path.join(ROOT_DIR, 'config.ts')\n await fs.access(configPath, fs.constants.F_OK)\n const config = ((await import(`file://${configPath}`)) as { default: ExtensionConfig }).default\n\n state.srcDir = buildPath(config.buildConfig?.srcDir || 'src')\n state.distDir = buildPath(config.buildConfig?.distDir || 'dist')\n state.outputDir = buildPath(config.buildConfig?.outputDir || 'build')\n state.i18nDir = buildPath(config.buildConfig?.i18nDir || 'i18n')\n state.resourcesDir = buildPath(config.buildConfig?.resourcesDir || 'resources')\n state.isIsolateMode = config.buildConfig?.isIsolateMode || false\n if (state.isIsolateMode) {\n state.mainEntry = buildPath(config.buildConfig?.mainEntry || path.join(state.srcDir, 'main/index.ts'))\n state.isolatePreloadEntry = buildPath(\n config.buildConfig?.isolatePreloadEntry || path.join(state.srcDir, 'isolate-preload/index.ts')\n )\n } else {\n state.mainEntry = buildPath(config.buildConfig?.mainEntry || path.join(state.srcDir, 'index.ts'))\n }\n\n return config\n}\n\nexport const loadEnvFile = async () => {\n const envPath = path.join(ROOT_DIR, '.env')\n let envContent: string\n try {\n await fs.access(envPath, fs.constants.F_OK)\n envContent = (await fs.readFile(envPath, 'utf-8')).trim()\n } catch {\n return\n }\n if (!envContent) return\n const lines = envContent.split('\\n')\n for (const line of lines) {\n let [key, ...rest] = line.split('=')\n key = key.trim()\n if (key.startsWith('#') || key === '') continue\n process.env[key] = rest.join('=').trim()\n }\n}\n\nexport const buildPackageName = (config: ExtensionConfig) => {\n return `${config.id}_v${config.version}.${EXTENSION.pkgExtName}`\n}\n\n/**\n * build code\n */\nexport const build = async (config: UserConfig) => {\n if (config.build) config.build.watch = null\n return viteBuild({ ...config, configFile: false })\n .then(() => {\n // output\n // console.log(output)\n return true\n })\n .catch((error) => {\n console.log(error)\n return false\n })\n}\n"],"mappings":";;;;AAAA,IAAa,QAAQ;CACnB,QAAQ;CACR,SAAS;CACT,WAAW;CACX,SAAS;CACT,cAAc;CACd,eAAe;CACf,WAAW;CACX,qBAAqB;CACtB;;;ACTD,IAAa,YAAY;CACvB,YAAY;CACZ,eAAe;CACf,cAAc;CACd,mBAAmB;CACnB,eAAe;CACf,iBAAiB;CAClB;;;ACED,IAAa,WAAW,KAAK,KAAK,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC,GAAG;AAE/E,IAAM,aAAa,YAAoB;AACrC,KAAI,KAAK,WAAW,QAAQ,CAAE,QAAO;AACrC,QAAO,KAAK,KAAK,UAAU,QAAQ;;AAGrC,IAAa,YAAY,YAAY;;CACnC,MAAM,aAAa,KAAK,KAAK,UAAU,YAAY;AACnD,OAAM,GAAG,OAAO,YAAY,GAAG,UAAU,KAAK;CAC9C,MAAM,UAAW,MAAM,OAAO,UAAU,eAAgD;AAExF,OAAM,SAAS,YAAA,sBAAU,OAAO,iBAAA,QAAA,wBAAA,KAAA,IAAA,KAAA,IAAA,oBAAa,WAAU,MAAM;AAC7D,OAAM,UAAU,YAAA,uBAAU,OAAO,iBAAA,QAAA,yBAAA,KAAA,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,KAAK,MAAM,IAAI;AACpC,QAAM,IAAI,MAAM;AAChB,MAAI,IAAI,WAAW,IAAI,IAAI,QAAQ,GAAI;AACvC,UAAQ,IAAI,OAAO,KAAK,KAAK,IAAI,CAAC,MAAM;;;AAI5C,IAAa,oBAAoB,WAA4B;AAC3D,QAAO,GAAG,OAAO,GAAG,IAAI,OAAO,QAAQ,GAAG,UAAU;;;;;AAMtD,IAAa,UAAQ,OAAO,WAAuB;AACjD,KAAI,OAAO,MAAO,QAAO,MAAM,QAAQ;AACvC,QAAO,MAAU;EAAE,GAAG;EAAQ,YAAY;EAAO,CAAC,CAC/C,WAAW;AAGV,SAAO;GACP,CACD,OAAO,UAAU;AAChB,UAAQ,IAAI,MAAM;AAClB,SAAO;GACP"}
1
+ {"version":3,"file":"utils-BN85b34y.js","names":[],"sources":["../src/state.ts","../src/constants.ts","../src/utils.ts"],"sourcesContent":["export const state = {\n srcDir: '',\n distDir: '',\n outputDir: '',\n i18nDir: '',\n resourcesDir: '',\n isIsolateMode: false,\n mainEntry: '',\n isolatePreloadEntry: '',\n}\n","export const EXTENSION = {\n pkgExtName: 'alix',\n mainifestName: 'manifest.json',\n signFileName: 'sig',\n extBundleFileName: 'ext.tgz',\n entryFileName: 'main.js',\n versionInfoName: 'version.json',\n}\n","import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport { build as viteBuild, type UserConfig } from 'vite'\n\nimport { EXTENSION } from './constants'\nimport { state } from './state'\nimport type { ExtensionConfig } from './types/build'\n\nexport const ROOT_DIR = path.join(import.meta.dirname.split('node_modules')[0])\n\nconst buildPath = (subPath: string) => {\n if (path.isAbsolute(subPath)) return subPath\n return path.join(ROOT_DIR, subPath)\n}\n\nexport const getConfig = async () => {\n const configPath = path.join(ROOT_DIR, 'config.ts')\n await fs.access(configPath, fs.constants.F_OK)\n const config = ((await import(`file://${configPath}`)) as { default: ExtensionConfig }).default\n\n state.srcDir = buildPath(config.buildConfig?.srcDir || 'src')\n state.distDir = buildPath(config.buildConfig?.distDir || 'dist')\n state.outputDir = buildPath(config.buildConfig?.outputDir || 'build')\n state.i18nDir = buildPath(config.buildConfig?.i18nDir || 'i18n')\n state.resourcesDir = buildPath(config.buildConfig?.resourcesDir || 'resources')\n state.isIsolateMode = config.buildConfig?.isIsolateMode || false\n if (state.isIsolateMode) {\n state.mainEntry = buildPath(config.buildConfig?.mainEntry || path.join(state.srcDir, 'main/index.ts'))\n state.isolatePreloadEntry = buildPath(\n config.buildConfig?.isolatePreloadEntry || path.join(state.srcDir, 'isolate-preload/index.ts')\n )\n } else {\n state.mainEntry = buildPath(config.buildConfig?.mainEntry || path.join(state.srcDir, 'index.ts'))\n }\n\n return config\n}\n\nexport const loadEnvFile = async () => {\n const envPath = path.join(ROOT_DIR, '.env')\n let envContent: string\n try {\n await fs.access(envPath, fs.constants.F_OK)\n envContent = (await fs.readFile(envPath, 'utf-8')).trim()\n } catch {\n return\n }\n if (!envContent) return\n const lines = envContent.split('\\n')\n for (const line of lines) {\n let [key, ...rest] = line.split('=')\n key = key.trim()\n if (key.startsWith('#') || key === '') continue\n process.env[key] = rest.join('=').trim()\n }\n}\n\nexport const buildPackageName = (config: ExtensionConfig) => {\n return `${config.id}_v${config.version}.${EXTENSION.pkgExtName}`\n}\n\n/**\n * build code\n */\nexport const build = async (config: UserConfig) => {\n if (config.build) config.build.watch = null\n return viteBuild({ ...config, configFile: false })\n .then(() => {\n // output\n // console.log(output)\n return true\n })\n .catch((error) => {\n console.log(error)\n return false\n })\n}\n"],"mappings":";;;;AAAA,IAAa,QAAQ;CACnB,QAAQ;CACR,SAAS;CACT,WAAW;CACX,SAAS;CACT,cAAc;CACd,eAAe;CACf,WAAW;CACX,qBAAqB;CACtB;;;ACTD,IAAa,YAAY;CACvB,YAAY;CACZ,eAAe;CACf,cAAc;CACd,mBAAmB;CACnB,eAAe;CACf,iBAAiB;CAClB;;;ACED,IAAa,WAAW,KAAK,KAAK,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC,GAAG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A,yBAAA,KAAA,IAAA,KAAA,IAAA,qBAAa,cAAa,KAAK,KAAK,MAAM,QAAQ,WAAW,CAAC;;CAGnG,OAAO;;AAGT,IAAa,cAAc,YAAY;CACrC,MAAM,UAAU,KAAK,KAAK,UAAU,OAAO;CAC3C,IAAI;CACJ,IAAI;EACF,MAAM,GAAG,OAAO,SAAS,GAAG,UAAU,KAAK;EAC3C,cAAc,MAAM,GAAG,SAAS,SAAS,QAAQ,EAAE,MAAM;SACnD;EACN;;CAEF,IAAI,CAAC,YAAY;CACjB,MAAM,QAAQ,WAAW,MAAM,KAAK;CACpC,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,CAAC,KAAK,GAAG,QAAQ,KAAK,MAAM,IAAI;EACpC,MAAM,IAAI,MAAM;EAChB,IAAI,IAAI,WAAW,IAAI,IAAI,QAAQ,IAAI;EACvC,QAAQ,IAAI,OAAO,KAAK,KAAK,IAAI,CAAC,MAAM;;;AAI5C,IAAa,oBAAoB,WAA4B;CAC3D,OAAO,GAAG,OAAO,GAAG,IAAI,OAAO,QAAQ,GAAG,UAAU;;;;;AAMtD,IAAa,UAAQ,OAAO,WAAuB;CACjD,IAAI,OAAO,OAAO,OAAO,MAAM,QAAQ;CACvC,OAAO,MAAU;EAAE,GAAG;EAAQ,YAAY;EAAO,CAAC,CAC/C,WAAW;EAGV,OAAO;GACP,CACD,OAAO,UAAU;EAChB,QAAQ,IAAI,MAAM;EAClB,OAAO;GACP"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@any-listen/extension-kit",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "keywords": [
5
5
  "any-listen",
6
6
  "any-listen-extension"
@@ -61,21 +61,21 @@
61
61
  "@eslint/js": "^9.39.4",
62
62
  "@tsconfig/node24": "^24.0.4",
63
63
  "@tsconfig/recommended": "^1.0.13",
64
- "@typescript-eslint/eslint-plugin": "^8.58.1",
65
- "@typescript-eslint/parser": "^8.58.1",
66
- "eslint-config-love": "^152.0.0",
67
- "globals": "^17.5.0",
68
- "tar": "^7.5.13",
69
- "vite": "^8.0.8"
64
+ "@typescript-eslint/eslint-plugin": "^8.59.2",
65
+ "@typescript-eslint/parser": "^8.59.2",
66
+ "eslint-config-love": "^154.0.0",
67
+ "globals": "^17.6.0",
68
+ "tar": "^7.5.14",
69
+ "vite": "^8.0.11"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@types/node": "^25.6.0",
73
73
  "eslint": "^9.39.4",
74
- "oxfmt": "^0.44.0",
74
+ "oxfmt": "^0.48.0",
75
75
  "typescript": "^5.9.3"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "eslint": "^9.39.4"
79
79
  },
80
- "packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319"
80
+ "packageManager": "pnpm@10.33.4+sha512.1c67b3b359b2d408119ba1ed289f34b8fc3c6873412bec6fd264fbdc82489e510fcbecb9ce9d22dae7f3b76269d8441046014bdca53b9979cd7a561ad631b800"
81
81
  }
package/src/publish.ts CHANGED
@@ -24,7 +24,7 @@ export const run = async () => {
24
24
  date: versionInfo.date,
25
25
  })
26
26
  } else {
27
- versionInfo = { version: '', download_url: '', log: '', date: new Date().toISOString() }
27
+ versionInfo = { version: '', download_url: '', log: '', date: new Date().toISOString(), history: [] }
28
28
  }
29
29
  versionInfo.version = config.version
30
30
  if (config.download_url_template) {
@@ -3,8 +3,6 @@ import { defineConfig } from 'vite'
3
3
  import { EXTENSION } from './constants'
4
4
  import { state } from './state'
5
5
 
6
- const isProd = process.env.NODE_ENV == 'production'
7
-
8
6
  const createBuildConfig = (name: string, filePath: string) => {
9
7
  return defineConfig({
10
8
  base: './',
@@ -19,11 +17,6 @@ const createBuildConfig = (name: string, filePath: string) => {
19
17
  target: 'esnext',
20
18
  emptyOutDir: true,
21
19
  minify: false,
22
- watch: isProd
23
- ? null
24
- : {
25
- buildDelay: 500,
26
- },
27
20
  outDir: state.distDir,
28
21
  rolldownOptions: {
29
22
  external: ['any-listen'],
@@ -568,14 +568,40 @@ declare namespace AnyListen {
568
568
  isCollect: boolean
569
569
  }
570
570
  }
571
- }
572
571
 
573
- interface IPCActionBase<A> {
574
- action: A
575
- }
576
- interface IPCActionData<A, D> extends IPCActionBase<A> {
577
- data: D
572
+ namespace Resource {
573
+ interface SongListItem {
574
+ play_count: string
575
+ id: string
576
+ author: string
577
+ name: string
578
+ time?: string
579
+ img: string
580
+ // grade: basic.favorcnt / 10,
581
+ desc: string | null
582
+ total?: string
583
+ }
584
+
585
+ interface CommonItem {
586
+ id: string
587
+ name: string
588
+ }
589
+ type TagItem = CommonItem
590
+ interface TagGroupItem {
591
+ name: string
592
+ list: CommonItem[]
593
+ }
594
+
595
+ type BoardItem = CommonItem
596
+ }
578
597
  }
598
+
599
+ // interface IPCActionBase<A> {
600
+ // action: A
601
+ // }
602
+ // interface IPCActionData<A, D> extends IPCActionBase<A> {
603
+ // data: D
604
+ // }
579
605
  interface CommonParams {
580
606
  extensionId: string
581
607
  source: string
@@ -594,7 +620,7 @@ interface LyricSearchResult {
594
620
  name: string
595
621
  artist?: string
596
622
  interval?: number
597
- lyric?: string
623
+ lyric?: AnyListen.Music.LyricInfo
598
624
  }
599
625
  interface LyricDetailParams extends CommonParams {
600
626
  id: string
@@ -602,6 +628,10 @@ interface LyricDetailParams extends CommonParams {
602
628
  interface PicSearchParams extends CommonParams {
603
629
  name: string
604
630
  artist?: string
631
+ interval?: number
632
+ }
633
+ interface SonglistSearchParams extends CommonListParams {
634
+ keyword: string
605
635
  }
606
636
  interface SearchParams extends CommonListParams {
607
637
  name: string
@@ -614,6 +644,13 @@ interface SonglistListParams extends CommonListParams {
614
644
  sort: string
615
645
  tag: string
616
646
  }
647
+ interface LeaderboardDateParams extends CommonParams {
648
+ id: string
649
+ }
650
+ interface LeaderboardDetailParams extends CommonListParams {
651
+ id: string
652
+ date: string
653
+ }
617
654
  export interface ListCommonResult<T> {
618
655
  list: T[]
619
656
  total: number
@@ -628,34 +665,6 @@ interface MusicUrlParams extends MusicCommonParams {
628
665
  quality?: string
629
666
  type?: AnyListen.Music.FileType
630
667
  }
631
- interface MusicUrlInfo {
632
- url: string
633
- quality: string
634
- }
635
-
636
- interface SongListItem {
637
- play_count: string
638
- id: string
639
- author: string
640
- name: string
641
- time?: string
642
- img: string
643
- // grade: basic.favorcnt / 10,
644
- desc: string | null
645
- total?: string
646
- }
647
-
648
- interface CommonItem {
649
- id: string
650
- name: string
651
- }
652
- type TagItem = CommonItem
653
- interface TagGroupItem {
654
- name: string
655
- list: CommonItem[]
656
- }
657
-
658
- type BoardItem = CommonItem
659
668
 
660
669
  declare global {
661
670
  namespace AnyListen_API {
@@ -892,6 +901,10 @@ declare global {
892
901
 
893
902
  readonly onLocaleChanged: (callback: (locale: Locale) => void) => () => void
894
903
  }
904
+ interface Constants {
905
+ readonly storageDir: string
906
+ readonly extensionDir: string
907
+ }
895
908
  /** 应用相关 */
896
909
  interface App {
897
910
  showMessage: (message: string, options?: MessageDialogOptions) => Promise<number>
@@ -993,7 +1006,8 @@ declare global {
993
1006
  type MusicSearchResult = ListCommonResult<AnyListen.Music.MusicInfoOnline>
994
1007
 
995
1008
  interface ResourceAction {
996
- // ('tipSearch' | 'hotSearch', CommonParams) => Promise<string[]>
1009
+ tipSearch: (params: CommonParams) => Promise<string[]>
1010
+ hotSearch: (params: CommonParams) => Promise<string[]>
997
1011
  musicSearch: (params: SearchParams) => Promise<ListCommonResult<AnyListen.Music.MusicInfoOnline>>
998
1012
  musicPic: (params: MusicCommonParams) => Promise<string>
999
1013
  musicUrl: (params: MusicUrlParams) => Promise<MusicUrlInfo>
@@ -1001,14 +1015,14 @@ declare global {
1001
1015
  musicPicSearch: (params: PicSearchParams) => Promise<string[]>
1002
1016
  lyricSearch: (params: LyricSearchParams) => Promise<LyricSearchResult[]>
1003
1017
  lyricDetail: (params: LyricDetailParams) => Promise<AnyListen.Music.LyricInfo>
1004
- // songlistSearch: (params: SearchParams) => Promise<ListCommonResult<AnyListen.Resource.SongListItem>>
1005
- // songlistSorts: (params: CommonParams) => Promise<AnyListen.Resource.TagItem[]>
1006
- // songlistTags: (params: CommonParams) => Promise<AnyListen.Resource.TagGroupItem[]>
1007
- // songlist: (params: SonglistListParams) => Promise<ListCommonResult<AnyListen.Resource.SongListItem>>
1008
- // songlistDetail: (params: ListDetailParams) => Promise<ListCommonResult<Music.MusicInfoOnline>>
1009
- // leaderboard: (params: CommonParams) => Promise<AnyListen.Resource.TagGroupItem[]>
1010
- // leaderboardDate: (params: SonglistListParams) => Promise<ListCommonResult<Music.MusicInfoOnline>>
1011
- // leaderboardDetail: (params: SonglistListParams) => Promise<ListCommonResult<Music.MusicInfoOnline>>
1018
+ songlistSearch: (params: SonglistSearchParams) => Promise<ListCommonResult<AnyListen.Resource.SongListItem>>
1019
+ songlistSorts: (params: CommonParams) => Promise<AnyListen.Resource.TagItem[]>
1020
+ songlistTags: (params: CommonParams) => Promise<AnyListen.Resource.TagGroupItem[]>
1021
+ songlist: (params: SonglistListParams) => Promise<ListCommonResult<AnyListen.Resource.SongListItem>>
1022
+ songlistDetail: (params: ListDetailParams) => Promise<ListCommonResult<AnyListen.Music.MusicInfoOnline>>
1023
+ leaderboard: (params: CommonParams) => Promise<AnyListen.Resource.TagGroupItem[]>
1024
+ leaderboardDate: (params: LeaderboardDateParams) => Promise<AnyListen.Resource.TagItem[]>
1025
+ leaderboardDetail: (params: LeaderboardDetailParams) => Promise<ListCommonResult<AnyListen.Music.MusicInfoOnline>>
1012
1026
  }
1013
1027
 
1014
1028
  interface BackupDataAction {
@@ -1120,6 +1134,7 @@ declare global {
1120
1134
  }
1121
1135
  }
1122
1136
  command: Command
1137
+ constants: Constants
1123
1138
  }
1124
1139
  }
1125
1140
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-CUKFiHZ-.js","names":[],"sources":["../src/cpResources.ts","../src/mainifest.ts","../src/pack.ts","../src/vite.config.ts","../src/build.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { state } from './state'\n\nexport const cpResources = async () => {\n const sourcePath = state.resourcesDir\n const targetPath = path.join(state.distDir, 'resources')\n const sourceI18nPath = state.i18nDir\n const targetI18nPath = path.join(state.distDir, 'i18n')\n\n await Promise.all([\n fs.promises.cp(sourcePath, targetPath, { recursive: true }),\n fs.promises.cp(sourceI18nPath, targetI18nPath, { recursive: true }),\n ])\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { EXTENSION } from './constants'\nimport { state } from './state'\nimport type { ExtensionConfig } from './types/build'\n\nexport const createMainifest = async (config: ExtensionConfig) => {\n const mainifest = {\n id: config.id,\n name: config.name,\n description: config.description,\n icon: config.icon,\n version: config.version,\n target_engine: config.target_engine,\n author: config.author,\n homepage: config.homepage,\n license: config.license,\n categories: config.categories,\n tags: config.tags,\n grant: config.grant,\n contributes: config.contributes,\n main: EXTENSION.entryFileName,\n }\n\n await fs.promises.writeFile(path.join(state.distDir, EXTENSION.mainifestName), JSON.stringify(mainifest, null, 2), 'utf8')\n}\n","import crypto from 'node:crypto'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { EXTENSION } from './constants'\nimport { state } from './state'\nimport type { ExtensionConfig } from './types/build'\nimport { buildPackageName } from './utils'\n\nconst buildPublicKey = (publicKey: string) => {\n if (!publicKey.includes('-----BEGIN PUBLIC KEY-----')) {\n return `-----BEGIN PUBLIC KEY-----\\n${publicKey}\\n-----END PUBLIC KEY-----`\n }\n return publicKey\n}\n\nconst signData = (data: Buffer, privateKey: string) => {\n const sign = crypto.createSign('SHA256')\n sign.update(data)\n sign.end()\n const signature = sign.sign(privateKey, 'hex')\n return signature\n}\nconst verifySignature = (data: Buffer, publicKey: string, signature: string) => {\n const verify = crypto.createVerify('SHA256')\n verify.update(data)\n verify.end()\n const isValid = verify.verify(publicKey, signature, 'hex')\n return isValid\n}\n\nconst packFile = async ({ gzip, cwd, files, dist }: { gzip: boolean; cwd: string; files: string[]; dist: string }) => {\n const { c } = await import('tar')\n return new Promise<void>((resolve, reject) => {\n c(\n {\n gzip,\n cwd,\n },\n files\n )\n .pipe(fs.createWriteStream(dist))\n .on('finish', () => {\n resolve()\n })\n .on('error', reject)\n })\n}\n\nexport const pack = async (config: ExtensionConfig) => {\n let privateKey = process.env.PRI_KEY?.trim()\n let publicKey = process.env.PUB_KEY?.trim()\n if (!privateKey || !publicKey) throw new Error('Missing private key or public key')\n if (!privateKey.includes('-----BEGIN PRIVATE KEY-----')) {\n privateKey = `-----BEGIN PRIVATE KEY-----\\n${privateKey}\\n-----END PRIVATE KEY-----`\n }\n\n const unpackedDir = path.join(state.outputDir, 'unpacked')\n await fs.promises.rm(unpackedDir, { recursive: true }).catch(() => {})\n await fs.promises.mkdir(unpackedDir, { recursive: true }).catch(() => {})\n const extBundleFilePath = path.join(unpackedDir, EXTENSION.extBundleFileName)\n await packFile({\n gzip: true,\n cwd: state.distDir,\n files: [EXTENSION.entryFileName, EXTENSION.mainifestName, 'resources', 'i18n'],\n dist: extBundleFilePath,\n })\n const buf = await fs.promises.readFile(extBundleFilePath)\n const signature = signData(buf, privateKey)\n if (!verifySignature(buf, buildPublicKey(publicKey), signature)) {\n throw new Error('Signature is valid, please check your public key')\n }\n await fs.promises.writeFile(path.join(unpackedDir, EXTENSION.signFileName), `${signature}\\n${publicKey}`)\n await packFile({\n gzip: true,\n cwd: unpackedDir,\n files: [EXTENSION.extBundleFileName, EXTENSION.signFileName],\n dist: path.join(state.outputDir, buildPackageName(config)),\n })\n}\n","import { defineConfig } from 'vite'\n\nimport { EXTENSION } from './constants'\nimport { state } from './state'\n\nconst isProd = process.env.NODE_ENV == 'production'\n\nconst createBuildConfig = (name: string, filePath: string) => {\n return defineConfig({\n base: './',\n mode: process.env.NODE_ENV,\n publicDir: false,\n resolve: {\n alias: {\n '@': state.srcDir,\n },\n },\n build: {\n target: 'esnext',\n emptyOutDir: true,\n minify: false,\n watch: isProd\n ? null\n : {\n buildDelay: 500,\n },\n outDir: state.distDir,\n rolldownOptions: {\n external: ['any-listen'],\n input: {\n [name]: filePath,\n },\n output: {\n entryFileNames: '[name]',\n format: 'iife',\n },\n },\n },\n })\n}\n\nexport default (isIsolateMode?: boolean) => {\n const inputs = isIsolateMode\n ? {\n [EXTENSION.entryFileName]: state.mainEntry,\n 'resources/isolate-preload.js': state.isolatePreloadEntry,\n }\n : {\n [EXTENSION.entryFileName]: state.mainEntry,\n }\n return Object.entries(inputs).map(([name, filePath]) => createBuildConfig(name, filePath))\n}\n","import { cpResources } from './cpResources'\nimport { createMainifest } from './mainifest'\nimport { pack } from './pack'\nimport { state } from './state'\nimport { build, getConfig, loadEnvFile } from './utils'\nimport createConfigs from './vite.config'\n\nconst run = async () => {\n await loadEnvFile()\n const config = await getConfig()\n const appConfigs = createConfigs(state.isIsolateMode)\n await Promise.all(appConfigs.map(async (appConfig) => build(appConfig)))\n await Promise.all([cpResources(), createMainifest(config)])\n await pack(config)\n}\n\nvoid run()\n"],"mappings":";;;;;;AAKA,IAAa,cAAc,YAAY;CACrC,MAAM,aAAa,MAAM;CACzB,MAAM,aAAa,KAAK,KAAK,MAAM,SAAS,YAAY;CACxD,MAAM,iBAAiB,MAAM;CAC7B,MAAM,iBAAiB,KAAK,KAAK,MAAM,SAAS,OAAO;AAEvD,OAAM,QAAQ,IAAI,CAChB,GAAG,SAAS,GAAG,YAAY,YAAY,EAAE,WAAW,MAAM,CAAC,EAC3D,GAAG,SAAS,GAAG,gBAAgB,gBAAgB,EAAE,WAAW,MAAM,CAAC,CACpE,CAAC;;;;ACPJ,IAAa,kBAAkB,OAAO,WAA4B;CAChE,MAAM,YAAY;EAChB,IAAI,OAAO;EACX,MAAM,OAAO;EACb,aAAa,OAAO;EACpB,MAAM,OAAO;EACb,SAAS,OAAO;EAChB,eAAe,OAAO;EACtB,QAAQ,OAAO;EACf,UAAU,OAAO;EACjB,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AAQ;KACT;IACF;GACF;EACF,CAAC;;AAGJ,IAAA,uBAAgB,kBAA4B;CAC1C,MAAM,SAAS,gBACX;GACG,UAAU,gBAAgB,MAAM;EACjC,gCAAgC,MAAM;EACvC,GACD,GACG,UAAU,gBAAgB,MAAM,WAClC;AACL,QAAO,OAAO,QAAQ,OAAO,CAAC,KAAK,CAAC,MAAM,cAAc,kBAAkB,MAAM,SAAS,CAAC;;;;AC3C5F,IAAM,MAAM,YAAY;AACtB,OAAM,aAAa;CACnB,MAAM,SAAS,MAAM,WAAW;CAChC,MAAM,aAAa,oBAAc,MAAM,cAAc;AACrD,OAAM,QAAQ,IAAI,WAAW,IAAI,OAAO,cAAc,QAAM,UAAU,CAAC,CAAC;AACxE,OAAM,QAAQ,IAAI,CAAC,aAAa,EAAE,gBAAgB,OAAO,CAAC,CAAC;AAC3D,OAAM,KAAK,OAAO;;AAGf,KAAK"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"publish-BUpufhVY.js","names":[],"sources":["../src/publish.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport type { VersionInfo } from './types/build'\nimport { buildPackageName, getConfig, ROOT_DIR } from './utils'\n\nexport const run = async () => {\n const config = await getConfig()\n const filePath = path.join(ROOT_DIR, 'publish/version.json')\n let versionInfo = await fs.promises\n .readFile(filePath, 'utf-8')\n .then((d) => JSON.parse(d) as VersionInfo)\n .catch(() => null)\n if (versionInfo) {\n if (versionInfo.version === config.version) {\n console.warn(`Version (v${config.version}) already published`)\n process.exit(1)\n }\n versionInfo.history ||= []\n versionInfo.history.push({\n version: versionInfo.version,\n download_url: versionInfo.download_url,\n log: versionInfo.log,\n date: versionInfo.date,\n })\n } else {\n versionInfo = { version: '', download_url: '', log: '', date: new Date().toISOString() }\n }\n versionInfo.version = config.version\n if (config.download_url_template) {\n versionInfo.download_url = `${config.download_url_template.replaceAll('{version}', config.version)}/${buildPackageName(config)}`\n }\n versionInfo.log = await fs.promises\n .readFile(path.join(ROOT_DIR, 'publish/changeLog.md'), 'utf-8')\n .then((d) => d.toString().trim())\n .catch(() => '')\n versionInfo.date = new Date().toISOString()\n\n await fs.promises.rm(filePath, { recursive: true, force: true })\n await fs.promises.writeFile(filePath, JSON.stringify(versionInfo))\n}\n\nvoid run()\n"],"mappings":";;;;AAMA,IAAa,MAAM,YAAY;CAC7B,MAAM,SAAS,MAAM,WAAW;CAChC,MAAM,WAAW,KAAK,KAAK,UAAU,uBAAuB;CAC5D,IAAI,cAAc,MAAM,GAAG,SACxB,SAAS,UAAU,QAAQ,CAC3B,MAAM,MAAM,KAAK,MAAM,EAAE,CAAgB,CACzC,YAAY,KAAK;AACpB,KAAI,aAAa;AACf,MAAI,YAAY,YAAY,OAAO,SAAS;AAC1C,WAAQ,KAAK,aAAa,OAAO,QAAQ,qBAAqB;AAC9D,WAAQ,KAAK,EAAE;;AAEjB,cAAY,YAAY,EAAE;AAC1B,cAAY,QAAQ,KAAK;GACvB,SAAS,YAAY;GACrB,cAAc,YAAY;GAC1B,KAAK,YAAY;GACjB,MAAM,YAAY;GACnB,CAAC;OAEF,eAAc;EAAE,SAAS;EAAI,cAAc;EAAI,KAAK;EAAI,uBAAM,IAAI,MAAM,EAAC,aAAa;EAAE;AAE1F,aAAY,UAAU,OAAO;AAC7B,KAAI,OAAO,sBACT,aAAY,eAAe,GAAG,OAAO,sBAAsB,WAAW,aAAa,OAAO,QAAQ,CAAC,GAAG,iBAAiB,OAAO;AAEhI,aAAY,MAAM,MAAM,GAAG,SACxB,SAAS,KAAK,KAAK,UAAU,uBAAuB,EAAE,QAAQ,CAC9D,MAAM,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,CAChC,YAAY,GAAG;AAClB,aAAY,wBAAO,IAAI,MAAM,EAAC,aAAa;AAE3C,OAAM,GAAG,SAAS,GAAG,UAAU;EAAE,WAAW;EAAM,OAAO;EAAM,CAAC;AAChE,OAAM,GAAG,SAAS,UAAU,UAAU,KAAK,UAAU,YAAY,CAAC;;AAG/D,KAAK"}