-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathbuild-stackblitz-files.ts
More file actions
97 lines (84 loc) · 2.98 KB
/
build-stackblitz-files.ts
File metadata and controls
97 lines (84 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* LayerChart StackBlitz Files Generator
*
* This script generates base files needed for StackBlitz projects that can run
* any LayerChart example in an isolated environment.
*
* @description
* Reads template files from scripts/stackblitz-template/ and generates:
* - package.json with LayerChart and dependencies
* - SvelteKit configuration files
* - Basic layout and app.html
* - Outputs to docs/static/stackblitz-files.json
*
* @usage
* pnpm generate:stackblitz
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { readAllFilesFromDirectory } from './stackblitz-utils.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const TEMPLATES_DIR = path.resolve(__dirname, 'stackblitz-template');
const SOURCE_DIR = path.resolve(__dirname, '../src');
const OUTPUT_FILE = path.resolve(__dirname, '../static/stackblitz-files.json');
const REMOTE_SOURCES_FILE = path.resolve(__dirname, '../static/remote-sources.json');
/**
* Read a source file from the docs/src directory
*/
function readSource(sourcePath: string): string {
const filePath = path.join(SOURCE_DIR, sourcePath);
return fs.readFileSync(filePath, 'utf-8');
}
// Suppress unused variable warnings - fs and path are used via the imported function
void fs;
void path;
/**
* Generate the base files object by reading from template files
*/
function generateStackBlitzFiles() {
return {
// Read all template files from stackblitz-template directory
...readAllFilesFromDirectory(TEMPLATES_DIR),
// Add source files from docs/src
'src/lib/utils/data.ts': readSource('lib/utils/data.ts')
};
}
/**
* Generate a JSON file containing the source code of remote modules
* This is used by stackblitz.server.ts to parse function definitions
*/
function generateRemoteSourceFiles() {
return {
'data.remote.ts': readSource('lib/data.remote.ts'),
'geo.remote.ts': readSource('lib/geo.remote.ts'),
'graph.remote.ts': readSource('lib/graph.remote.ts')
};
}
/**
* Main function
*/
async function main() {
console.log('LayerChart StackBlitz Files Generator');
console.log('=====================================\n');
const files = generateStackBlitzFiles();
const remoteSources = generateRemoteSourceFiles();
// Ensure output directory exists
const outputDir = path.dirname(OUTPUT_FILE);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Write the files
fs.writeFileSync(OUTPUT_FILE, JSON.stringify(files, null, 2));
fs.writeFileSync(REMOTE_SOURCES_FILE, JSON.stringify(remoteSources, null, 2));
console.log(`✅ StackBlitz files saved to ${OUTPUT_FILE}`);
console.log(` Total files: ${Object.keys(files).length}`);
console.log(`\n✅ Remote source files saved to ${REMOTE_SOURCES_FILE}`);
console.log(` Total remote files: ${Object.keys(remoteSources).length}`);
console.log(`\nTemplate files read from: ${TEMPLATES_DIR}`);
}
main().catch((error) => {
console.error('Fatal error:', error);
process.exit(1);
});