@windwalker-io/core 4.2.4 → 4.2.6
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/LICENSE +19 -19
- package/dist/debugger/debugger-BOPm1u5O.js +2 -0
- package/dist/debugger/debugger.js +16 -17
- package/dist/debugger/vue-animate.min-DEk1PxEb.js +2 -0
- package/dist/debugger-console.css +1 -6
- package/dist/next.js +38 -37
- package/package.json +2 -2
- package/src/asset-bundler.mjs +114 -114
- package/src/debugger/types/global.d.js +2 -2
- package/src/index.mjs +10 -11
- package/src/legacy/4.0/js-sync.mjs +74 -74
- package/src/next/fusion/index.ts +2 -2
- package/src/next/fusion/plugins/assets.ts +29 -29
- package/src/next/fusion/plugins/index.ts +3 -3
- package/src/next/fusion/plugins/systemjs.ts +66 -66
- package/src/next/fusion/processors/cloneAssets.ts +81 -81
- package/src/next/fusion/processors/cssModulize.ts +128 -127
- package/src/next/fusion/processors/index.ts +4 -4
- package/src/next/fusion/processors/installVendors.ts +184 -178
- package/src/next/fusion/processors/jsModulize.ts +306 -300
- package/src/next/index.ts +2 -2
- package/src/next/utilities/asset-sync.ts +47 -47
- package/src/next/utilities/crypto.ts +11 -11
- package/src/next/utilities/fs.ts +61 -61
- package/src/next/utilities/index.ts +5 -5
- package/src/next/utilities/modules.ts +17 -17
- package/dist/debugger/debugger-ChQADeB6.js +0 -2
- package/dist/debugger/vue-animate.min-BkEL-t1R.js +0 -9
|
@@ -1,300 +1,306 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type BuildTask,
|
|
3
|
-
type ConfigBuilder,
|
|
4
|
-
js,
|
|
5
|
-
type MaybePromise,
|
|
6
|
-
plugin as addPlugin,
|
|
7
|
-
type ProcessorInterface,
|
|
8
|
-
type ProcessorPreview,
|
|
9
|
-
shortHash,
|
|
10
|
-
} from '@windwalker-io/fusion-next';
|
|
11
|
-
import fs from 'fs-extra';
|
|
12
|
-
import { parse } from 'node-html-parser';
|
|
13
|
-
import crypto from 'node:crypto';
|
|
14
|
-
import { normalize, resolve } from 'node:path';
|
|
15
|
-
import { type FindFileResult, findFilesFromGlobArray, findModules, findPackages, stripUrlQuery } from '../../utilities';
|
|
16
|
-
|
|
17
|
-
export interface JsModulizeOptions {
|
|
18
|
-
tmpPath?: string;
|
|
19
|
-
cleanTmp?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function jsModulize(entry: string, dest: string, options: JsModulizeOptions = {}) {
|
|
23
|
-
return new JsModulizeProcessor(js(entry, dest), options);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface JsModulizeDeepOptions extends JsModulizeOptions {
|
|
27
|
-
mergeScripts?: boolean;
|
|
28
|
-
parseBlades?: boolean;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function jsModulizeDeep(stage: string, entry: string, dest: string, options: JsModulizeDeepOptions = {}) {
|
|
32
|
-
const processor = jsModulize(entry, dest, options)
|
|
33
|
-
.stage(stage.toLowerCase());
|
|
34
|
-
|
|
35
|
-
if (options.mergeScripts ?? true) {
|
|
36
|
-
processor.mergeScripts(
|
|
37
|
-
findModules(`${stage}/**/assets/*.ts`),
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (options.parseBlades ?? true) {
|
|
42
|
-
processor.parseBlades(
|
|
43
|
-
findModules(`${stage}/**/*.blade.php`),
|
|
44
|
-
findPackages('views/**/*.blade.php'),
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return processor;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export class JsModulizeProcessor implements ProcessorInterface {
|
|
52
|
-
protected scriptPatterns: string[] = [];
|
|
53
|
-
protected bladePatterns: string[] = [];
|
|
54
|
-
protected stagePrefix: string = '';
|
|
55
|
-
|
|
56
|
-
constructor(protected processor: ReturnType<typeof js>, protected options: JsModulizeOptions = {}) {
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
config(taskName: string, builder: ConfigBuilder) {
|
|
60
|
-
const tasks = this.processor.config(taskName, builder) as BuildTask[];
|
|
61
|
-
const task = tasks[0];
|
|
62
|
-
const inputFile = resolve(task.input);
|
|
63
|
-
const tmpPath = this.options.tmpPath ?? resolve('./tmp/fusion/jsmodules/').replace(/\\/g, '/');
|
|
64
|
-
const clean = this.options.cleanTmp ?? true;
|
|
65
|
-
|
|
66
|
-
if (clean) {
|
|
67
|
-
builder.postBuildCallbacks.push((options, bundle) => {
|
|
68
|
-
fs.removeSync(tmpPath);
|
|
69
|
-
});
|
|
70
|
-
builder.serverStopCallbacks.push((options, bundle) => {
|
|
71
|
-
fs.removeSync(tmpPath);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
this.ignoreMainImport(task);
|
|
76
|
-
|
|
77
|
-
builder.resolveIdCallbacks.push((id) => {
|
|
78
|
-
if (id === '@main') {
|
|
79
|
-
return { id, external: true };
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// Todo: Must dynamic changes in load() hook
|
|
84
|
-
const scriptFiles = findFilesFromGlobArray(this.scriptPatterns);
|
|
85
|
-
const bladeFiles = findBladeFiles(this.bladePatterns);
|
|
86
|
-
|
|
87
|
-
// Watches
|
|
88
|
-
// Currently we don't watch blade files because not necessary to reload full-pages.
|
|
89
|
-
// for (const bladeFile of bladeScripts) {
|
|
90
|
-
// builder.watches.push({
|
|
91
|
-
// file: resolve(bladeFile.file.fullpath),
|
|
92
|
-
// moduleFile: inputFile,
|
|
93
|
-
// updateType: 'js-update',
|
|
94
|
-
// } satisfies WatchTask);
|
|
95
|
-
// }
|
|
96
|
-
|
|
97
|
-
builder.loadCallbacks.push((src, options) => {
|
|
98
|
-
const srcFile = stripUrlQuery(src);
|
|
99
|
-
const scripts: Record<string, string> = {};
|
|
100
|
-
|
|
101
|
-
// if (src === appSrcFileName) {
|
|
102
|
-
if (normalize(srcFile) === inputFile) {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
.
|
|
138
|
-
.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
//
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
return
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
this.
|
|
211
|
-
|
|
212
|
-
return this;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
this.
|
|
217
|
-
|
|
218
|
-
return this;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
//
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
-
//
|
|
239
|
-
//
|
|
240
|
-
//
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
.
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
type BuildTask,
|
|
3
|
+
type ConfigBuilder,
|
|
4
|
+
js,
|
|
5
|
+
type MaybePromise,
|
|
6
|
+
plugin as addPlugin,
|
|
7
|
+
type ProcessorInterface,
|
|
8
|
+
type ProcessorPreview,
|
|
9
|
+
shortHash,
|
|
10
|
+
} from '@windwalker-io/fusion-next';
|
|
11
|
+
import fs from 'fs-extra';
|
|
12
|
+
import { parse } from 'node-html-parser';
|
|
13
|
+
import crypto from 'node:crypto';
|
|
14
|
+
import { normalize, resolve } from 'node:path';
|
|
15
|
+
import { type FindFileResult, findFilesFromGlobArray, findModules, findPackages, stripUrlQuery } from '../../utilities';
|
|
16
|
+
|
|
17
|
+
export interface JsModulizeOptions {
|
|
18
|
+
tmpPath?: string;
|
|
19
|
+
cleanTmp?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function jsModulize(entry: string, dest: string, options: JsModulizeOptions = {}) {
|
|
23
|
+
return new JsModulizeProcessor(js(entry, dest), options);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface JsModulizeDeepOptions extends JsModulizeOptions {
|
|
27
|
+
mergeScripts?: boolean;
|
|
28
|
+
parseBlades?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function jsModulizeDeep(stage: string, entry: string, dest: string, options: JsModulizeDeepOptions = {}) {
|
|
32
|
+
const processor = jsModulize(entry, dest, options)
|
|
33
|
+
.stage(stage.toLowerCase());
|
|
34
|
+
|
|
35
|
+
if (options.mergeScripts ?? true) {
|
|
36
|
+
processor.mergeScripts(
|
|
37
|
+
findModules(`${stage}/**/assets/*.ts`),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (options.parseBlades ?? true) {
|
|
42
|
+
processor.parseBlades(
|
|
43
|
+
findModules(`${stage}/**/*.blade.php`),
|
|
44
|
+
findPackages('views/**/*.blade.php'),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return processor;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class JsModulizeProcessor implements ProcessorInterface {
|
|
52
|
+
protected scriptPatterns: string[] = [];
|
|
53
|
+
protected bladePatterns: string[] = [];
|
|
54
|
+
protected stagePrefix: string = '';
|
|
55
|
+
|
|
56
|
+
constructor(protected processor: ReturnType<typeof js>, protected options: JsModulizeOptions = {}) {
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
config(taskName: string, builder: ConfigBuilder) {
|
|
60
|
+
const tasks = this.processor.config(taskName, builder) as BuildTask[];
|
|
61
|
+
const task = tasks[0];
|
|
62
|
+
const inputFile = resolve(task.input);
|
|
63
|
+
const tmpPath = this.options.tmpPath ?? resolve('./tmp/fusion/jsmodules/').replace(/\\/g, '/');
|
|
64
|
+
const clean = this.options.cleanTmp ?? true;
|
|
65
|
+
|
|
66
|
+
if (clean) {
|
|
67
|
+
builder.postBuildCallbacks.push((options, bundle) => {
|
|
68
|
+
fs.removeSync(tmpPath);
|
|
69
|
+
});
|
|
70
|
+
builder.serverStopCallbacks.push((options, bundle) => {
|
|
71
|
+
fs.removeSync(tmpPath);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.ignoreMainImport(task);
|
|
76
|
+
|
|
77
|
+
builder.resolveIdCallbacks.push((id) => {
|
|
78
|
+
if (id === '@main') {
|
|
79
|
+
return { id, external: true };
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Todo: Must dynamic changes in load() hook
|
|
84
|
+
const scriptFiles = findFilesFromGlobArray(this.scriptPatterns);
|
|
85
|
+
// const bladeFiles = findBladeFiles(this.bladePatterns);
|
|
86
|
+
|
|
87
|
+
// Watches
|
|
88
|
+
// Currently we don't watch blade files because not necessary to reload full-pages.
|
|
89
|
+
// for (const bladeFile of bladeScripts) {
|
|
90
|
+
// builder.watches.push({
|
|
91
|
+
// file: resolve(bladeFile.file.fullpath),
|
|
92
|
+
// moduleFile: inputFile,
|
|
93
|
+
// updateType: 'js-update',
|
|
94
|
+
// } satisfies WatchTask);
|
|
95
|
+
// }
|
|
96
|
+
|
|
97
|
+
builder.loadCallbacks.push((src, options) => {
|
|
98
|
+
const srcFile = stripUrlQuery(src);
|
|
99
|
+
const scripts: Record<string, string> = {};
|
|
100
|
+
|
|
101
|
+
// if (src === appSrcFileName) {
|
|
102
|
+
if (normalize(srcFile) === inputFile) {
|
|
103
|
+
const bladeFiles = findBladeFiles(this.bladePatterns);
|
|
104
|
+
const bladeScripts = parseScriptsFromBlades(bladeFiles);
|
|
105
|
+
|
|
106
|
+
// Merge standalone ts files
|
|
107
|
+
for (const scriptFile of scriptFiles) {
|
|
108
|
+
let fullpath = scriptFile.fullpath;
|
|
109
|
+
|
|
110
|
+
if (fullpath.endsWith('.d.ts')) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let key = scriptFile.relativePath.replace(/assets\//, '').toLowerCase();
|
|
115
|
+
fullpath = resolve(fullpath).replace(/\\/g, '/');
|
|
116
|
+
|
|
117
|
+
key = key.substring(0, key.lastIndexOf('.'));
|
|
118
|
+
|
|
119
|
+
if (this.stagePrefix) {
|
|
120
|
+
key = this.stagePrefix + '/' + key;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// md5
|
|
124
|
+
key = 'view:' + crypto.createHash('md5').update(key).digest('hex');
|
|
125
|
+
|
|
126
|
+
scripts[key] = fullpath;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Parse from blades
|
|
130
|
+
const listens: string[] = [];
|
|
131
|
+
|
|
132
|
+
fs.ensureDirSync(tmpPath);
|
|
133
|
+
|
|
134
|
+
for (const result of bladeScripts) {
|
|
135
|
+
let key = result.as;
|
|
136
|
+
const filename = result.path
|
|
137
|
+
.split(/\\|\//g)
|
|
138
|
+
.pop()
|
|
139
|
+
.replace(/\\|\//g, '_');
|
|
140
|
+
|
|
141
|
+
const tmpFile = tmpPath + '/' + filename + '__' + result.as.replace(/\./g, '-') + '.ts';
|
|
142
|
+
|
|
143
|
+
if (!fs.existsSync(tmpFile) || fs.readFileSync(tmpFile, 'utf8') !== result.code) {
|
|
144
|
+
fs.writeFileSync(tmpFile, result.code);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
scripts[`inline:${key}`] = tmpFile;
|
|
148
|
+
|
|
149
|
+
const fullpath = resolve(result.file.fullpath).replace(/\\/g, '/');
|
|
150
|
+
|
|
151
|
+
// builder.addWatch(fullpath, fullpath);
|
|
152
|
+
|
|
153
|
+
// if (!listens.includes(fullpath)) {
|
|
154
|
+
// listens.push(fullpath);
|
|
155
|
+
// }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let listJS = `{\n`;
|
|
159
|
+
|
|
160
|
+
for (const key in scripts) {
|
|
161
|
+
const fullpath = scripts[key];
|
|
162
|
+
listJS += `'${key}': () => import('${fullpath}'),\n`;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
listJS += `}`;
|
|
166
|
+
|
|
167
|
+
// Listen extra files
|
|
168
|
+
// builder.watches.push(...listens);
|
|
169
|
+
// for (const listen of listens) {
|
|
170
|
+
// builder.addWatch(listen, listen);
|
|
171
|
+
// }
|
|
172
|
+
|
|
173
|
+
let { code, comments } = stripComments(fs.readFileSync(srcFile, 'utf-8'));
|
|
174
|
+
|
|
175
|
+
// Replace `defineJsModules(...)`
|
|
176
|
+
code = code.replace(/defineJsModules\((.*?)\)/g, listJS);
|
|
177
|
+
|
|
178
|
+
return restoreComments(code, comments);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @see https://github.com/vitejs/vite/issues/6393#issuecomment-1006819717
|
|
187
|
+
* @see https://stackoverflow.com/questions/76259677/vite-dev-server-throws-error-when-resolving-external-path-from-importmap
|
|
188
|
+
*/
|
|
189
|
+
private ignoreMainImport(task: BuildTask) {
|
|
190
|
+
const VALID_ID_PREFIX = `/@id/`;
|
|
191
|
+
const importKeys = ['@main'];
|
|
192
|
+
const reg = new RegExp(
|
|
193
|
+
`${VALID_ID_PREFIX}(${importKeys.join("|")})`,
|
|
194
|
+
"g"
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
addPlugin({
|
|
198
|
+
name: 'keep-main-external-' + task.id,
|
|
199
|
+
transform(code) {
|
|
200
|
+
return reg.test(code) ? code.replace(reg, (m, s1) => s1) : code;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
preview(): MaybePromise<ProcessorPreview[]> {
|
|
206
|
+
return [];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
mergeScripts(...patterns: (string | string[])[]) {
|
|
210
|
+
this.scriptPatterns = this.scriptPatterns.concat(patterns.flat());
|
|
211
|
+
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
parseBlades(...bladePatterns: (string[] | string)[]) {
|
|
216
|
+
this.bladePatterns = this.bladePatterns.concat(bladePatterns.flat());
|
|
217
|
+
|
|
218
|
+
return this;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
stage(stage: string) {
|
|
222
|
+
this.stagePrefix = stage;
|
|
223
|
+
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
interface ScriptResult {
|
|
229
|
+
as: string;
|
|
230
|
+
file: FindFileResult;
|
|
231
|
+
path: string;
|
|
232
|
+
code: string;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// function parseScriptsFromBlade(file: string, service: Record<string, ParsedModule>): string[] {
|
|
236
|
+
// const bladeText = fs.readFileSync(file, 'utf8');
|
|
237
|
+
//
|
|
238
|
+
// const html = parse(bladeText);
|
|
239
|
+
//
|
|
240
|
+
// return html.querySelectorAll('script[lang]')
|
|
241
|
+
// .filter(
|
|
242
|
+
// (el) => ['ts', 'typescript'].includes(el.getAttribute('lang') || '')
|
|
243
|
+
// )
|
|
244
|
+
// .map((el) => el.innerHTML)
|
|
245
|
+
// .filter((c) => c.trim() !== '');
|
|
246
|
+
// }
|
|
247
|
+
|
|
248
|
+
function findBladeFiles(patterns: string | string[]) {
|
|
249
|
+
return findFilesFromGlobArray(Array.isArray(patterns) ? patterns : [patterns]);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function parseScriptsFromBlades(files: FindFileResult[]): ScriptResult[] {
|
|
253
|
+
return files.map((file) => {
|
|
254
|
+
const bladeText = fs.readFileSync(file.fullpath, 'utf8');
|
|
255
|
+
|
|
256
|
+
const html = parse(bladeText);
|
|
257
|
+
// const key = file.relativePath.replace(/.blade.php$/, '').toLowerCase();
|
|
258
|
+
|
|
259
|
+
return html.querySelectorAll('script[lang][data-macro]')
|
|
260
|
+
.filter(
|
|
261
|
+
(el) => ['ts', 'typescript'].includes(el.getAttribute('lang') || '')
|
|
262
|
+
)
|
|
263
|
+
.map((el) => ({
|
|
264
|
+
as: el.getAttribute('data-macro') || '',
|
|
265
|
+
file: file,
|
|
266
|
+
path: file.relativePath.replace(/.blade.php$/, ''),
|
|
267
|
+
code: el.innerHTML
|
|
268
|
+
}))
|
|
269
|
+
.filter((c) => c.code.trim() !== '');
|
|
270
|
+
})
|
|
271
|
+
.flat();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
type CommentPlaceholder = { key: string; value: string; };
|
|
275
|
+
|
|
276
|
+
function stripComments(code: string): { code: string; comments: CommentPlaceholder[] } {
|
|
277
|
+
const comments: CommentPlaceholder[] = [];
|
|
278
|
+
let i = 0;
|
|
279
|
+
|
|
280
|
+
code = code
|
|
281
|
+
// Multi-line /* */
|
|
282
|
+
.replace(/\/\*[\s\S]*?\*\//g, match => {
|
|
283
|
+
const key = `__COMMENT_BLOCK_${i}__`;
|
|
284
|
+
comments.push({ key, value: match });
|
|
285
|
+
i++;
|
|
286
|
+
return key;
|
|
287
|
+
})
|
|
288
|
+
// Single-line //
|
|
289
|
+
.replace(/\/\/.*$/gm, match => {
|
|
290
|
+
const key = `__COMMENT_LINE_${i}__`;
|
|
291
|
+
comments.push({ key, value: match });
|
|
292
|
+
i++;
|
|
293
|
+
return key;
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
return { code, comments };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function restoreComments(code: string, comments: CommentPlaceholder[]): string {
|
|
300
|
+
for (const { key, value } of comments) {
|
|
301
|
+
const re = new RegExp(key, 'g');
|
|
302
|
+
code = code.replace(re, value);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return code;
|
|
306
|
+
}
|
package/src/next/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './fusion';
|
|
2
|
-
export * from './utilities';
|
|
1
|
+
export * from './fusion';
|
|
2
|
+
export * from './utilities';
|