@windwalker-io/core 4.2.9 → 4.2.11
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/Dashboard-CzDoLneW.js +1 -0
- package/dist/debugger/{Database-BGuRRq-L.js → Database-CSU8eOK6.js} +2 -2
- package/dist/debugger/DefaultLayout-fPOBRlxo.js +1 -0
- package/dist/debugger/Events-zF0JqyW4.js +1 -0
- package/dist/debugger/KeyValueTable-6M6bFpX8.js +1 -0
- package/dist/debugger/{Request-yQA1-Fkb.js → Request-DKOZpKRC.js} +1 -1
- package/dist/debugger/{Routing-C5mAPB17.js → Routing-puFmtUNp.js} +1 -1
- package/dist/debugger/{System-JFuNpoZY.js → System-Daos7PgT.js} +1 -1
- package/dist/debugger/{Timeline-Uii-K9v_.js → Timeline-BozTDh0s.js} +1 -1
- package/dist/debugger/debugger.js +11 -11
- package/dist/next.js +17 -4
- package/package.json +7 -3
- package/src/asset-bundler.mjs +114 -114
- package/src/debugger/types/global.d.js +2 -2
- package/src/index.mjs +10 -10
- 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 +85 -81
- package/src/next/fusion/processors/cssModulize.ts +128 -128
- package/src/next/fusion/processors/index.ts +4 -4
- package/src/next/fusion/processors/installVendors.ts +184 -184
- package/src/next/fusion/processors/jsModulize.ts +319 -307
- 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/Dashboard-Bm7ihi81.js +0 -1
- package/dist/debugger/DefaultLayout-DviqbPNR.js +0 -1
- package/dist/debugger/Events-CNF6gvg0.js +0 -1
- package/dist/debugger/KeyValueTable-BfTkP1Rg.js +0 -1
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import { resolve } from 'node:path';
|
|
3
|
-
import type { OutputAsset, OutputChunk } from 'rollup';
|
|
4
|
-
import type { PluginOption } from 'vite';
|
|
5
|
-
|
|
6
|
-
export function injectSystemJS(systemPath?: string, filter?: (file: OutputAsset | OutputChunk) => any): PluginOption {
|
|
7
|
-
systemPath ??= resolve('node_modules/systemjs/dist/system.min.js');
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
name: 'core:inject-systemjs',
|
|
11
|
-
async generateBundle(options, bundle) {
|
|
12
|
-
if (options.format !== 'system') {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const systemjsCode = fs.readFileSync(
|
|
17
|
-
resolve(systemPath),
|
|
18
|
-
'utf-8'
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
for (const file of Object.values(bundle)) {
|
|
22
|
-
if (filter && !filter(file)) {
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (file.type === 'chunk' && file.isEntry && file.fileName.endsWith('.js')) {
|
|
27
|
-
file.code = systemjsCode + '\n' + file.code;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function systemCSSFix(): PluginOption {
|
|
35
|
-
return {
|
|
36
|
-
name: 'core:systemjs-css-fix',
|
|
37
|
-
async generateBundle(options, bundle) {
|
|
38
|
-
if (options.format !== 'system') {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
43
|
-
if (fileName.endsWith('.css') && 'code' in chunk) {
|
|
44
|
-
const regex = /__vite_style__\.textContent\s*=\s*"([\s\S]*?)";/;
|
|
45
|
-
let match = chunk.code.match(regex);
|
|
46
|
-
|
|
47
|
-
// For minified
|
|
48
|
-
if (!match) {
|
|
49
|
-
const regex = /\.textContent\s*=\s*`([\s\S]*?)`/;
|
|
50
|
-
match = chunk.code.match(regex);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (match && match[1]) {
|
|
54
|
-
chunk.code = match[1]
|
|
55
|
-
.replace(/\\"/g, '"')
|
|
56
|
-
.replace(/\\n/g, '\n')
|
|
57
|
-
.replace(/\\t/g, '\t')
|
|
58
|
-
.replace(/\\\\/g, '\\')
|
|
59
|
-
.replace(/\/\*\$vite\$:\d+\*\/$/, '')
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import type { OutputAsset, OutputChunk } from 'rollup';
|
|
4
|
+
import type { PluginOption } from 'vite';
|
|
5
|
+
|
|
6
|
+
export function injectSystemJS(systemPath?: string, filter?: (file: OutputAsset | OutputChunk) => any): PluginOption {
|
|
7
|
+
systemPath ??= resolve('node_modules/systemjs/dist/system.min.js');
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
name: 'core:inject-systemjs',
|
|
11
|
+
async generateBundle(options, bundle) {
|
|
12
|
+
if (options.format !== 'system') {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const systemjsCode = fs.readFileSync(
|
|
17
|
+
resolve(systemPath),
|
|
18
|
+
'utf-8'
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
for (const file of Object.values(bundle)) {
|
|
22
|
+
if (filter && !filter(file)) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (file.type === 'chunk' && file.isEntry && file.fileName.endsWith('.js')) {
|
|
27
|
+
file.code = systemjsCode + '\n' + file.code;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function systemCSSFix(): PluginOption {
|
|
35
|
+
return {
|
|
36
|
+
name: 'core:systemjs-css-fix',
|
|
37
|
+
async generateBundle(options, bundle) {
|
|
38
|
+
if (options.format !== 'system') {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
43
|
+
if (fileName.endsWith('.css') && 'code' in chunk) {
|
|
44
|
+
const regex = /__vite_style__\.textContent\s*=\s*"([\s\S]*?)";/;
|
|
45
|
+
let match = chunk.code.match(regex);
|
|
46
|
+
|
|
47
|
+
// For minified
|
|
48
|
+
if (!match) {
|
|
49
|
+
const regex = /\.textContent\s*=\s*`([\s\S]*?)`/;
|
|
50
|
+
match = chunk.code.match(regex);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (match && match[1]) {
|
|
54
|
+
chunk.code = match[1]
|
|
55
|
+
.replace(/\\"/g, '"')
|
|
56
|
+
.replace(/\\n/g, '\n')
|
|
57
|
+
.replace(/\\t/g, '\t')
|
|
58
|
+
.replace(/\\\\/g, '\\')
|
|
59
|
+
.replace(/\/\*\$vite\$:\d+\*\/$/, '')
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
@@ -1,81 +1,85 @@
|
|
|
1
|
-
import { callback, type ConfigBuilder } from '@windwalker-io/fusion-next';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { relative } from 'node:path';
|
|
6
|
-
import { containsMiddleGlob, removeLastGlob, uniqId } from '../../utilities';
|
|
7
|
-
|
|
8
|
-
export function cloneAssets(patterns: Record<string, string>) {
|
|
9
|
-
return callback((taskName, builder) => {
|
|
10
|
-
const reposition = getAvailableForReposition(patterns);
|
|
11
|
-
|
|
12
|
-
handleReposition(builder, reposition);
|
|
13
|
-
|
|
14
|
-
handleCloneAssets(builder, Object.keys(patterns));
|
|
15
|
-
|
|
16
|
-
return null;
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function getAvailableForReposition(patterns: Record<string, string>) {
|
|
21
|
-
const reposition: Record<string, string> = {};
|
|
22
|
-
|
|
23
|
-
for (const from in patterns) {
|
|
24
|
-
// If clone from contains middle glob: eg. `assets/**/files`, we cannot handle the naming
|
|
25
|
-
// Let the naming options to handle it.
|
|
26
|
-
if (!containsMiddleGlob(from)) {
|
|
27
|
-
reposition[from] = patterns[from];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return reposition;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function handleCloneAssets(builder: ConfigBuilder, clonePatterns: string[]) {
|
|
35
|
-
// An module starts `hidden:` will be ignored by fusion
|
|
36
|
-
const id = uniqId('hidden:clone-asset-') + '.js';
|
|
37
|
-
|
|
38
|
-
const task = builder.addTask(id);
|
|
39
|
-
|
|
40
|
-
builder.resolveIdCallbacks.push((src) => {
|
|
41
|
-
if (src === id) {
|
|
42
|
-
return id;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
builder.loadCallbacks.push((src) => {
|
|
47
|
-
if (src === id) {
|
|
48
|
-
const glob = clonePatterns
|
|
49
|
-
// Replace slash to unix style
|
|
50
|
-
.map(v => v.replace(/\\/g, '/'))
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
.map(v =>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
1
|
+
import { callback, type ConfigBuilder } from '@windwalker-io/fusion-next';
|
|
2
|
+
import fg from 'fast-glob';
|
|
3
|
+
import isGlob from 'is-glob';
|
|
4
|
+
import micromatch from 'micromatch';
|
|
5
|
+
import { normalize, relative } from 'node:path';
|
|
6
|
+
import { containsMiddleGlob, removeLastGlob, uniqId } from '../../utilities';
|
|
7
|
+
|
|
8
|
+
export function cloneAssets(patterns: Record<string, string>) {
|
|
9
|
+
return callback((taskName, builder) => {
|
|
10
|
+
const reposition = getAvailableForReposition(patterns);
|
|
11
|
+
|
|
12
|
+
handleReposition(builder, reposition);
|
|
13
|
+
|
|
14
|
+
handleCloneAssets(builder, Object.keys(patterns));
|
|
15
|
+
|
|
16
|
+
return null;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getAvailableForReposition(patterns: Record<string, string>) {
|
|
21
|
+
const reposition: Record<string, string> = {};
|
|
22
|
+
|
|
23
|
+
for (const from in patterns) {
|
|
24
|
+
// If clone from contains middle glob: eg. `assets/**/files`, we cannot handle the naming
|
|
25
|
+
// Let the naming options to handle it.
|
|
26
|
+
if (!containsMiddleGlob(from)) {
|
|
27
|
+
reposition[from] = patterns[from];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return reposition;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function handleCloneAssets(builder: ConfigBuilder, clonePatterns: string[]) {
|
|
35
|
+
// An module starts `hidden:` will be ignored by fusion
|
|
36
|
+
const id = uniqId('hidden:clone-asset-') + '.js';
|
|
37
|
+
|
|
38
|
+
const task = builder.addTask(id);
|
|
39
|
+
|
|
40
|
+
builder.resolveIdCallbacks.push((src) => {
|
|
41
|
+
if (src === id) {
|
|
42
|
+
return id;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
builder.loadCallbacks.push((src) => {
|
|
47
|
+
if (src === id) {
|
|
48
|
+
const glob = clonePatterns
|
|
49
|
+
// Replace slash to unix style
|
|
50
|
+
.map(v => v.replace(/\\/g, '/'));
|
|
51
|
+
|
|
52
|
+
// Find images and handle paths
|
|
53
|
+
const images = fg.globSync(glob)
|
|
54
|
+
.map(v => v.startsWith('./') || !v.startsWith('/') ? `/${v}` : v);
|
|
55
|
+
|
|
56
|
+
// Build imports
|
|
57
|
+
const lines = images.map((v, i) => `import img${i++} from '${v}';`);
|
|
58
|
+
|
|
59
|
+
// export as array to keep from treeshake
|
|
60
|
+
lines.push(`export default [${images.map((_, index) => `img${index}`).join(', ')}];`);
|
|
61
|
+
|
|
62
|
+
return lines.join('\n') + '\n';
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function handleReposition(builder: ConfigBuilder, reposition: Record<string, string>) {
|
|
68
|
+
builder.assetFileNamesCallbacks.push((assetInfo) => {
|
|
69
|
+
const fileName = assetInfo.originalFileName || assetInfo.name || assetInfo.names[0] || '';
|
|
70
|
+
|
|
71
|
+
for (const base in reposition) {
|
|
72
|
+
if (match(fileName, base)) {
|
|
73
|
+
return normalize(reposition[base] + relative(removeLastGlob(base), fileName)).replace(/\\/g, '/');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function match(str: string, pattern: string) {
|
|
80
|
+
if (isGlob(pattern)) {
|
|
81
|
+
return micromatch.isMatch(str, pattern);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return str.startsWith(pattern);
|
|
85
|
+
}
|
|
@@ -1,128 +1,128 @@
|
|
|
1
|
-
import { type ConfigBuilder, css, type ProcessorInterface, type ProcessorPreview } from '@windwalker-io/fusion-next';
|
|
2
|
-
import { WatchTask } from '@windwalker-io/fusion-next/src/types';
|
|
3
|
-
import fg from 'fast-glob';
|
|
4
|
-
import fs from 'fs-extra';
|
|
5
|
-
import { parse } from 'node-html-parser';
|
|
6
|
-
import { normalize, resolve } from 'node:path';
|
|
7
|
-
import { findModules, findPackages, stripUrlQuery } from '../../utilities';
|
|
8
|
-
|
|
9
|
-
export function cssModulize(entry: string, dest: string) {
|
|
10
|
-
return new CssModulizeProcessor(css(entry, dest));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface CssModulizeDeepOptions {
|
|
14
|
-
mergeCss?: boolean;
|
|
15
|
-
parseBlades?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function cssModulizeDeep(stage: string, entry: string, dest: string, options: CssModulizeDeepOptions = {}) {
|
|
19
|
-
const processor = cssModulize(entry, dest);
|
|
20
|
-
|
|
21
|
-
if (options.mergeCss ?? true) {
|
|
22
|
-
processor.mergeCss(findModules(`${stage}/**/assets/*.scss`));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (options.parseBlades ?? true) {
|
|
26
|
-
processor.parseBlades(
|
|
27
|
-
findModules(`${stage}/**/*.blade.php`),
|
|
28
|
-
findPackages('views/**/*.blade.php'),
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return processor;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
class CssModulizeProcessor implements ProcessorInterface {
|
|
36
|
-
|
|
37
|
-
constructor(
|
|
38
|
-
protected processor: ReturnType<typeof css>,
|
|
39
|
-
protected bladePatterns: string[] = [],
|
|
40
|
-
protected cssPatterns: string[] = []
|
|
41
|
-
) {
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
parseBlades(...bladePatterns: (string[] | string)[]) {
|
|
46
|
-
this.bladePatterns = this.bladePatterns.concat(bladePatterns.flat());
|
|
47
|
-
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
mergeCss(...css: (string[] | string)[]) {
|
|
52
|
-
this.cssPatterns = this.cssPatterns.concat(css.flat());
|
|
53
|
-
|
|
54
|
-
return this;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
config(taskName: string, builder: ConfigBuilder) {
|
|
58
|
-
const tasks = this.processor.config(taskName, builder);
|
|
59
|
-
const task = tasks[0];
|
|
60
|
-
const inputFile = resolve(task.input);
|
|
61
|
-
|
|
62
|
-
builder.loadCallbacks.push((src, options) => {
|
|
63
|
-
const file = stripUrlQuery(src);
|
|
64
|
-
|
|
65
|
-
if (normalize(file) === inputFile) {
|
|
66
|
-
// get blade styles and add watches
|
|
67
|
-
const bladeFiles = fg.globSync(this.bladePatterns);
|
|
68
|
-
|
|
69
|
-
for (const file of bladeFiles) {
|
|
70
|
-
const realpath = resolve(file).replace(/\\/g, '/');
|
|
71
|
-
builder.addWatch(realpath, {
|
|
72
|
-
file: realpath,
|
|
73
|
-
moduleFile: inputFile,
|
|
74
|
-
updateType: 'css-update',
|
|
75
|
-
} satisfies WatchTask);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const patterns = fg.globSync(
|
|
79
|
-
this.cssPatterns.map((v) => resolve(v))
|
|
80
|
-
.map(v => v.replace(/\\/g, '/'))
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const imports = patterns
|
|
84
|
-
.map((pattern) => `@import "${pattern}";`)
|
|
85
|
-
.concat(this.parseStylesFromBlades(bladeFiles))
|
|
86
|
-
.join('\n');
|
|
87
|
-
|
|
88
|
-
let main = fs.readFileSync(file, 'utf-8');
|
|
89
|
-
|
|
90
|
-
main += `\n\n${imports}\n`;
|
|
91
|
-
|
|
92
|
-
return main;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
return undefined;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
parseStylesFromBlades(files: string[]) {
|
|
100
|
-
return files.map((file) => {
|
|
101
|
-
const bladeText = fs.readFileSync(file, 'utf8');
|
|
102
|
-
|
|
103
|
-
const html = parse(bladeText);
|
|
104
|
-
|
|
105
|
-
return html.querySelectorAll('style[type][data-macro],script[type][data-macro]')
|
|
106
|
-
.filter(
|
|
107
|
-
(el) => ['text/scss', 'text/css'].includes(el.getAttribute('type') || '')
|
|
108
|
-
)
|
|
109
|
-
.map((el) => {
|
|
110
|
-
const scope = el.getAttribute('data-scope');
|
|
111
|
-
|
|
112
|
-
if (scope) {
|
|
113
|
-
return `${scope} {
|
|
114
|
-
${el.innerHTML}
|
|
115
|
-
}`;
|
|
116
|
-
} else {
|
|
117
|
-
return el.innerHTML;
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
})
|
|
121
|
-
.filter((c) => c.length > 0)
|
|
122
|
-
.flat();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
preview(): ProcessorPreview[] {
|
|
126
|
-
return [];
|
|
127
|
-
}
|
|
128
|
-
}
|
|
1
|
+
import { type ConfigBuilder, css, type ProcessorInterface, type ProcessorPreview } from '@windwalker-io/fusion-next';
|
|
2
|
+
import { WatchTask } from '@windwalker-io/fusion-next/src/types';
|
|
3
|
+
import fg from 'fast-glob';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import { parse } from 'node-html-parser';
|
|
6
|
+
import { normalize, resolve } from 'node:path';
|
|
7
|
+
import { findModules, findPackages, stripUrlQuery } from '../../utilities';
|
|
8
|
+
|
|
9
|
+
export function cssModulize(entry: string, dest: string) {
|
|
10
|
+
return new CssModulizeProcessor(css(entry, dest));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface CssModulizeDeepOptions {
|
|
14
|
+
mergeCss?: boolean;
|
|
15
|
+
parseBlades?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function cssModulizeDeep(stage: string, entry: string, dest: string, options: CssModulizeDeepOptions = {}) {
|
|
19
|
+
const processor = cssModulize(entry, dest);
|
|
20
|
+
|
|
21
|
+
if (options.mergeCss ?? true) {
|
|
22
|
+
processor.mergeCss(findModules(`${stage}/**/assets/*.scss`));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (options.parseBlades ?? true) {
|
|
26
|
+
processor.parseBlades(
|
|
27
|
+
findModules(`${stage}/**/*.blade.php`),
|
|
28
|
+
findPackages('views/**/*.blade.php'),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return processor;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
class CssModulizeProcessor implements ProcessorInterface {
|
|
36
|
+
|
|
37
|
+
constructor(
|
|
38
|
+
protected processor: ReturnType<typeof css>,
|
|
39
|
+
protected bladePatterns: string[] = [],
|
|
40
|
+
protected cssPatterns: string[] = []
|
|
41
|
+
) {
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
parseBlades(...bladePatterns: (string[] | string)[]) {
|
|
46
|
+
this.bladePatterns = this.bladePatterns.concat(bladePatterns.flat());
|
|
47
|
+
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
mergeCss(...css: (string[] | string)[]) {
|
|
52
|
+
this.cssPatterns = this.cssPatterns.concat(css.flat());
|
|
53
|
+
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
config(taskName: string, builder: ConfigBuilder) {
|
|
58
|
+
const tasks = this.processor.config(taskName, builder);
|
|
59
|
+
const task = tasks[0];
|
|
60
|
+
const inputFile = resolve(task.input);
|
|
61
|
+
|
|
62
|
+
builder.loadCallbacks.push((src, options) => {
|
|
63
|
+
const file = stripUrlQuery(src);
|
|
64
|
+
|
|
65
|
+
if (normalize(file) === inputFile) {
|
|
66
|
+
// get blade styles and add watches
|
|
67
|
+
const bladeFiles = fg.globSync(this.bladePatterns);
|
|
68
|
+
|
|
69
|
+
for (const file of bladeFiles) {
|
|
70
|
+
const realpath = resolve(file).replace(/\\/g, '/');
|
|
71
|
+
builder.addWatch(realpath, {
|
|
72
|
+
file: realpath,
|
|
73
|
+
moduleFile: inputFile,
|
|
74
|
+
updateType: 'css-update',
|
|
75
|
+
} satisfies WatchTask);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const patterns = fg.globSync(
|
|
79
|
+
this.cssPatterns.map((v) => resolve(v))
|
|
80
|
+
.map(v => v.replace(/\\/g, '/'))
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const imports = patterns
|
|
84
|
+
.map((pattern) => `@import "${pattern}";`)
|
|
85
|
+
.concat(this.parseStylesFromBlades(bladeFiles))
|
|
86
|
+
.join('\n');
|
|
87
|
+
|
|
88
|
+
let main = fs.readFileSync(file, 'utf-8');
|
|
89
|
+
|
|
90
|
+
main += `\n\n${imports}\n`;
|
|
91
|
+
|
|
92
|
+
return main;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
parseStylesFromBlades(files: string[]) {
|
|
100
|
+
return files.map((file) => {
|
|
101
|
+
const bladeText = fs.readFileSync(file, 'utf8');
|
|
102
|
+
|
|
103
|
+
const html = parse(bladeText);
|
|
104
|
+
|
|
105
|
+
return html.querySelectorAll('style[type][data-macro],script[type][data-macro]')
|
|
106
|
+
.filter(
|
|
107
|
+
(el) => ['text/scss', 'text/css'].includes(el.getAttribute('type') || '')
|
|
108
|
+
)
|
|
109
|
+
.map((el) => {
|
|
110
|
+
const scope = el.getAttribute('data-scope');
|
|
111
|
+
|
|
112
|
+
if (scope) {
|
|
113
|
+
return `${scope} {
|
|
114
|
+
${el.innerHTML}
|
|
115
|
+
}`;
|
|
116
|
+
} else {
|
|
117
|
+
return el.innerHTML;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
})
|
|
121
|
+
.filter((c) => c.length > 0)
|
|
122
|
+
.flat();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
preview(): ProcessorPreview[] {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { cssModulize, cssModulizeDeep, type CssModulizeDeepOptions } from './cssModulize';
|
|
2
|
-
export { jsModulize, jsModulizeDeep, type JsModulizeOptions, type JsModulizeDeepOptions } from './jsModulize';
|
|
3
|
-
export { installVendors } from './installVendors';
|
|
4
|
-
export { cloneAssets } from './cloneAssets';
|
|
1
|
+
export { cssModulize, cssModulizeDeep, type CssModulizeDeepOptions } from './cssModulize';
|
|
2
|
+
export { jsModulize, jsModulizeDeep, type JsModulizeOptions, type JsModulizeDeepOptions } from './jsModulize';
|
|
3
|
+
export { installVendors } from './installVendors';
|
|
4
|
+
export { cloneAssets } from './cloneAssets';
|