create-ifc-lite 1.6.0 → 1.7.0

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.
@@ -0,0 +1,143 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+ import { existsSync, readFileSync, writeFileSync, rmSync } from 'fs';
5
+ import { join } from 'path';
6
+ import { execSync } from 'child_process';
7
+ /**
8
+ * Fetch the latest published version of @ifc-lite/parser from npm.
9
+ * Falls back to '^1.0.0' when the registry is unreachable.
10
+ */
11
+ export function getLatestVersion() {
12
+ try {
13
+ const result = execSync('npm view @ifc-lite/parser version', { stdio: 'pipe' });
14
+ return `^${result.toString().trim()}`;
15
+ }
16
+ catch {
17
+ return '^1.0.0'; // fallback
18
+ }
19
+ }
20
+ /**
21
+ * Rewrite the viewer's package.json so it works as a standalone project:
22
+ * - Set the project name
23
+ * - Replace workspace: protocol versions with the latest npm version
24
+ * - Remove the .git directory if present
25
+ */
26
+ export function fixPackageJson(targetDir, projectName) {
27
+ const pkgPath = join(targetDir, 'package.json');
28
+ if (!existsSync(pkgPath))
29
+ return;
30
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
31
+ // Update name
32
+ pkg.name = projectName;
33
+ // Replace workspace protocol with latest npm version in all dependency fields
34
+ const latestVersion = getLatestVersion();
35
+ const depFields = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
36
+ for (const field of depFields) {
37
+ const deps = pkg[field];
38
+ if (!deps)
39
+ continue;
40
+ for (const [name, version] of Object.entries(deps)) {
41
+ if (typeof version === 'string' && version.includes('workspace:')) {
42
+ deps[name] = latestVersion;
43
+ }
44
+ }
45
+ }
46
+ // Remove git directory if present
47
+ const gitDir = join(targetDir, '.git');
48
+ if (existsSync(gitDir)) {
49
+ rmSync(gitDir, { recursive: true, force: true });
50
+ }
51
+ writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
52
+ }
53
+ /**
54
+ * Write a standalone tsconfig.json without monorepo references.
55
+ */
56
+ export function fixTsConfig(targetDir) {
57
+ const tsconfigPath = join(targetDir, 'tsconfig.json');
58
+ // Write standalone tsconfig without monorepo references
59
+ const tsconfig = {
60
+ compilerOptions: {
61
+ target: 'ES2022',
62
+ lib: ['ES2022', 'DOM', 'DOM.Iterable'],
63
+ module: 'ESNext',
64
+ moduleResolution: 'bundler',
65
+ jsx: 'react-jsx',
66
+ strict: true,
67
+ esModuleInterop: true,
68
+ skipLibCheck: true,
69
+ noEmit: true,
70
+ baseUrl: '.',
71
+ paths: {
72
+ '@/*': ['./src/*']
73
+ }
74
+ },
75
+ include: ['src/**/*'],
76
+ exclude: ['node_modules']
77
+ };
78
+ writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2));
79
+ }
80
+ /**
81
+ * Write a standalone vite.config.ts with WASM support.
82
+ */
83
+ export function fixViteConfig(targetDir) {
84
+ const viteConfigPath = join(targetDir, 'vite.config.ts');
85
+ // Write standalone vite config with WASM support
86
+ const viteConfig = `import { defineConfig } from 'vite';
87
+ import react from '@vitejs/plugin-react';
88
+ import path from 'path';
89
+ import { readFileSync } from 'fs';
90
+
91
+ const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));
92
+
93
+ export default defineConfig({
94
+ plugins: [
95
+ react(),
96
+ {
97
+ name: 'wasm-mime-type',
98
+ configureServer(server) {
99
+ server.middlewares.use((req, res, next) => {
100
+ if (req.url?.endsWith('.wasm')) {
101
+ res.setHeader('Content-Type', 'application/wasm');
102
+ }
103
+ next();
104
+ });
105
+ },
106
+ },
107
+ ],
108
+ define: {
109
+ __APP_VERSION__: JSON.stringify(pkg.version),
110
+ __BUILD_DATE__: JSON.stringify(new Date().toISOString()),
111
+ __RELEASE_HISTORY__: JSON.stringify([]),
112
+ },
113
+ resolve: {
114
+ alias: {
115
+ '@': path.resolve(__dirname, './src'),
116
+ },
117
+ },
118
+ server: {
119
+ port: 3000,
120
+ open: true,
121
+ fs: {
122
+ allow: ['..'],
123
+ },
124
+ },
125
+ build: {
126
+ target: 'esnext',
127
+ },
128
+ optimizeDeps: {
129
+ exclude: ['@duckdb/duckdb-wasm', '@ifc-lite/wasm'],
130
+ },
131
+ assetsInclude: ['**/*.wasm'],
132
+ });
133
+ `;
134
+ writeFileSync(viteConfigPath, viteConfig);
135
+ }
136
+ /**
137
+ * Apply all viewer-template fixups: package.json, tsconfig, vite config.
138
+ */
139
+ export function fixViewerTemplate(targetDir, projectName) {
140
+ fixPackageJson(targetDir, projectName);
141
+ fixTsConfig(targetDir);
142
+ fixViteConfig(targetDir);
143
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Download the viewer application from the ifc-lite GitHub repository.
3
+ *
4
+ * Tries `npx degit` first (fastest path). Falls back to a git sparse
5
+ * checkout when degit is unavailable or fails.
6
+ */
7
+ export declare function downloadViewer(targetDir: string, _projectName: string): Promise<boolean>;
@@ -0,0 +1,63 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+ import { rmSync } from 'fs';
5
+ import { join, dirname } from 'path';
6
+ import { execSync } from 'child_process';
7
+ const REPO_URL = 'https://github.com/louistrue/ifc-lite';
8
+ const VIEWER_PATH = 'apps/viewer';
9
+ /**
10
+ * Run a shell command silently. Returns true on success, false on failure.
11
+ */
12
+ function runCommand(cmd, cwd) {
13
+ try {
14
+ execSync(cmd, { cwd, stdio: 'pipe' });
15
+ return true;
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
21
+ /**
22
+ * Download the viewer application from the ifc-lite GitHub repository.
23
+ *
24
+ * Tries `npx degit` first (fastest path). Falls back to a git sparse
25
+ * checkout when degit is unavailable or fails.
26
+ */
27
+ export async function downloadViewer(targetDir, _projectName) {
28
+ // Try degit first (fastest)
29
+ if (runCommand('npx --version')) {
30
+ console.log(' Downloading viewer template...');
31
+ try {
32
+ execSync(`npx degit ${REPO_URL}/${VIEWER_PATH} "${targetDir}"`, {
33
+ stdio: 'pipe',
34
+ timeout: 60000
35
+ });
36
+ return true;
37
+ }
38
+ catch {
39
+ // degit failed, try git sparse checkout
40
+ }
41
+ }
42
+ // Fallback: git sparse checkout
43
+ if (runCommand('git --version')) {
44
+ console.log(' Downloading via git...');
45
+ const tempDir = join(dirname(targetDir), `.temp-${Date.now()}`);
46
+ try {
47
+ execSync(`git clone --filter=blob:none --sparse "${REPO_URL}.git" "${tempDir}"`, {
48
+ stdio: 'pipe',
49
+ timeout: 120000
50
+ });
51
+ execSync(`git sparse-checkout set ${VIEWER_PATH}`, { cwd: tempDir, stdio: 'pipe' });
52
+ // Move viewer to target
53
+ const viewerSrc = join(tempDir, VIEWER_PATH);
54
+ execSync(`mv "${viewerSrc}" "${targetDir}"`, { stdio: 'pipe' });
55
+ rmSync(tempDir, { recursive: true, force: true });
56
+ return true;
57
+ }
58
+ catch {
59
+ rmSync(tempDir, { recursive: true, force: true });
60
+ }
61
+ }
62
+ return false;
63
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ifc-lite",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Create IFC-Lite projects with one command",
5
5
  "type": "module",
6
6
  "bin": {