react-scanner-ui 0.0.14 ā 0.0.15
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAyHpC,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAUnD"}
|
package/dist/commands/build.js
CHANGED
|
@@ -1,11 +1,109 @@
|
|
|
1
|
+
import { resolve, dirname } from 'path';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import { writeFileSync, mkdirSync, existsSync } from 'fs';
|
|
1
4
|
import { checkPeerDependency } from '../utils/dependencies.js';
|
|
5
|
+
import { getScanData } from '../utils/scannerConfig.js';
|
|
6
|
+
// ESM equivalent of __dirname
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
/**
|
|
10
|
+
* Get the path to the UI directory.
|
|
11
|
+
* Works both in development (src/) and production (dist/)
|
|
12
|
+
*/
|
|
13
|
+
function getUiRoot() {
|
|
14
|
+
// __dirname will be either src/commands or dist/commands
|
|
15
|
+
// UI is always at project-root/ui
|
|
16
|
+
const currentDir = __dirname;
|
|
17
|
+
// Go up from commands/ to src/ or dist/, then up to project root, then into ui/
|
|
18
|
+
return resolve(currentDir, '../../ui');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build the React Scanner UI and output to consumer's .react-scanner-ui/ folder
|
|
22
|
+
*/
|
|
23
|
+
async function runBuild() {
|
|
24
|
+
const consumerRoot = process.cwd();
|
|
25
|
+
const outputDir = resolve(consumerRoot, '.react-scanner-ui');
|
|
26
|
+
console.log('\nš¦ Building React Scanner UI...\n');
|
|
27
|
+
// Step 1: Get the scan data
|
|
28
|
+
console.log(' ā Reading scan data...');
|
|
29
|
+
const scanResult = await getScanData();
|
|
30
|
+
if (scanResult.error) {
|
|
31
|
+
console.error(`\nā Error: ${scanResult.error}`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
if (!scanResult.data) {
|
|
35
|
+
console.error('\nā Error: No scan data found.');
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
// Step 2: Build the UI with Vite
|
|
39
|
+
console.log(' ā Building UI with Vite...');
|
|
40
|
+
const { build } = await import('vite');
|
|
41
|
+
const react = (await import('@vitejs/plugin-react')).default;
|
|
42
|
+
const uiRoot = getUiRoot();
|
|
43
|
+
// Create output directory if it doesn't exist
|
|
44
|
+
if (!existsSync(outputDir)) {
|
|
45
|
+
mkdirSync(outputDir, { recursive: true });
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
await build({
|
|
49
|
+
root: uiRoot,
|
|
50
|
+
plugins: [react()],
|
|
51
|
+
base: './', // Use relative paths for assets
|
|
52
|
+
build: {
|
|
53
|
+
outDir: outputDir,
|
|
54
|
+
emptyOutDir: true,
|
|
55
|
+
},
|
|
56
|
+
resolve: {
|
|
57
|
+
alias: {
|
|
58
|
+
'@': resolve(uiRoot, 'src'),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
logLevel: 'warn', // Reduce noise during build
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error('\nā Vite build failed:', error);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
// Step 3: Write the scan data as a JSON file
|
|
69
|
+
console.log(' ā Embedding scan data...');
|
|
70
|
+
const scanDataPath = resolve(outputDir, 'scan-data.json');
|
|
71
|
+
writeFileSync(scanDataPath, JSON.stringify({ data: scanResult.data, error: null }, null, 2));
|
|
72
|
+
// Step 4: Create a custom index.html that loads scan data from the JSON file
|
|
73
|
+
// We need to modify the built index.html to handle static data loading
|
|
74
|
+
const indexPath = resolve(outputDir, 'index.html');
|
|
75
|
+
const { readFileSync } = await import('fs');
|
|
76
|
+
let indexHtml = readFileSync(indexPath, 'utf-8');
|
|
77
|
+
// Inject a script that intercepts fetch calls to /api/scan-data
|
|
78
|
+
const injectScript = `
|
|
79
|
+
<script>
|
|
80
|
+
// Intercept fetch for static build
|
|
81
|
+
const originalFetch = window.fetch;
|
|
82
|
+
window.fetch = async function(url, options) {
|
|
83
|
+
if (url === '/api/scan-data' || url.endsWith('/api/scan-data')) {
|
|
84
|
+
const response = await originalFetch('./scan-data.json', options);
|
|
85
|
+
return response;
|
|
86
|
+
}
|
|
87
|
+
return originalFetch(url, options);
|
|
88
|
+
};
|
|
89
|
+
</script>
|
|
90
|
+
`;
|
|
91
|
+
// Inject the script before the closing </head> tag
|
|
92
|
+
indexHtml = indexHtml.replace('</head>', `${injectScript}</head>`);
|
|
93
|
+
writeFileSync(indexPath, indexHtml);
|
|
94
|
+
console.log(`\nā
Build complete! Output: ${outputDir}\n`);
|
|
95
|
+
console.log(' You can serve the static files with any web server:');
|
|
96
|
+
console.log(` ā npx serve ${outputDir}`);
|
|
97
|
+
console.log(` ā python -m http.server -d ${outputDir}`);
|
|
98
|
+
console.log('');
|
|
99
|
+
}
|
|
2
100
|
export function buildCommand(program) {
|
|
3
101
|
program
|
|
4
102
|
.command('build')
|
|
5
|
-
.description('
|
|
6
|
-
.action(() => {
|
|
103
|
+
.description('Build the React Scanner UI as static files to .react-scanner-ui/')
|
|
104
|
+
.action(async () => {
|
|
7
105
|
checkPeerDependency();
|
|
8
|
-
|
|
106
|
+
await runBuild();
|
|
9
107
|
});
|
|
10
108
|
}
|
|
11
109
|
//# sourceMappingURL=build.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,8BAA8B;AAC9B,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC;;;GAGG;AACH,SAAS,SAAS;IAChB,yDAAyD;IACzD,kCAAkC;IAClC,MAAM,UAAU,GAAG,SAAS,CAAC;IAE7B,gFAAgF;IAChF,OAAO,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,QAAQ;IACrB,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACnC,MAAM,SAAS,GAAG,OAAO,CAAC,YAAY,EAAE,mBAAmB,CAAC,CAAC;IAE7D,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;IAEnD,4BAA4B;IAC5B,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,MAAM,WAAW,EAAE,CAAC;IAEvC,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;QACrB,OAAO,CAAC,KAAK,CAAC,cAAc,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;QAChD,OAAO,CAAC,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-1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAGA,wBAAgB,wBAAwB,IAAI,IAAI,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAGA,wBAAgB,wBAAwB,IAAI,IAAI,CAyB/C"}
|
package/dist/utils/config.js
CHANGED
|
@@ -18,6 +18,7 @@ export function createReactScannerConfig() {
|
|
|
18
18
|
try {
|
|
19
19
|
writeFileSync(configPath, configContent);
|
|
20
20
|
console.log('Created react-scanner.config.js');
|
|
21
|
+
console.log('\nš” Tip: Add .react-scanner-ui/ to your .gitignore file.');
|
|
21
22
|
}
|
|
22
23
|
catch (error) {
|
|
23
24
|
console.error('Failed to create react-scanner.config.js', error);
|
package/dist/utils/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,MAAM,UAAU,wBAAwB;IACtC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,yBAAyB,CAAC,CAAC;IAElE,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;QACvD,OAAO;IACT,CAAC;IAED,MAAM,aAAa,GAAG;;;;;;;;CAQvB,CAAC;IAEA,IAAI,CAAC;QACH,aAAa,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;QACzC,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA,OAA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