@dcoder-x/vite 0.1.0 → 0.1.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/dist/ClippyVitePlugin.d.ts +1 -1
- package/dist/ClippyVitePlugin.js +80 -27
- package/package.json +2 -2
package/dist/ClippyVitePlugin.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { RouteExtractor } from '@
|
|
2
|
-
import { ComponentExtractor } from '@
|
|
3
|
-
import { SelectorGenerator } from '@
|
|
4
|
-
import { FlowInferrer } from '@
|
|
5
|
-
import { PackageBuilder } from '@
|
|
6
|
-
import { PackageWriter } from '@
|
|
7
|
-
import { Uploader } from '@
|
|
1
|
+
import { RouteExtractor } from '@dcoder-x/plugin-shared/extractors/RouteExtractor';
|
|
2
|
+
import { ComponentExtractor } from '@dcoder-x/plugin-shared/extractors/ComponentExtractor';
|
|
3
|
+
import { SelectorGenerator } from '@dcoder-x/plugin-shared/extractors/SelectorGenerator';
|
|
4
|
+
import { FlowInferrer } from '@dcoder-x/plugin-shared/extractors/FlowInferrer';
|
|
5
|
+
import { PackageBuilder } from '@dcoder-x/plugin-shared/upload/PackageBuilder';
|
|
6
|
+
import { PackageWriter } from '@dcoder-x/plugin-shared/upload/PackageWriter';
|
|
7
|
+
import { Uploader } from '@dcoder-x/plugin-shared/upload/Uploader';
|
|
8
|
+
import { injectClippyIds, deriveBuildId, performUpload } from '@dcoder-x/plugin-shared';
|
|
8
9
|
export function clippyVitePlugin(options) {
|
|
9
10
|
const moduleGraph = new Map();
|
|
11
|
+
const injectedMap = new Map();
|
|
10
12
|
return {
|
|
11
13
|
name: 'clippy-vite-plugin',
|
|
12
14
|
apply: 'build',
|
|
@@ -18,41 +20,92 @@ export function clippyVitePlugin(options) {
|
|
|
18
20
|
});
|
|
19
21
|
}
|
|
20
22
|
},
|
|
23
|
+
transform(source, id) {
|
|
24
|
+
const cleanId = id.split('?')[0];
|
|
25
|
+
if (!/\.[jt]sx?$/.test(cleanId))
|
|
26
|
+
return null;
|
|
27
|
+
const result = injectClippyIds(source, cleanId);
|
|
28
|
+
if (result.injectedCount === 0)
|
|
29
|
+
return null;
|
|
30
|
+
if (result.injected && result.injected.length)
|
|
31
|
+
injectedMap.set(cleanId, result.injected);
|
|
32
|
+
return {
|
|
33
|
+
code: result.source,
|
|
34
|
+
map: null,
|
|
35
|
+
};
|
|
36
|
+
},
|
|
21
37
|
async closeBundle() {
|
|
22
38
|
try {
|
|
23
39
|
const dir = process.cwd();
|
|
24
|
-
const buildId =
|
|
40
|
+
const buildId = deriveBuildId(moduleGraph);
|
|
25
41
|
const routes = await new RouteExtractor(dir).extract();
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
42
|
+
const extractor = new ComponentExtractor({ type: 'rollup', moduleGraph }, routes);
|
|
43
|
+
const elements = await extractor.extract();
|
|
44
|
+
const components = await extractor.extractComponents();
|
|
45
|
+
const injectedObj = Object.fromEntries(Array.from(injectedMap.entries()));
|
|
46
|
+
const selectors = new SelectorGenerator().generate(elements, injectedObj);
|
|
47
|
+
const flows = new FlowInferrer(routes, elements, components).infer();
|
|
29
48
|
const packageBuilder = new PackageBuilder();
|
|
30
|
-
const
|
|
49
|
+
const artifacts = packageBuilder.buildArtifacts({
|
|
31
50
|
buildId,
|
|
32
51
|
bundler: 'vite',
|
|
33
52
|
routes,
|
|
34
|
-
components,
|
|
35
53
|
selectors,
|
|
36
54
|
flows,
|
|
55
|
+
components,
|
|
37
56
|
});
|
|
38
57
|
if (options.localOutputDir) {
|
|
39
|
-
|
|
40
|
-
|
|
58
|
+
try {
|
|
59
|
+
const fs = await import('fs');
|
|
60
|
+
const path = await import('path');
|
|
61
|
+
fs.mkdirSync(options.localOutputDir, { recursive: true });
|
|
62
|
+
const injectedObj = Object.fromEntries(Array.from(injectedMap.entries()));
|
|
63
|
+
fs.writeFileSync(path.join(options.localOutputDir, 'clippy-injected.json'), JSON.stringify(injectedObj, null, 2), 'utf-8');
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
/* ignore write errors */
|
|
67
|
+
}
|
|
41
68
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
const uploaded = await new Uploader(options).upload(pkg);
|
|
51
|
-
if (uploaded) {
|
|
52
|
-
console.log('[Clippy] Knowledge package uploaded.');
|
|
69
|
+
if (options.localOutputDir) {
|
|
70
|
+
const written = new PackageWriter().writeArtifacts(options.localOutputDir, artifacts);
|
|
71
|
+
console.log(`[Clippy] Policy artifacts written: ${written.policyPath}, ${written.selectorsPath}`);
|
|
72
|
+
}
|
|
73
|
+
const artifactUpload = await performUpload(artifacts, options);
|
|
74
|
+
if (artifactUpload.skipped) {
|
|
75
|
+
console.log('[Clippy] Policy artifact upload skipped.');
|
|
53
76
|
}
|
|
54
77
|
else {
|
|
55
|
-
console.log(
|
|
78
|
+
console.log(`[Clippy] Policy artifacts uploaded (${artifactUpload.mode}).`);
|
|
79
|
+
}
|
|
80
|
+
const uploader = new Uploader(options);
|
|
81
|
+
if (options.legacyPackageMode) {
|
|
82
|
+
const knowledgePackage = packageBuilder.buildPackage({
|
|
83
|
+
buildId,
|
|
84
|
+
bundler: 'vite',
|
|
85
|
+
routes,
|
|
86
|
+
components: elements,
|
|
87
|
+
selectors,
|
|
88
|
+
flows,
|
|
89
|
+
});
|
|
90
|
+
if (options.localOutputDir) {
|
|
91
|
+
const written = new PackageWriter().write(options.localOutputDir, knowledgePackage);
|
|
92
|
+
console.log(`[Clippy] Legacy knowledge package written: ${written.jsonPath}`);
|
|
93
|
+
}
|
|
94
|
+
const legacyPayload = packageBuilder.build({
|
|
95
|
+
buildId: knowledgePackage.buildId,
|
|
96
|
+
bundler: knowledgePackage.bundler,
|
|
97
|
+
routes: knowledgePackage.routes,
|
|
98
|
+
components: knowledgePackage.components,
|
|
99
|
+
selectors: knowledgePackage.selectors,
|
|
100
|
+
flows: knowledgePackage.flows,
|
|
101
|
+
});
|
|
102
|
+
const legacyUploaded = await uploader.upload(legacyPayload);
|
|
103
|
+
if (legacyUploaded) {
|
|
104
|
+
console.log('[Clippy] Legacy knowledge package uploaded.');
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
console.log('[Clippy] Legacy knowledge package upload skipped.');
|
|
108
|
+
}
|
|
56
109
|
}
|
|
57
110
|
}
|
|
58
111
|
catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcoder-x/vite",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dcoder-x/plugin-shared": "
|
|
21
|
+
"@dcoder-x/plugin-shared": "workspace:*"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"vite": ">=4.0.0",
|