@aippy/vite-plugins 0.3.0 โ 0.4.0-dev.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 +36 -27
- package/dist/aippy-preload/index.js +1 -1
- package/dist/{aippy-preload-8BoWu90-.js โ aippy-preload-Dhhw3O6d.js} +73 -56
- package/dist/asset-constants/generator-utils.d.ts +2 -1
- package/dist/asset-constants/index.js +1 -1
- package/dist/asset-constants/manifest.d.ts +53 -0
- package/dist/asset-constants/wrapper-keys.d.ts +5 -0
- package/dist/asset-constants-BUK7zWRd.js +360 -0
- package/dist/index/index.js +2 -2
- package/dist/manifest-DQGCd9CQ.js +399 -0
- package/package.json +5 -3
- package/src/asset-constants/assets.schema.json +238 -0
- package/dist/asset-constants-BvKclVVI.js +0 -252
- package/dist/file-scanner-DT-LbrCa.js +0 -85
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import { extractAssetsFromContent as e, generateConstantName as t, processAssetURL as n } from "./utils/index.js";
|
|
2
|
-
import { a as r, i, n as a, r as o, t as s } from "./file-scanner-DT-LbrCa.js";
|
|
3
|
-
import { promises as c } from "fs";
|
|
4
|
-
import l from "path";
|
|
5
|
-
import { parse as u } from "@babel/parser";
|
|
6
|
-
import d from "@babel/traverse";
|
|
7
|
-
import * as f from "@babel/types";
|
|
8
|
-
import p from "@babel/generator";
|
|
9
|
-
//#region src/asset-constants/generator-utils.ts
|
|
10
|
-
function m(e, t) {
|
|
11
|
-
let n = {};
|
|
12
|
-
for (let [e, r] of t.entries()) n[r] = e;
|
|
13
|
-
return Array.from(e.values()).forEach((e) => {
|
|
14
|
-
n[e.constantName] = e.originalUri;
|
|
15
|
-
}), JSON.stringify(n, null, 2) + "\n";
|
|
16
|
-
}
|
|
17
|
-
function h(e) {
|
|
18
|
-
let t = /* @__PURE__ */ new Map();
|
|
19
|
-
try {
|
|
20
|
-
if (!e.trim()) return t;
|
|
21
|
-
let n = JSON.parse(e);
|
|
22
|
-
for (let [e, r] of Object.entries(n)) typeof r == "string" && t.set(r, e);
|
|
23
|
-
t.size > 0 && console.log(`๐ Found ${t.size} existing constants in assets.json`);
|
|
24
|
-
} catch (e) {
|
|
25
|
-
console.warn("Warning: Failed to parse existing assets.json:", e);
|
|
26
|
-
}
|
|
27
|
-
return t;
|
|
28
|
-
}
|
|
29
|
-
function g(e, t, n, r) {
|
|
30
|
-
let i = Array.from(n.values()).filter((e) => t.has(e.originalUri)).length, a = e - i;
|
|
31
|
-
console.log(a > 0 ? `โ
Generated ${e} asset constants (${a} new, ${i} reused) in ${r}` : e > 0 ? `โ
Generated ${e} asset constants (all reused from existing) in ${r}` : "โ
No asset constants found");
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/asset-constants/index.ts
|
|
35
|
-
var _ = typeof d == "function" ? d : d.default, v = typeof p == "function" ? p : p.default, y = class {
|
|
36
|
-
constructor(e = {}) {
|
|
37
|
-
r(this, "options", void 0), r(this, "assets", /* @__PURE__ */ new Map()), r(this, "existingAssets", /* @__PURE__ */ new Map()), r(this, "fileCache", new s()), this.options = {
|
|
38
|
-
extensions: [
|
|
39
|
-
".png",
|
|
40
|
-
".jpg",
|
|
41
|
-
".jpeg",
|
|
42
|
-
".gif",
|
|
43
|
-
".svg",
|
|
44
|
-
".mp4",
|
|
45
|
-
".mp3",
|
|
46
|
-
".wav",
|
|
47
|
-
".ogg",
|
|
48
|
-
".webm"
|
|
49
|
-
],
|
|
50
|
-
srcDir: "src",
|
|
51
|
-
outputFile: "src/config/assets.json",
|
|
52
|
-
devMode: !1,
|
|
53
|
-
...e
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
clearCache() {
|
|
57
|
-
this.fileCache.clear();
|
|
58
|
-
}
|
|
59
|
-
generateConstantName(e) {
|
|
60
|
-
let n = /* @__PURE__ */ new Set([...Array.from(this.assets.values()).map((e) => e.constantName), ...Array.from(this.existingAssets.values())]);
|
|
61
|
-
return t(e, n);
|
|
62
|
-
}
|
|
63
|
-
async scanTsFile(t) {
|
|
64
|
-
try {
|
|
65
|
-
let n = await this.fileCache.read(t), r = [], i = e(n, "js", this.options.extensions), a = n.split("\n");
|
|
66
|
-
return i.forEach((e) => {
|
|
67
|
-
let n = this.generateConstantName(e), i = a.findIndex((t) => t.includes(e)) + 1;
|
|
68
|
-
r.push({
|
|
69
|
-
originalUri: e,
|
|
70
|
-
constantName: n,
|
|
71
|
-
filePath: t,
|
|
72
|
-
line: i,
|
|
73
|
-
column: 1
|
|
74
|
-
});
|
|
75
|
-
}), r;
|
|
76
|
-
} catch (e) {
|
|
77
|
-
return console.warn(`Warning: Failed to scan ${t}:`, e), [];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
async scanAllTsFiles() {
|
|
81
|
-
let e = this.options.srcDir;
|
|
82
|
-
try {
|
|
83
|
-
let t = await o(e, [".ts", ".tsx"]);
|
|
84
|
-
for (let e of t) e.endsWith("assets.json") || e.endsWith("assets.ts") || (await this.scanTsFile(e)).forEach((e) => {
|
|
85
|
-
this.existingAssets.has(e.originalUri) && (e.constantName = this.existingAssets.get(e.originalUri));
|
|
86
|
-
let t = e.originalUri;
|
|
87
|
-
this.assets.has(t) || this.assets.set(t, e);
|
|
88
|
-
});
|
|
89
|
-
} catch (e) {
|
|
90
|
-
console.error("Error scanning TypeScript files:", e);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
async readExistingAssetsFile() {
|
|
94
|
-
try {
|
|
95
|
-
return await c.readFile(this.options.outputFile, "utf-8");
|
|
96
|
-
} catch {
|
|
97
|
-
return "";
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
async parseExistingAssets() {
|
|
101
|
-
let e = await this.readExistingAssetsFile();
|
|
102
|
-
this.existingAssets = h(e);
|
|
103
|
-
}
|
|
104
|
-
async generateAssetsFile() {
|
|
105
|
-
await this.parseExistingAssets(), await this.scanAllTsFiles();
|
|
106
|
-
let e = m(this.assets, this.existingAssets), t = l.dirname(this.options.outputFile);
|
|
107
|
-
await c.mkdir(t, { recursive: !0 }), await c.writeFile(this.options.outputFile, e, "utf-8"), await this.generateAssetsWrapper(), g(this.assets.size, this.existingAssets, this.assets, this.options.outputFile);
|
|
108
|
-
}
|
|
109
|
-
async generateAssetsWrapper() {
|
|
110
|
-
let e = this.options.outputFile.replace(/\.json$/, ".ts"), t = `// ๐ Auto-generated wrapper for assets.json
|
|
111
|
-
// This file handles iOS image replacement via asset-interceptor.js
|
|
112
|
-
import assetsData from "./${l.basename(this.options.outputFile)}";
|
|
113
|
-
|
|
114
|
-
// Batch process all asset URLs for potential replacements
|
|
115
|
-
// sessionStorage may contain __aippy_asset_overrides__ with multiple image mappings
|
|
116
|
-
(window as any).getReplacedAssets?.(assetsData);
|
|
117
|
-
|
|
118
|
-
export default assetsData;
|
|
119
|
-
`;
|
|
120
|
-
await c.writeFile(e, t, "utf-8"), console.log(` โ Generated assets wrapper: ${l.relative(process.cwd(), e)}`);
|
|
121
|
-
}
|
|
122
|
-
getAssets() {
|
|
123
|
-
return Array.from(this.assets.values());
|
|
124
|
-
}
|
|
125
|
-
async replaceUrisInFile(e, t) {
|
|
126
|
-
try {
|
|
127
|
-
let r = await this.fileCache.read(e), o = u(r, {
|
|
128
|
-
sourceType: "module",
|
|
129
|
-
plugins: [
|
|
130
|
-
"typescript",
|
|
131
|
-
"jsx",
|
|
132
|
-
"decorators-legacy"
|
|
133
|
-
]
|
|
134
|
-
}), s = !1;
|
|
135
|
-
if (_(o, { StringLiteral: (e) => {
|
|
136
|
-
let r = e.node.value, i = n(r);
|
|
137
|
-
if (t.has(i)) {
|
|
138
|
-
let n = t.get(i), r = f.memberExpression(f.identifier("assetsData"), f.identifier(n));
|
|
139
|
-
e.parent && f.isJSXAttribute(e.parent) ? e.replaceWith(f.jsxExpressionContainer(r)) : e.replaceWith(r), s = !0;
|
|
140
|
-
}
|
|
141
|
-
} }), !s) return;
|
|
142
|
-
let d = this.options.outputFile.replace(/\.json$/, ".ts"), p = a(d, this.options.srcDir), m = i(e, d), h = i(e, this.options.outputFile) + ".json", g = !1;
|
|
143
|
-
if (_(o, { ImportDeclaration: (e) => {
|
|
144
|
-
let t = e.node.source.value;
|
|
145
|
-
(t === p || t === m || t === h) && (g = !0, e.stop());
|
|
146
|
-
} }), !g) {
|
|
147
|
-
let e = f.importDeclaration([f.importDefaultSpecifier(f.identifier("assetsData"))], f.stringLiteral(p));
|
|
148
|
-
o.program.body.unshift(e);
|
|
149
|
-
}
|
|
150
|
-
let y = v(o, {
|
|
151
|
-
retainLines: !1,
|
|
152
|
-
comments: !0,
|
|
153
|
-
compact: !1
|
|
154
|
-
}, r);
|
|
155
|
-
await c.writeFile(e, y.code, "utf-8"), this.fileCache.invalidate(e), console.log(` โ Replaced URIs in ${l.relative(process.cwd(), e)}`);
|
|
156
|
-
} catch (t) {
|
|
157
|
-
console.warn(`Warning: Failed to replace URIs in ${e}:`, t);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
async replaceAllUris() {
|
|
161
|
-
let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Set();
|
|
162
|
-
for (let n of this.assets.values()) e.set(n.originalUri, n.constantName), t.add(n.filePath);
|
|
163
|
-
for (let n of t) await this.replaceUrisInFile(n, e);
|
|
164
|
-
}
|
|
165
|
-
async cleanupUnusedConstants() {
|
|
166
|
-
try {
|
|
167
|
-
let e = await this.readExistingAssetsFile();
|
|
168
|
-
if (!e.trim()) return;
|
|
169
|
-
let t = /* @__PURE__ */ new Map();
|
|
170
|
-
try {
|
|
171
|
-
let n = JSON.parse(e);
|
|
172
|
-
for (let [e, r] of Object.entries(n)) typeof r == "string" && t.set(e, r);
|
|
173
|
-
} catch (e) {
|
|
174
|
-
console.warn("Warning: Failed to parse assets.json:", e);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
if (t.size === 0) return;
|
|
178
|
-
let n = /* @__PURE__ */ new Set(), r = await o(this.options.srcDir, [".ts", ".tsx"]);
|
|
179
|
-
for (let e of r) if (!(e.endsWith("assets.json") || e.endsWith("assets.ts"))) try {
|
|
180
|
-
let r = await this.fileCache.read(e);
|
|
181
|
-
for (let e of t.keys()) r.includes(e) && n.add(e);
|
|
182
|
-
} catch (t) {
|
|
183
|
-
console.warn(`Warning: Failed to read ${e}:`, t);
|
|
184
|
-
}
|
|
185
|
-
let i = [];
|
|
186
|
-
for (let e of t.keys()) n.has(e) || i.push(e);
|
|
187
|
-
if (i.length > 0) {
|
|
188
|
-
console.log(`๐งน Removing ${i.length} unused constant(s):`), i.forEach((e) => {
|
|
189
|
-
console.log(` - ${e}`);
|
|
190
|
-
});
|
|
191
|
-
let e = [];
|
|
192
|
-
for (let n of i) {
|
|
193
|
-
let r = t.get(n);
|
|
194
|
-
r && e.push(r);
|
|
195
|
-
}
|
|
196
|
-
for (let t of e) this.assets.delete(t);
|
|
197
|
-
} else console.log("โ
All constants are in use");
|
|
198
|
-
} catch (e) {
|
|
199
|
-
console.warn("Warning: Failed to cleanup unused constants:", e);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
async upgradeJsonImportsToTs() {
|
|
203
|
-
let e = this.options.outputFile.replace(/\.json$/, ".ts"), t = a(e, this.options.srcDir), n = await o(this.options.srcDir, [".ts", ".tsx"]), r = 0;
|
|
204
|
-
for (let a of n) if (!(a.endsWith("assets.ts") || a.endsWith("assets.json"))) try {
|
|
205
|
-
let n = await this.fileCache.read(a), o = i(a, this.options.outputFile) + ".json", s = i(a, e);
|
|
206
|
-
if (!n.includes(o) && !n.includes(s)) continue;
|
|
207
|
-
let d = u(n, {
|
|
208
|
-
sourceType: "module",
|
|
209
|
-
plugins: [
|
|
210
|
-
"typescript",
|
|
211
|
-
"jsx",
|
|
212
|
-
"decorators-legacy"
|
|
213
|
-
]
|
|
214
|
-
}), f = !1;
|
|
215
|
-
if (_(d, { ImportDeclaration: (e) => {
|
|
216
|
-
let n = e.node.source.value;
|
|
217
|
-
(n === o || n === s) && (e.node.source.value = t, f = !0);
|
|
218
|
-
} }), f) {
|
|
219
|
-
let e = v(d, {
|
|
220
|
-
retainLines: !1,
|
|
221
|
-
comments: !0,
|
|
222
|
-
compact: !1
|
|
223
|
-
}, n);
|
|
224
|
-
await c.writeFile(a, e.code, "utf-8"), this.fileCache.invalidate(a), console.log(` โ Upgraded import in ${l.relative(process.cwd(), a)} โ ${t}`), r++;
|
|
225
|
-
}
|
|
226
|
-
} catch (e) {
|
|
227
|
-
console.warn(`Warning: Failed to upgrade imports in ${a}:`, e);
|
|
228
|
-
}
|
|
229
|
-
r > 0 && console.log(`โ
Upgraded ${r} file(s) to use ${t}`);
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
function b(e = {}) {
|
|
233
|
-
return {
|
|
234
|
-
name: "vite-plugin-asset-constants",
|
|
235
|
-
apply: "build",
|
|
236
|
-
enforce: "pre",
|
|
237
|
-
async buildStart() {
|
|
238
|
-
if (e.devMode) try {
|
|
239
|
-
let t = new y(e);
|
|
240
|
-
await t.generateAssetsFile();
|
|
241
|
-
let n = t.getAssets();
|
|
242
|
-
n.length > 0 && (console.log(`๐ฆ Found ${n.length} asset references:`), n.forEach((e) => {
|
|
243
|
-
console.log(` ${e.constantName} = '${e.originalUri}' (${l.relative(process.cwd(), e.filePath)}:${e.line})`);
|
|
244
|
-
}), console.log("\n๐ Replacing URIs with constants..."), await t.replaceAllUris(), console.log("โ
URI replacement completed!")), console.log("\n๐งน Checking for unused constants..."), await t.cleanupUnusedConstants(), await t.generateAssetsFile(), console.log("\n๐ Upgrading assets.json imports to assets.ts..."), await t.upgradeJsonImportsToTs(), console.log("โ
Asset constants finalized!\n"), t.clearCache();
|
|
245
|
-
} catch (e) {
|
|
246
|
-
console.error("โ Error in asset constants plugin:", e);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
//#endregion
|
|
252
|
-
export { b as t };
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { promises as e } from "fs";
|
|
2
|
-
import t from "path";
|
|
3
|
-
//#region \0@oxc-project+runtime@0.144.0/helpers/esm/typeof.js
|
|
4
|
-
function n(e) {
|
|
5
|
-
"@babel/helpers - typeof";
|
|
6
|
-
return n = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
|
|
7
|
-
return typeof e;
|
|
8
|
-
} : function(e) {
|
|
9
|
-
return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
|
|
10
|
-
}, n(e);
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region \0@oxc-project+runtime@0.144.0/helpers/esm/toPrimitive.js
|
|
14
|
-
function r(e, t) {
|
|
15
|
-
if (n(e) != "object" || !e) return e;
|
|
16
|
-
var r = e[Symbol.toPrimitive];
|
|
17
|
-
if (r !== void 0) {
|
|
18
|
-
var i = r.call(e, t || "default");
|
|
19
|
-
if (n(i) != "object") return i;
|
|
20
|
-
throw TypeError("@@toPrimitive must return a primitive value.");
|
|
21
|
-
}
|
|
22
|
-
return (t === "string" ? String : Number)(e);
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region \0@oxc-project+runtime@0.144.0/helpers/esm/toPropertyKey.js
|
|
26
|
-
function i(e) {
|
|
27
|
-
var t = r(e, "string");
|
|
28
|
-
return n(t) == "symbol" ? t : t + "";
|
|
29
|
-
}
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region \0@oxc-project+runtime@0.144.0/helpers/esm/defineProperty.js
|
|
32
|
-
function a(e, t, n) {
|
|
33
|
-
return (t = i(t)) in e ? Object.defineProperty(e, t, {
|
|
34
|
-
value: n,
|
|
35
|
-
enumerable: !0,
|
|
36
|
-
configurable: !0,
|
|
37
|
-
writable: !0
|
|
38
|
-
}) : e[t] = n, e;
|
|
39
|
-
}
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/utils/file-scanner.ts
|
|
42
|
-
async function o(n, r) {
|
|
43
|
-
let i = [];
|
|
44
|
-
try {
|
|
45
|
-
let a = await e.readdir(n, { withFileTypes: !0 });
|
|
46
|
-
for (let e of a) {
|
|
47
|
-
let a = t.join(n, e.name);
|
|
48
|
-
if (e.isDirectory()) {
|
|
49
|
-
let e = await o(a, r);
|
|
50
|
-
i.push(...e);
|
|
51
|
-
} else if (e.isFile()) {
|
|
52
|
-
let n = t.extname(e.name);
|
|
53
|
-
r.includes(n) && i.push(a);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
} catch (e) {
|
|
57
|
-
console.warn(`Warning: Failed to read directory ${n}:`, e);
|
|
58
|
-
}
|
|
59
|
-
return i;
|
|
60
|
-
}
|
|
61
|
-
function s(e, n) {
|
|
62
|
-
let r = t.relative(t.dirname(e), n).replace(/\.(ts|tsx|js|jsx|json)$/, "");
|
|
63
|
-
return r.startsWith(".") ? r : `./${r}`;
|
|
64
|
-
}
|
|
65
|
-
function c(e, n) {
|
|
66
|
-
return `@/${t.relative(n, e).replace(/\.(ts|tsx|js|jsx|json)$/, "")}`;
|
|
67
|
-
}
|
|
68
|
-
var l = class {
|
|
69
|
-
constructor() {
|
|
70
|
-
a(this, "cache", /* @__PURE__ */ new Map());
|
|
71
|
-
}
|
|
72
|
-
async read(t) {
|
|
73
|
-
if (this.cache.has(t)) return this.cache.get(t);
|
|
74
|
-
let n = await e.readFile(t, "utf-8");
|
|
75
|
-
return this.cache.set(t, n), n;
|
|
76
|
-
}
|
|
77
|
-
invalidate(e) {
|
|
78
|
-
this.cache.delete(e);
|
|
79
|
-
}
|
|
80
|
-
clear() {
|
|
81
|
-
this.cache.clear();
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
//#endregion
|
|
85
|
-
export { a, s as i, c as n, o as r, l as t };
|