@cdfrd/publish-notification-plugin 0.1.0
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 +106 -0
- package/dist/index.cjs +1148 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +61 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +1114 -0
- package/dist/index.js.map +1 -0
- package/dist/types-DaCJHaWX.d.cts +132 -0
- package/dist/types-DaCJHaWX.d.ts +132 -0
- package/dist/version.cjs +102 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.d.cts +13 -0
- package/dist/version.d.ts +13 -0
- package/dist/version.js +75 -0
- package/dist/version.js.map +1 -0
- package/dist/vite.cjs +111 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.cts +10 -0
- package/dist/vite.d.ts +10 -0
- package/dist/vite.js +84 -0
- package/dist/vite.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/build/default-plugin-version.ts","../src/build/version.ts","../src/constants.ts"],"sourcesContent":["import { resolve } from 'node:path'\n\nimport type { VersionPluginOptions } from '../types'\nimport { writeVersionJsonFile } from './version'\n\n/**\n * For non-Vite/Webpack toolchains. Call after build.\n * Default outDir: dist → writes dist/update-notice/version.json\n */\nexport async function defaultPluginVersion(\n options: VersionPluginOptions = {},\n): Promise<{ filePath: string; version: string }> {\n const outDir = resolve(process.cwd(), options.outDir ?? 'dist')\n return writeVersionJsonFile(outDir, options, process.cwd())\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/** Wait for Antd button CSS transitions to settle before applying watched primary. */\nexport const THEME_WATCH_DEBOUNCE_MS = 150\n\nexport const PLACEMENT_STYLES: Record<string, string> = {\n topLeft: 'top:16px;left:24px',\n topRight: 'top:16px;right:24px',\n bottomLeft: 'bottom:16px;left:24px',\n bottomRight: 'bottom:16px;right:24px',\n}\n\nexport const DEFAULT_CHECK_INTERVAL = 10 * 60 * 1000\n"],"mappings":";AAAA,SAAS,WAAAA,gBAAe;;;ACAxB,SAAS,gBAAgB;AACzB,SAAS,WAAW,cAAc,qBAAqB;AACvD,SAAS,eAAe;;;ACFjB,IAAM,iBAAiB;AACvB,IAAM,iBAAiB;AAsBvB,IAAM,yBAAyB,KAAK,KAAK;;;ADbzC,SAAS,iBAAiB,MAAM,QAAQ,IAAI,GAAW;AAC5D,MAAI;AACF,WAAO,SAAS,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,MAAM,aAAa,QAAQ,KAAK,cAAc,GAAG,MAAM,CAAC;AAGzE,WAAO,OAAO,IAAI,YAAY,YAAY,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,IAAI;AAAA,EACtF,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var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/vite.ts
|
|
21
|
+
var vite_exports = {};
|
|
22
|
+
__export(vite_exports, {
|
|
23
|
+
vitePluginVersion: () => vitePluginVersion
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(vite_exports);
|
|
26
|
+
|
|
27
|
+
// src/build/version.ts
|
|
28
|
+
var import_node_child_process = require("child_process");
|
|
29
|
+
var import_node_fs = require("fs");
|
|
30
|
+
var import_node_path = require("path");
|
|
31
|
+
|
|
32
|
+
// src/constants.ts
|
|
33
|
+
var DIRECTORY_NAME = "update-notice";
|
|
34
|
+
var JSON_FILE_NAME = "version";
|
|
35
|
+
var DEFAULT_CHECK_INTERVAL = 10 * 60 * 1e3;
|
|
36
|
+
|
|
37
|
+
// src/build/version.ts
|
|
38
|
+
function getGitCommitHash(cwd = process.cwd()) {
|
|
39
|
+
try {
|
|
40
|
+
return (0, import_node_child_process.execSync)("git rev-parse --short HEAD", {
|
|
41
|
+
cwd,
|
|
42
|
+
encoding: "utf8",
|
|
43
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
44
|
+
}).trim();
|
|
45
|
+
} catch {
|
|
46
|
+
return "";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function getPackageVersion(cwd = process.cwd()) {
|
|
50
|
+
try {
|
|
51
|
+
const pkg = JSON.parse((0, import_node_fs.readFileSync)((0, import_node_path.resolve)(cwd, "package.json"), "utf8"));
|
|
52
|
+
return typeof pkg.version === "string" && pkg.version.trim() ? pkg.version.trim() : "";
|
|
53
|
+
} catch {
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function resolveVersion(versionType = "timestamp", cwd = process.cwd()) {
|
|
58
|
+
const buildTime = String(Date.now());
|
|
59
|
+
try {
|
|
60
|
+
switch (versionType) {
|
|
61
|
+
case "gitcommit": {
|
|
62
|
+
const git = getGitCommitHash(cwd);
|
|
63
|
+
return { version: git || buildTime };
|
|
64
|
+
}
|
|
65
|
+
case "version": {
|
|
66
|
+
const pkg = getPackageVersion(cwd);
|
|
67
|
+
return { version: pkg || buildTime };
|
|
68
|
+
}
|
|
69
|
+
case "timestamp":
|
|
70
|
+
default:
|
|
71
|
+
return { version: buildTime };
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
return { version: buildTime };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function generateVersionJsonContent(meta) {
|
|
78
|
+
return `${JSON.stringify({ version: meta.version }, null, 2)}
|
|
79
|
+
`;
|
|
80
|
+
}
|
|
81
|
+
function getVersionJsonRelativePath() {
|
|
82
|
+
return `${DIRECTORY_NAME}/${JSON_FILE_NAME}.json`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/build/vite-plugin-version.ts
|
|
86
|
+
function vitePluginVersion(options = {}) {
|
|
87
|
+
let outDir = options.outDir;
|
|
88
|
+
let versionSource = "";
|
|
89
|
+
return {
|
|
90
|
+
name: "publish-notification-vite-plugin-version",
|
|
91
|
+
apply: "build",
|
|
92
|
+
enforce: "post",
|
|
93
|
+
configResolved(config) {
|
|
94
|
+
if (!outDir) outDir = config.build.outDir;
|
|
95
|
+
const meta = resolveVersion(options.versionType ?? "timestamp", config.root);
|
|
96
|
+
versionSource = generateVersionJsonContent(meta);
|
|
97
|
+
},
|
|
98
|
+
generateBundle() {
|
|
99
|
+
this.emitFile({
|
|
100
|
+
type: "asset",
|
|
101
|
+
fileName: getVersionJsonRelativePath(),
|
|
102
|
+
source: versionSource || generateVersionJsonContent(resolveVersion(options.versionType ?? "timestamp"))
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
vitePluginVersion
|
|
110
|
+
});
|
|
111
|
+
//# sourceMappingURL=vite.cjs.map
|
|
@@ -0,0 +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/** Wait for Antd button CSS transitions to settle before applying watched primary. */\nexport const THEME_WATCH_DEBOUNCE_MS = 150\n\nexport const PLACEMENT_STYLES: Record<string, string> = {\n topLeft: 'top:16px;left:24px',\n topRight: 'top:16px;right:24px',\n bottomLeft: 'bottom:16px;left:24px',\n bottomRight: 'bottom:16px;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;AAsBvB,IAAM,yBAAyB,KAAK,KAAK;;;ADbzC,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,EAC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;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":[]}
|
package/dist/vite.d.cts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { f as VersionPluginOptions } from './types-DaCJHaWX.cjs';
|
|
3
|
+
export { g as VersionType } from './types-DaCJHaWX.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Vite plugin: emit update-notice/version.json only (no HTML / runtime inject).
|
|
7
|
+
*/
|
|
8
|
+
declare function vitePluginVersion(options?: VersionPluginOptions): Plugin;
|
|
9
|
+
|
|
10
|
+
export { VersionPluginOptions, vitePluginVersion };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { f as VersionPluginOptions } from './types-DaCJHaWX.js';
|
|
3
|
+
export { g as VersionType } from './types-DaCJHaWX.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Vite plugin: emit update-notice/version.json only (no HTML / runtime inject).
|
|
7
|
+
*/
|
|
8
|
+
declare function vitePluginVersion(options?: VersionPluginOptions): Plugin;
|
|
9
|
+
|
|
10
|
+
export { VersionPluginOptions, vitePluginVersion };
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// src/build/version.ts
|
|
2
|
+
import { execSync } from "child_process";
|
|
3
|
+
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
4
|
+
import { resolve } from "path";
|
|
5
|
+
|
|
6
|
+
// src/constants.ts
|
|
7
|
+
var DIRECTORY_NAME = "update-notice";
|
|
8
|
+
var JSON_FILE_NAME = "version";
|
|
9
|
+
var DEFAULT_CHECK_INTERVAL = 10 * 60 * 1e3;
|
|
10
|
+
|
|
11
|
+
// src/build/version.ts
|
|
12
|
+
function getGitCommitHash(cwd = process.cwd()) {
|
|
13
|
+
try {
|
|
14
|
+
return execSync("git rev-parse --short HEAD", {
|
|
15
|
+
cwd,
|
|
16
|
+
encoding: "utf8",
|
|
17
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
18
|
+
}).trim();
|
|
19
|
+
} catch {
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function getPackageVersion(cwd = process.cwd()) {
|
|
24
|
+
try {
|
|
25
|
+
const pkg = JSON.parse(readFileSync(resolve(cwd, "package.json"), "utf8"));
|
|
26
|
+
return typeof pkg.version === "string" && pkg.version.trim() ? pkg.version.trim() : "";
|
|
27
|
+
} catch {
|
|
28
|
+
return "";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function resolveVersion(versionType = "timestamp", cwd = process.cwd()) {
|
|
32
|
+
const buildTime = String(Date.now());
|
|
33
|
+
try {
|
|
34
|
+
switch (versionType) {
|
|
35
|
+
case "gitcommit": {
|
|
36
|
+
const git = getGitCommitHash(cwd);
|
|
37
|
+
return { version: git || buildTime };
|
|
38
|
+
}
|
|
39
|
+
case "version": {
|
|
40
|
+
const pkg = getPackageVersion(cwd);
|
|
41
|
+
return { version: pkg || buildTime };
|
|
42
|
+
}
|
|
43
|
+
case "timestamp":
|
|
44
|
+
default:
|
|
45
|
+
return { version: buildTime };
|
|
46
|
+
}
|
|
47
|
+
} catch {
|
|
48
|
+
return { version: buildTime };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function generateVersionJsonContent(meta) {
|
|
52
|
+
return `${JSON.stringify({ version: meta.version }, null, 2)}
|
|
53
|
+
`;
|
|
54
|
+
}
|
|
55
|
+
function getVersionJsonRelativePath() {
|
|
56
|
+
return `${DIRECTORY_NAME}/${JSON_FILE_NAME}.json`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/build/vite-plugin-version.ts
|
|
60
|
+
function vitePluginVersion(options = {}) {
|
|
61
|
+
let outDir = options.outDir;
|
|
62
|
+
let versionSource = "";
|
|
63
|
+
return {
|
|
64
|
+
name: "publish-notification-vite-plugin-version",
|
|
65
|
+
apply: "build",
|
|
66
|
+
enforce: "post",
|
|
67
|
+
configResolved(config) {
|
|
68
|
+
if (!outDir) outDir = config.build.outDir;
|
|
69
|
+
const meta = resolveVersion(options.versionType ?? "timestamp", config.root);
|
|
70
|
+
versionSource = generateVersionJsonContent(meta);
|
|
71
|
+
},
|
|
72
|
+
generateBundle() {
|
|
73
|
+
this.emitFile({
|
|
74
|
+
type: "asset",
|
|
75
|
+
fileName: getVersionJsonRelativePath(),
|
|
76
|
+
source: versionSource || generateVersionJsonContent(resolveVersion(options.versionType ?? "timestamp"))
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
vitePluginVersion
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
ADDED
|
@@ -0,0 +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/** Wait for Antd button CSS transitions to settle before applying watched primary. */\nexport const THEME_WATCH_DEBOUNCE_MS = 150\n\nexport const PLACEMENT_STYLES: Record<string, string> = {\n topLeft: 'top:16px;left:24px',\n topRight: 'top:16px;right:24px',\n bottomLeft: 'bottom:16px;left:24px',\n bottomRight: 'bottom:16px;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,iBAAiB;AACvB,IAAM,iBAAiB;AAsBvB,IAAM,yBAAyB,KAAK,KAAK;;;ADbzC,SAAS,iBAAiB,MAAM,QAAQ,IAAI,GAAW;AAC5D,MAAI;AACF,WAAO,SAAS,8BAA8B;AAAA,MAC5C;AAAA,MACA,UAAU;AAAA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,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":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cdfrd/publish-notification-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Web version update notice toolkit (Runtime API + Vite version.json helper)",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
17
|
+
},
|
|
18
|
+
"./vite": {
|
|
19
|
+
"types": "./dist/vite.d.ts",
|
|
20
|
+
"import": "./dist/vite.js",
|
|
21
|
+
"require": "./dist/vite.cjs"
|
|
22
|
+
},
|
|
23
|
+
"./version": {
|
|
24
|
+
"types": "./dist/version.d.ts",
|
|
25
|
+
"import": "./dist/version.js",
|
|
26
|
+
"require": "./dist/version.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup",
|
|
34
|
+
"dev": "pnpm build && pnpm dev:vite",
|
|
35
|
+
"dev:vite": "pnpm --filter \"./examples/vite/**\" run build && pnpm --filter \"./examples/vite/**\" --parallel run preview",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tests/tsconfig.json"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"vite": ">=3.0.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"vite": {
|
|
44
|
+
"optional": true
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^22.10.0",
|
|
49
|
+
"jsdom": "^25.0.1",
|
|
50
|
+
"tsup": "^8.3.5",
|
|
51
|
+
"typescript": "^5.7.2",
|
|
52
|
+
"vite": "^6.0.3",
|
|
53
|
+
"vitest": "^2.1.8"
|
|
54
|
+
},
|
|
55
|
+
"license": "MIT"
|
|
56
|
+
}
|