@cdfrd/publish-notification-plugin 0.1.2 → 0.1.4

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.
@@ -25,16 +25,14 @@ interface CheckConfig {
25
25
  /** @default true */
26
26
  onResourceError?: boolean;
27
27
  }
28
- interface LocaleConfig {
29
- default?: Locale;
30
- data?: Partial<Record<Locale, Partial<{
31
- title?: string;
32
- description?: string;
33
- buttonText?: string;
34
- dismissButtonText?: string;
35
- forcedDescription?: string;
36
- }>>>;
37
- }
28
+ /** 按语言覆盖内置通知文案 */
29
+ type LocaleConfig = Partial<Record<Locale, Partial<{
30
+ title?: string;
31
+ description?: string;
32
+ buttonText?: string;
33
+ dismissButtonText?: string;
34
+ forcedDescription?: string;
35
+ }>>>;
38
36
  /** Runtime options 公共字段(不含互斥通知开关) */
39
37
  interface UpdateNoticeOptionsBase {
40
38
  versionBase?: string;
@@ -25,16 +25,14 @@ interface CheckConfig {
25
25
  /** @default true */
26
26
  onResourceError?: boolean;
27
27
  }
28
- interface LocaleConfig {
29
- default?: Locale;
30
- data?: Partial<Record<Locale, Partial<{
31
- title?: string;
32
- description?: string;
33
- buttonText?: string;
34
- dismissButtonText?: string;
35
- forcedDescription?: string;
36
- }>>>;
37
- }
28
+ /** 按语言覆盖内置通知文案 */
29
+ type LocaleConfig = Partial<Record<Locale, Partial<{
30
+ title?: string;
31
+ description?: string;
32
+ buttonText?: string;
33
+ dismissButtonText?: string;
34
+ forcedDescription?: string;
35
+ }>>>;
38
36
  /** Runtime options 公共字段(不含互斥通知开关) */
39
37
  interface UpdateNoticeOptionsBase {
40
38
  versionBase?: string;
@@ -1,5 +1,5 @@
1
- import { f as VersionPluginOptions } from './types-DaCJHaWX.cjs';
2
- export { g as VersionType } from './types-DaCJHaWX.cjs';
1
+ import { f as VersionPluginOptions } from './types-CtjSwxB7.cjs';
2
+ export { g as VersionType } from './types-CtjSwxB7.cjs';
3
3
 
4
4
  /**
5
5
  * For non-Vite/Webpack toolchains. Call after build.
package/dist/version.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { f as VersionPluginOptions } from './types-DaCJHaWX.js';
2
- export { g as VersionType } from './types-DaCJHaWX.js';
1
+ import { f as VersionPluginOptions } from './types-CtjSwxB7.js';
2
+ export { g as VersionType } from './types-CtjSwxB7.js';
3
3
 
4
4
  /**
5
5
  * For non-Vite/Webpack toolchains. Call after build.
package/dist/vite.cjs CHANGED
@@ -24,6 +24,10 @@ __export(vite_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(vite_exports);
26
26
 
27
+ // src/build/vite-plugin-version.ts
28
+ var import_node_fs2 = require("fs");
29
+ var import_node_path2 = require("path");
30
+
27
31
  // src/build/version.ts
28
32
  var import_node_child_process = require("child_process");
29
33
  var import_node_fs = require("fs");
@@ -86,21 +90,31 @@ function getVersionJsonRelativePath() {
86
90
  function vitePluginVersion(options = {}) {
87
91
  let outDir = options.outDir;
88
92
  let versionSource = "";
93
+ let viteBuildOutDir = "";
89
94
  return {
90
95
  name: "publish-notification-vite-plugin-version",
91
96
  apply: "build",
92
97
  enforce: "post",
93
98
  configResolved(config) {
94
- if (!outDir) outDir = config.build.outDir;
99
+ viteBuildOutDir = (0, import_node_path2.resolve)(config.root, config.build.outDir);
100
+ outDir = (0, import_node_path2.resolve)(config.root, outDir || config.build.outDir);
95
101
  const meta = resolveVersion(options.versionType ?? "timestamp", config.root);
96
102
  versionSource = generateVersionJsonContent(meta);
97
103
  },
98
104
  generateBundle() {
99
- this.emitFile({
100
- type: "asset",
101
- fileName: getVersionJsonRelativePath(),
102
- source: versionSource || generateVersionJsonContent(resolveVersion(options.versionType ?? "timestamp"))
103
- });
105
+ const fileName = getVersionJsonRelativePath();
106
+ const source = versionSource || generateVersionJsonContent(resolveVersion(options.versionType ?? "timestamp"));
107
+ if (outDir === viteBuildOutDir) {
108
+ this.emitFile({
109
+ type: "asset",
110
+ fileName,
111
+ source
112
+ });
113
+ return;
114
+ }
115
+ const filePath = (0, import_node_path2.resolve)(outDir, fileName);
116
+ (0, import_node_fs2.mkdirSync)((0, import_node_path2.dirname)(filePath), { recursive: true });
117
+ (0, import_node_fs2.writeFileSync)(filePath, source, "utf8");
104
118
  }
105
119
  };
106
120
  }
package/dist/vite.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/vite.ts","../src/build/version.ts","../src/constants.ts","../src/build/vite-plugin-version.ts"],"sourcesContent":["export { vitePluginVersion } from './build/vite-plugin-version'\nexport type { VersionPluginOptions, VersionType } from './types'\n","import { execSync } from 'node:child_process'\nimport { mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport { DIRECTORY_NAME, JSON_FILE_NAME } from '../constants'\nimport type { VersionJson, VersionPluginOptions, VersionType } from '../types'\nimport { hasNewVersion } from '../core/version-compare'\n\nexport { hasNewVersion }\n\nexport function getGitCommitHash(cwd = process.cwd()): string {\n try {\n return execSync('git rev-parse --short HEAD', {\n cwd,\n encoding: 'utf8',\n stdio: ['ignore', 'pipe', 'ignore'],\n }).trim()\n } catch {\n return ''\n }\n}\n\nexport function getPackageVersion(cwd = process.cwd()): string {\n try {\n const pkg = JSON.parse(readFileSync(resolve(cwd, 'package.json'), 'utf8')) as {\n version?: string\n }\n return typeof pkg.version === 'string' && pkg.version.trim() ? pkg.version.trim() : ''\n } catch {\n return ''\n }\n}\n\n/**\n * Resolve version for version.json.\n * Default versionType is timestamp. On failure of preferred source, fall back to timestamp.\n */\nexport function resolveVersion(versionType: VersionType = 'timestamp', cwd = process.cwd()): VersionJson {\n const buildTime = String(Date.now())\n try {\n switch (versionType) {\n case 'gitcommit': {\n const git = getGitCommitHash(cwd)\n return { version: git || buildTime }\n }\n case 'version': {\n const pkg = getPackageVersion(cwd)\n return { version: pkg || buildTime }\n }\n case 'timestamp':\n default:\n return { version: buildTime }\n }\n } catch {\n return { version: buildTime }\n }\n}\n\nexport function generateVersionJsonContent(meta: VersionJson): string {\n return `${JSON.stringify({ version: meta.version }, null, 2)}\\n`\n}\n\nexport function getVersionJsonRelativePath(): string {\n return `${DIRECTORY_NAME}/${JSON_FILE_NAME}.json`\n}\n\nexport function writeVersionJsonFile(\n outDir: string,\n options: VersionPluginOptions = {},\n cwd = process.cwd(),\n): { filePath: string; version: string } {\n const meta = resolveVersion(options.versionType ?? 'timestamp', cwd)\n const dir = resolve(outDir, DIRECTORY_NAME)\n mkdirSync(dir, { recursive: true })\n const filePath = resolve(dir, `${JSON_FILE_NAME}.json`)\n writeFileSync(filePath, generateVersionJsonContent(meta), 'utf8')\n return { filePath, version: meta.version }\n}\n","export const DIRECTORY_NAME = 'update-notice'\nexport const JSON_FILE_NAME = 'version'\nexport const INJECT_STYLE_TAG_ID = '_cdfrd_un_styles_'\nexport const CUSTOM_UPDATE_EVENT_NAME = 'web_update_notice'\nexport const NOTIFICATION_ANCHOR_CLASS_NAME = 'cdfrd-update-notice-anchor'\nexport const NOTIFICATION_REFRESH_BTN_CLASS = 'cdfrd-update-notice-refresh-btn'\nexport const NOTIFICATION_DISMISS_BTN_CLASS = 'cdfrd-update-notice-dismiss-btn'\nexport const NOTIFICATION_CLOSE_BTN_CLASS = 'cdfrd-update-notice-close-btn'\nexport const DISMISS_STORAGE_PREFIX = 'cdfrd_update_notice_dismiss_'\nexport const MAX_DISMISSED_VERSIONS = 3\nexport const STANDALONE_APP_ID = '__standalone__'\nexport const DEFAULT_PRIMARY_COLOR = '#1677ff'\nexport const THEME_RETRY_MAX = 3\n/** Collapse MutationObserver bursts before re-resolving theme (cssVar fast path uses rAF). */\nexport const THEME_WATCH_DEBOUNCE_MS = 32\n/** Extra wait only when primary is read from transitioning `.ant-btn-primary` background. */\nexport const THEME_BTN_BG_SETTLE_MS = 180\n\n/** Ant Design Notification default offset: top/bottom 24 */\nexport const PLACEMENT_STYLES: Record<string, string> = {\n topLeft: 'top:24px;left:24px',\n topRight: 'top:24px;right:24px',\n bottomLeft: 'bottom:24px;left:24px',\n bottomRight: 'bottom:24px;right:24px',\n}\n\nexport const DEFAULT_CHECK_INTERVAL = 10 * 60 * 1000\n","import type { Plugin, ResolvedConfig } from 'vite'\n\nimport type { VersionPluginOptions } from '../types'\nimport { generateVersionJsonContent, getVersionJsonRelativePath, resolveVersion } from './version'\n\n/**\n * Vite plugin: emit update-notice/version.json only (no HTML / runtime inject).\n */\nexport function vitePluginVersion(options: VersionPluginOptions = {}): Plugin {\n let outDir = options.outDir\n let versionSource = ''\n\n return {\n name: 'publish-notification-vite-plugin-version',\n apply: 'build',\n enforce: 'post',\n configResolved(config: ResolvedConfig) {\n if (!outDir) outDir = config.build.outDir\n const meta = resolveVersion(options.versionType ?? 'timestamp', config.root)\n versionSource = generateVersionJsonContent(meta)\n },\n generateBundle() {\n this.emitFile({\n type: 'asset',\n fileName: getVersionJsonRelativePath(),\n source: versionSource || generateVersionJsonContent(resolveVersion(options.versionType ?? 'timestamp')),\n })\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gCAAyB;AACzB,qBAAuD;AACvD,uBAAwB;;;ACFjB,IAAM,iBAAiB;AACvB,IAAM,iBAAiB;AAyBvB,IAAM,yBAAyB,KAAK,KAAK;;;ADhBzC,SAAS,iBAAiB,MAAM,QAAQ,IAAI,GAAW;AAC5D,MAAI;AACF,eAAO,oCAAS,8BAA8B;AAAA,MAC5C;AAAA,MACA,UAAU;AAAA,MACV,OAAO,CAAC,UAAU,QAAQ,QAAQ;AAAA,IACpC,CAAC,EAAE,KAAK;AAAA,EACV,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,kBAAkB,MAAM,QAAQ,IAAI,GAAW;AAC7D,MAAI;AACF,UAAM,MAAM,KAAK,UAAM,iCAAa,0BAAQ,KAAK,cAAc,GAAG,MAAM,CAAC;AAGzE,WAAO,OAAO,IAAI,YAAY,YAAY,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,IAAI;AA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["../src/vite.ts","../src/build/vite-plugin-version.ts","../src/build/version.ts","../src/constants.ts"],"sourcesContent":["export { vitePluginVersion } from './build/vite-plugin-version'\nexport type { VersionPluginOptions, VersionType } from './types'\n","import { mkdirSync, writeFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport type { Plugin, ResolvedConfig } from 'vite'\n\nimport type { VersionPluginOptions } from '../types'\nimport { generateVersionJsonContent, getVersionJsonRelativePath, resolveVersion } from './version'\n\n/**\n * Vite plugin: emit update-notice/version.json only (no HTML / runtime inject).\n */\nexport function vitePluginVersion(options: VersionPluginOptions = {}): Plugin {\n let outDir = options.outDir\n let versionSource = ''\n let viteBuildOutDir = ''\n\n return {\n name: 'publish-notification-vite-plugin-version',\n apply: 'build',\n enforce: 'post',\n configResolved(config: ResolvedConfig) {\n viteBuildOutDir = resolve(config.root, config.build.outDir)\n outDir = resolve(config.root, outDir || config.build.outDir)\n const meta = resolveVersion(options.versionType ?? 'timestamp', config.root)\n versionSource = generateVersionJsonContent(meta)\n },\n generateBundle() {\n const fileName = getVersionJsonRelativePath()\n const source =\n versionSource || generateVersionJsonContent(resolveVersion(options.versionType ?? 'timestamp'))\n\n if (outDir === viteBuildOutDir) {\n this.emitFile({\n type: 'asset',\n fileName,\n source,\n })\n return\n }\n\n // Custom outDir outside Vite build.outDir: write directly (emitFile is always under Vite outDir)\n const filePath = resolve(outDir!, fileName)\n mkdirSync(dirname(filePath), { recursive: true })\n writeFileSync(filePath, source, 'utf8')\n },\n }\n}\n","import { execSync } from 'node:child_process'\nimport { mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport { DIRECTORY_NAME, JSON_FILE_NAME } from '../constants'\nimport type { VersionJson, VersionPluginOptions, VersionType } from '../types'\nimport { hasNewVersion } from '../core/version-compare'\n\nexport { hasNewVersion }\n\nexport function getGitCommitHash(cwd = process.cwd()): string {\n try {\n return execSync('git rev-parse --short HEAD', {\n cwd,\n encoding: 'utf8',\n stdio: ['ignore', 'pipe', 'ignore'],\n }).trim()\n } catch {\n return ''\n }\n}\n\nexport function getPackageVersion(cwd = process.cwd()): string {\n try {\n const pkg = JSON.parse(readFileSync(resolve(cwd, 'package.json'), 'utf8')) as {\n version?: string\n }\n return typeof pkg.version === 'string' && pkg.version.trim() ? pkg.version.trim() : ''\n } catch {\n return ''\n }\n}\n\n/**\n * Resolve version for version.json.\n * Default versionType is timestamp. On failure of preferred source, fall back to timestamp.\n */\nexport function resolveVersion(versionType: VersionType = 'timestamp', cwd = process.cwd()): VersionJson {\n const buildTime = String(Date.now())\n try {\n switch (versionType) {\n case 'gitcommit': {\n const git = getGitCommitHash(cwd)\n return { version: git || buildTime }\n }\n case 'version': {\n const pkg = getPackageVersion(cwd)\n return { version: pkg || buildTime }\n }\n case 'timestamp':\n default:\n return { version: buildTime }\n }\n } catch {\n return { version: buildTime }\n }\n}\n\nexport function generateVersionJsonContent(meta: VersionJson): string {\n return `${JSON.stringify({ version: meta.version }, null, 2)}\\n`\n}\n\nexport function getVersionJsonRelativePath(): string {\n return `${DIRECTORY_NAME}/${JSON_FILE_NAME}.json`\n}\n\nexport function writeVersionJsonFile(\n outDir: string,\n options: VersionPluginOptions = {},\n cwd = process.cwd(),\n): { filePath: string; version: string } {\n const meta = resolveVersion(options.versionType ?? 'timestamp', cwd)\n const dir = resolve(outDir, DIRECTORY_NAME)\n mkdirSync(dir, { recursive: true })\n const filePath = resolve(dir, `${JSON_FILE_NAME}.json`)\n writeFileSync(filePath, generateVersionJsonContent(meta), 'utf8')\n return { filePath, version: meta.version }\n}\n","export const DIRECTORY_NAME = 'update-notice'\nexport const JSON_FILE_NAME = 'version'\nexport const INJECT_STYLE_TAG_ID = '_cdfrd_un_styles_'\nexport const CUSTOM_UPDATE_EVENT_NAME = 'web_update_notice'\nexport const NOTIFICATION_ANCHOR_CLASS_NAME = 'cdfrd-update-notice-anchor'\nexport const NOTIFICATION_REFRESH_BTN_CLASS = 'cdfrd-update-notice-refresh-btn'\nexport const NOTIFICATION_DISMISS_BTN_CLASS = 'cdfrd-update-notice-dismiss-btn'\nexport const NOTIFICATION_CLOSE_BTN_CLASS = 'cdfrd-update-notice-close-btn'\nexport const DISMISS_STORAGE_PREFIX = 'cdfrd_update_notice_dismiss_'\nexport const MAX_DISMISSED_VERSIONS = 3\nexport const STANDALONE_APP_ID = '__standalone__'\nexport const DEFAULT_PRIMARY_COLOR = '#1677ff'\nexport const THEME_RETRY_MAX = 3\n/** Collapse MutationObserver bursts before re-resolving theme (cssVar fast path uses rAF). */\nexport const THEME_WATCH_DEBOUNCE_MS = 32\n/** Extra wait only when primary is read from transitioning `.ant-btn-primary` background. */\nexport const THEME_BTN_BG_SETTLE_MS = 180\n\n/** Ant Design Notification default offset: top/bottom 24 */\nexport const PLACEMENT_STYLES: Record<string, string> = {\n topLeft: 'top:24px;left:24px',\n topRight: 'top:24px;right:24px',\n bottomLeft: 'bottom:24px;left:24px',\n bottomRight: 'bottom:24px;right:24px',\n}\n\nexport const DEFAULT_CHECK_INTERVAL = 10 * 60 * 1000\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,kBAAyC;AACzC,IAAAC,oBAAiC;;;ACDjC,gCAAyB;AACzB,qBAAuD;AACvD,uBAAwB;;;ACFjB,IAAM,iBAAiB;AACvB,IAAM,iBAAiB;AAyBvB,IAAM,yBAAyB,KAAK,KAAK;;;ADhBzC,SAAS,iBAAiB,MAAM,QAAQ,IAAI,GAAW;AAC5D,MAAI;AACF,eAAO,oCAAS,8BAA8B;AAAA,MAC5C;AAAA,MACA,UAAU;AAAA,MACV,OAAO,CAAC,UAAU,QAAQ,QAAQ;AAAA,IACpC,CAAC,EAAE,KAAK;AAAA,EACV,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,kBAAkB,MAAM,QAAQ,IAAI,GAAW;AAC7D,MAAI;AACF,UAAM,MAAM,KAAK,UAAM,iCAAa,0BA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AAAA,IACA,iBAAiB;AACf,YAAM,WAAW,2BAA2B;AAC5C,YAAM,SACJ,iBAAiB,2BAA2B,eAAe,QAAQ,eAAe,WAAW,CAAC;AAEhG,UAAI,WAAW,iBAAiB;AAC9B,aAAK,SAAS;AAAA,UACZ,MAAM;AAAA,UACN;AAAA,UACA;AAAA,QACF,CAAC;AACD;AAAA,MACF;AAGA,YAAM,eAAW,2BAAQ,QAAS,QAAQ;AAC1C,yCAAU,2BAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AAChD,yCAAc,UAAU,QAAQ,MAAM;AAAA,IACxC;AAAA,EACF;AACF;","names":["import_node_fs","import_node_path"]}
package/dist/vite.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Plugin } from 'vite';
2
- import { f as VersionPluginOptions } from './types-DaCJHaWX.cjs';
3
- export { g as VersionType } from './types-DaCJHaWX.cjs';
2
+ import { f as VersionPluginOptions } from './types-CtjSwxB7.cjs';
3
+ export { g as VersionType } from './types-CtjSwxB7.cjs';
4
4
 
5
5
  /**
6
6
  * Vite plugin: emit update-notice/version.json only (no HTML / runtime inject).
package/dist/vite.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Plugin } from 'vite';
2
- import { f as VersionPluginOptions } from './types-DaCJHaWX.js';
3
- export { g as VersionType } from './types-DaCJHaWX.js';
2
+ import { f as VersionPluginOptions } from './types-CtjSwxB7.js';
3
+ export { g as VersionType } from './types-CtjSwxB7.js';
4
4
 
5
5
  /**
6
6
  * Vite plugin: emit update-notice/version.json only (no HTML / runtime inject).
package/dist/vite.js CHANGED
@@ -1,3 +1,7 @@
1
+ // src/build/vite-plugin-version.ts
2
+ import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
3
+ import { dirname, resolve as resolve2 } from "path";
4
+
1
5
  // src/build/version.ts
2
6
  import { execSync } from "child_process";
3
7
  import { mkdirSync, readFileSync, writeFileSync } from "fs";
@@ -60,21 +64,31 @@ function getVersionJsonRelativePath() {
60
64
  function vitePluginVersion(options = {}) {
61
65
  let outDir = options.outDir;
62
66
  let versionSource = "";
67
+ let viteBuildOutDir = "";
63
68
  return {
64
69
  name: "publish-notification-vite-plugin-version",
65
70
  apply: "build",
66
71
  enforce: "post",
67
72
  configResolved(config) {
68
- if (!outDir) outDir = config.build.outDir;
73
+ viteBuildOutDir = resolve2(config.root, config.build.outDir);
74
+ outDir = resolve2(config.root, outDir || config.build.outDir);
69
75
  const meta = resolveVersion(options.versionType ?? "timestamp", config.root);
70
76
  versionSource = generateVersionJsonContent(meta);
71
77
  },
72
78
  generateBundle() {
73
- this.emitFile({
74
- type: "asset",
75
- fileName: getVersionJsonRelativePath(),
76
- source: versionSource || generateVersionJsonContent(resolveVersion(options.versionType ?? "timestamp"))
77
- });
79
+ const fileName = getVersionJsonRelativePath();
80
+ const source = versionSource || generateVersionJsonContent(resolveVersion(options.versionType ?? "timestamp"));
81
+ if (outDir === viteBuildOutDir) {
82
+ this.emitFile({
83
+ type: "asset",
84
+ fileName,
85
+ source
86
+ });
87
+ return;
88
+ }
89
+ const filePath = resolve2(outDir, fileName);
90
+ mkdirSync2(dirname(filePath), { recursive: true });
91
+ writeFileSync2(filePath, source, "utf8");
78
92
  }
79
93
  };
80
94
  }
package/dist/vite.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/build/version.ts","../src/constants.ts","../src/build/vite-plugin-version.ts"],"sourcesContent":["import { execSync } from 'node:child_process'\nimport { mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport { DIRECTORY_NAME, JSON_FILE_NAME } from '../constants'\nimport type { VersionJson, VersionPluginOptions, VersionType } from '../types'\nimport { hasNewVersion } from '../core/version-compare'\n\nexport { hasNewVersion }\n\nexport function getGitCommitHash(cwd = process.cwd()): string {\n try {\n return execSync('git rev-parse --short HEAD', {\n cwd,\n encoding: 'utf8',\n stdio: ['ignore', 'pipe', 'ignore'],\n }).trim()\n } catch {\n return ''\n }\n}\n\nexport function getPackageVersion(cwd = process.cwd()): string {\n try {\n const pkg = JSON.parse(readFileSync(resolve(cwd, 'package.json'), 'utf8')) as {\n version?: string\n }\n return typeof pkg.version === 'string' && pkg.version.trim() ? pkg.version.trim() : ''\n } catch {\n return ''\n }\n}\n\n/**\n * Resolve version for version.json.\n * Default versionType is timestamp. On failure of preferred source, fall back to timestamp.\n */\nexport function resolveVersion(versionType: VersionType = 'timestamp', cwd = process.cwd()): VersionJson {\n const buildTime = String(Date.now())\n try {\n switch (versionType) {\n case 'gitcommit': {\n const git = getGitCommitHash(cwd)\n return { version: git || buildTime }\n }\n case 'version': {\n const pkg = getPackageVersion(cwd)\n return { version: pkg || buildTime }\n }\n case 'timestamp':\n default:\n return { version: buildTime }\n }\n } catch {\n return { version: buildTime }\n }\n}\n\nexport function generateVersionJsonContent(meta: VersionJson): string {\n return `${JSON.stringify({ version: meta.version }, null, 2)}\\n`\n}\n\nexport function getVersionJsonRelativePath(): string {\n return `${DIRECTORY_NAME}/${JSON_FILE_NAME}.json`\n}\n\nexport function writeVersionJsonFile(\n outDir: string,\n options: VersionPluginOptions = {},\n cwd = process.cwd(),\n): { filePath: string; version: string } {\n const meta = resolveVersion(options.versionType ?? 'timestamp', cwd)\n const dir = resolve(outDir, DIRECTORY_NAME)\n mkdirSync(dir, { recursive: true })\n const filePath = resolve(dir, `${JSON_FILE_NAME}.json`)\n writeFileSync(filePath, generateVersionJsonContent(meta), 'utf8')\n return { filePath, version: meta.version }\n}\n","export const DIRECTORY_NAME = 'update-notice'\nexport const JSON_FILE_NAME = 'version'\nexport const INJECT_STYLE_TAG_ID = '_cdfrd_un_styles_'\nexport const CUSTOM_UPDATE_EVENT_NAME = 'web_update_notice'\nexport const NOTIFICATION_ANCHOR_CLASS_NAME = 'cdfrd-update-notice-anchor'\nexport const NOTIFICATION_REFRESH_BTN_CLASS = 'cdfrd-update-notice-refresh-btn'\nexport const NOTIFICATION_DISMISS_BTN_CLASS = 'cdfrd-update-notice-dismiss-btn'\nexport const NOTIFICATION_CLOSE_BTN_CLASS = 'cdfrd-update-notice-close-btn'\nexport const DISMISS_STORAGE_PREFIX = 'cdfrd_update_notice_dismiss_'\nexport const MAX_DISMISSED_VERSIONS = 3\nexport const STANDALONE_APP_ID = '__standalone__'\nexport const DEFAULT_PRIMARY_COLOR = '#1677ff'\nexport const THEME_RETRY_MAX = 3\n/** Collapse MutationObserver bursts before re-resolving theme (cssVar fast path uses rAF). */\nexport const THEME_WATCH_DEBOUNCE_MS = 32\n/** Extra wait only when primary is read from transitioning `.ant-btn-primary` background. */\nexport const THEME_BTN_BG_SETTLE_MS = 180\n\n/** Ant Design Notification default offset: top/bottom 24 */\nexport const PLACEMENT_STYLES: Record<string, string> = {\n topLeft: 'top:24px;left:24px',\n topRight: 'top:24px;right:24px',\n bottomLeft: 'bottom:24px;left:24px',\n bottomRight: 'bottom:24px;right:24px',\n}\n\nexport const DEFAULT_CHECK_INTERVAL = 10 * 60 * 1000\n","import type { Plugin, ResolvedConfig } from 'vite'\n\nimport type { VersionPluginOptions } from '../types'\nimport { generateVersionJsonContent, getVersionJsonRelativePath, resolveVersion } from './version'\n\n/**\n * Vite plugin: emit update-notice/version.json only (no HTML / runtime inject).\n */\nexport function vitePluginVersion(options: VersionPluginOptions = {}): Plugin {\n let outDir = options.outDir\n let versionSource = ''\n\n return {\n name: 'publish-notification-vite-plugin-version',\n apply: 'build',\n enforce: 'post',\n configResolved(config: ResolvedConfig) {\n if (!outDir) outDir = config.build.outDir\n const meta = resolveVersion(options.versionType ?? 'timestamp', config.root)\n versionSource = generateVersionJsonContent(meta)\n },\n generateBundle() {\n this.emitFile({\n type: 'asset',\n fileName: getVersionJsonRelativePath(),\n source: versionSource || generateVersionJsonContent(resolveVersion(options.versionType ?? 'timestamp')),\n })\n },\n }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,WAAW,cAAc,qBAAqB;AACvD,SAAS,eAAe;;;ACFjB,IAAM,iBAAi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AkB,UAAgC,CAAC,GAAW;AAC5E,MAAI,SAAS,QAAQ;AACrB,MAAI,gBAAgB;AAEpB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,SAAS;AAAA,IACT,eAAe,QAAwB;AACrC,UAAI,CAAC,OAAQ,UAAS,OAAO,MAAM;AACnC,YAAM,OAAO,eAAe,QAAQ,eAAe,aAAa,OAAO,IAAI;AAC3E,sBAAgB,2BAA2B,IAAI;AAAA,IACjD;AAAA,IACA,iBAAiB;AACf,WAAK,SAAS;AAAA,QACZ,MAAM;AAAA,QACN,UAAU,2BAA2B;AAAA,QACrC,QAAQ,iBAAiB,2BAA2B,eAAe,QAAQ,eAAe,WAAW,CAAC;AAAA,MACxG,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/build/vite-plugin-version.ts","../src/build/version.ts","../src/constants.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport type { Plugin, ResolvedConfig } from 'vite'\n\nimport type { VersionPluginOptions } from '../types'\nimport { generateVersionJsonContent, getVersionJsonRelativePath, resolveVersion } from './version'\n\n/**\n * Vite plugin: emit update-notice/version.json only (no HTML / runtime inject).\n */\nexport function vitePluginVersion(options: VersionPluginOptions = {}): Plugin {\n let outDir = options.outDir\n let versionSource = ''\n let viteBuildOutDir = ''\n\n return {\n name: 'publish-notification-vite-plugin-version',\n apply: 'build',\n enforce: 'post',\n configResolved(config: ResolvedConfig) {\n viteBuildOutDir = resolve(config.root, config.build.outDir)\n outDir = resolve(config.root, outDir || config.build.outDir)\n const meta = resolveVersion(options.versionType ?? 'timestamp', config.root)\n versionSource = generateVersionJsonContent(meta)\n },\n generateBundle() {\n const fileName = getVersionJsonRelativePath()\n const source =\n versionSource || generateVersionJsonContent(resolveVersion(options.versionType ?? 'timestamp'))\n\n if (outDir === viteBuildOutDir) {\n this.emitFile({\n type: 'asset',\n fileName,\n source,\n })\n return\n }\n\n // Custom outDir outside Vite build.outDir: write directly (emitFile is always under Vite outDir)\n const filePath = resolve(outDir!, fileName)\n mkdirSync(dirname(filePath), { recursive: true })\n writeFileSync(filePath, source, 'utf8')\n },\n }\n}\n","import { execSync } from 'node:child_process'\nimport { mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport { DIRECTORY_NAME, JSON_FILE_NAME } from '../constants'\nimport type { VersionJson, VersionPluginOptions, VersionType } from '../types'\nimport { hasNewVersion } from '../core/version-compare'\n\nexport { hasNewVersion }\n\nexport function getGitCommitHash(cwd = process.cwd()): string {\n try {\n return execSync('git rev-parse --short HEAD', {\n cwd,\n encoding: 'utf8',\n stdio: ['ignore', 'pipe', 'ignore'],\n }).trim()\n } catch {\n return ''\n }\n}\n\nexport function getPackageVersion(cwd = process.cwd()): string {\n try {\n const pkg = JSON.parse(readFileSync(resolve(cwd, 'package.json'), 'utf8')) as {\n version?: string\n }\n return typeof pkg.version === 'string' && pkg.version.trim() ? pkg.version.trim() : ''\n } catch {\n return ''\n }\n}\n\n/**\n * Resolve version for version.json.\n * Default versionType is timestamp. On failure of preferred source, fall back to timestamp.\n */\nexport function resolveVersion(versionType: VersionType = 'timestamp', cwd = process.cwd()): VersionJson {\n const buildTime = String(Date.now())\n try {\n switch (versionType) {\n case 'gitcommit': {\n const git = getGitCommitHash(cwd)\n return { version: git || buildTime }\n }\n case 'version': {\n const pkg = getPackageVersion(cwd)\n return { version: pkg || buildTime }\n }\n case 'timestamp':\n default:\n return { version: buildTime }\n }\n } catch {\n return { version: buildTime }\n }\n}\n\nexport function generateVersionJsonContent(meta: VersionJson): string {\n return `${JSON.stringify({ version: meta.version }, null, 2)}\\n`\n}\n\nexport function getVersionJsonRelativePath(): string {\n return `${DIRECTORY_NAME}/${JSON_FILE_NAME}.json`\n}\n\nexport function writeVersionJsonFile(\n outDir: string,\n options: VersionPluginOptions = {},\n cwd = process.cwd(),\n): { filePath: string; version: string } {\n const meta = resolveVersion(options.versionType ?? 'timestamp', cwd)\n const dir = resolve(outDir, DIRECTORY_NAME)\n mkdirSync(dir, { recursive: true })\n const filePath = resolve(dir, `${JSON_FILE_NAME}.json`)\n writeFileSync(filePath, generateVersionJsonContent(meta), 'utf8')\n return { filePath, version: meta.version }\n}\n","export const DIRECTORY_NAME = 'update-notice'\nexport const JSON_FILE_NAME = 'version'\nexport const INJECT_STYLE_TAG_ID = '_cdfrd_un_styles_'\nexport const CUSTOM_UPDATE_EVENT_NAME = 'web_update_notice'\nexport const NOTIFICATION_ANCHOR_CLASS_NAME = 'cdfrd-update-notice-anchor'\nexport const NOTIFICATION_REFRESH_BTN_CLASS = 'cdfrd-update-notice-refresh-btn'\nexport const NOTIFICATION_DISMISS_BTN_CLASS = 'cdfrd-update-notice-dismiss-btn'\nexport const NOTIFICATION_CLOSE_BTN_CLASS = 'cdfrd-update-notice-close-btn'\nexport const DISMISS_STORAGE_PREFIX = 'cdfrd_update_notice_dismiss_'\nexport const MAX_DISMISSED_VERSIONS = 3\nexport const STANDALONE_APP_ID = '__standalone__'\nexport const DEFAULT_PRIMARY_COLOR = '#1677ff'\nexport const THEME_RETRY_MAX = 3\n/** Collapse MutationObserver bursts before re-resolving theme (cssVar fast path uses rAF). */\nexport const THEME_WATCH_DEBOUNCE_MS = 32\n/** Extra wait only when primary is read from transitioning `.ant-btn-primary` background. */\nexport const THEME_BTN_BG_SETTLE_MS = 180\n\n/** Ant Design Notification default offset: top/bottom 24 */\nexport const PLACEMENT_STYLES: Record<string, string> = {\n topLeft: 'top:24px;left:24px',\n topRight: 'top:24px;right:24px',\n bottomLeft: 'bottom:24px;left:24px',\n bottomRight: 'bottom:24px;right:24px',\n}\n\nexport const DEFAULT_CHECK_INTERVAL = 10 * 60 * 1000\n"],"mappings":";AAAA,SAAS,aAAAA,YAAW,iBAAAC,sBAAqB;AACzC,SAAS,SAAS,WAAAC,gBAAe;;;ACDjC,SAAS,gBAAgB;AACzB,SAAS,WAAW,cA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O,GAAG,cAAc,IAAI,cAAc;AAC5C;;;ADtDO,SAAS,kBAAkB,UAAgC,CAAC,GAAW;AAC5E,MAAI,SAAS,QAAQ;AACrB,MAAI,gBAAgB;AACpB,MAAI,kBAAkB;AAEtB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,SAAS;AAAA,IACT,eAAe,QAAwB;AACrC,wBAAkBC,SAAQ,OAAO,MAAM,OAAO,MAAM,MAAM;AAC1D,eAASA,SAAQ,OAAO,MAAM,UAAU,OAAO,MAAM,MAAM;AAC3D,YAAM,OAAO,eAAe,QAAQ,eAAe,aAAa,OAAO,IAAI;AAC3E,sBAAgB,2BAA2B,IAAI;AAAA,IACjD;AAAA,IACA,iBAAiB;AACf,YAAM,WAAW,2BAA2B;AAC5C,YAAM,SACJ,iBAAiB,2BAA2B,eAAe,QAAQ,eAAe,WAAW,CAAC;AAEhG,UAAI,WAAW,iBAAiB;AAC9B,aAAK,SAAS;AAAA,UACZ,MAAM;AAAA,UACN;AAAA,UACA;AAAA,QACF,CAAC;AACD;AAAA,MACF;AAGA,YAAM,WAAWA,SAAQ,QAAS,QAAQ;AAC1C,MAAAC,WAAU,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AAChD,MAAAC,eAAc,UAAU,QAAQ,MAAM;AAAA,IACxC;AAAA,EACF;AACF;","names":["mkdirSync","writeFileSync","resolve","resolve","mkdirSync","writeFileSync"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdfrd/publish-notification-plugin",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },