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,4 @@
1
+ /**
2
+ * Scaffold a minimal TypeScript project for parsing IFC files.
3
+ */
4
+ export declare function createBasicTemplate(targetDir: string, projectName: string): void;
@@ -0,0 +1,96 @@
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 { mkdirSync, writeFileSync } from 'fs';
5
+ import { join } from 'path';
6
+ import { getLatestVersion } from '../utils/config-fixers.js';
7
+ /**
8
+ * Scaffold a minimal TypeScript project for parsing IFC files.
9
+ */
10
+ export function createBasicTemplate(targetDir, projectName) {
11
+ const latestVersion = getLatestVersion();
12
+ // package.json
13
+ writeFileSync(join(targetDir, 'package.json'), JSON.stringify({
14
+ name: projectName,
15
+ version: latestVersion.replace('^', ''),
16
+ type: 'module',
17
+ scripts: {
18
+ parse: 'npx tsx src/index.ts',
19
+ build: 'tsc',
20
+ },
21
+ dependencies: {
22
+ '@ifc-lite/parser': latestVersion,
23
+ },
24
+ devDependencies: {
25
+ typescript: '^5.3.0',
26
+ tsx: '^4.0.0',
27
+ },
28
+ }, null, 2));
29
+ // tsconfig.json
30
+ writeFileSync(join(targetDir, 'tsconfig.json'), JSON.stringify({
31
+ compilerOptions: {
32
+ target: 'ES2022',
33
+ module: 'ESNext',
34
+ moduleResolution: 'bundler',
35
+ strict: true,
36
+ esModuleInterop: true,
37
+ skipLibCheck: true,
38
+ outDir: 'dist',
39
+ },
40
+ include: ['src'],
41
+ }, null, 2));
42
+ // src/index.ts
43
+ mkdirSync(join(targetDir, 'src'));
44
+ writeFileSync(join(targetDir, 'src', 'index.ts'), `import { IfcParser } from '@ifc-lite/parser';
45
+ import { readFileSync } from 'fs';
46
+
47
+ // Example: Parse an IFC file
48
+ const ifcPath = process.argv[2];
49
+
50
+ if (!ifcPath) {
51
+ console.log('Usage: npm run parse <path-to-ifc-file>');
52
+ console.log('');
53
+ console.log('Example:');
54
+ console.log(' npm run parse ./model.ifc');
55
+ process.exit(1);
56
+ }
57
+
58
+ const buffer = readFileSync(ifcPath);
59
+ const parser = new IfcParser();
60
+
61
+ console.log('Parsing IFC file...');
62
+ parser.parse(buffer).then(result => {
63
+ console.log('\\nFile parsed successfully!');
64
+ console.log(\` Entities: \${result.entityCount}\`);
65
+
66
+ // Count by type
67
+ const typeCounts = new Map<string, number>();
68
+ for (const [id, entity] of result.entities) {
69
+ typeCounts.set(entity.type, (typeCounts.get(entity.type) || 0) + 1);
70
+ }
71
+
72
+ console.log('\\nTop entity types:');
73
+ const sorted = [...typeCounts.entries()].sort((a, b) => b[1] - a[1]).slice(0, 10);
74
+ for (const [type, count] of sorted) {
75
+ console.log(\` \${type}: \${count}\`);
76
+ }
77
+ });
78
+ `);
79
+ // README
80
+ writeFileSync(join(targetDir, 'README.md'), `# ${projectName}
81
+
82
+ IFC parser project using [IFC-Lite](https://github.com/louistrue/ifc-lite).
83
+
84
+ ## Quick Start
85
+
86
+ \`\`\`bash
87
+ npm install
88
+ npm run parse ./your-model.ifc
89
+ \`\`\`
90
+
91
+ ## Learn More
92
+
93
+ - [IFC-Lite Documentation](https://louistrue.github.io/ifc-lite/)
94
+ - [API Reference](https://louistrue.github.io/ifc-lite/api/)
95
+ `);
96
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Scaffold a native-binary IFC processing server with TypeScript client examples.
3
+ * No Docker required -- the server binary is downloaded and run via npm scripts.
4
+ */
5
+ export declare function createServerNativeTemplate(targetDir: string, projectName: string): void;
@@ -0,0 +1,406 @@
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 { mkdirSync, writeFileSync } from 'fs';
5
+ import { join } from 'path';
6
+ import { getLatestVersion } from '../utils/config-fixers.js';
7
+ /**
8
+ * Scaffold a native-binary IFC processing server with TypeScript client examples.
9
+ * No Docker required -- the server binary is downloaded and run via npm scripts.
10
+ */
11
+ export function createServerNativeTemplate(targetDir, projectName) {
12
+ const latestVersion = getLatestVersion();
13
+ // package.json
14
+ writeFileSync(join(targetDir, 'package.json'), JSON.stringify({
15
+ name: projectName,
16
+ version: '0.1.0',
17
+ type: 'module',
18
+ description: 'IFC processing server (native binary) with TypeScript client',
19
+ scripts: {
20
+ 'server:start': 'npx @ifc-lite/server-bin',
21
+ 'server:download': 'npx @ifc-lite/server-bin download',
22
+ 'server:info': 'npx @ifc-lite/server-bin info',
23
+ 'example': 'npx tsx src/example.ts',
24
+ 'example:stream': 'npx tsx src/example-stream.ts',
25
+ 'build': 'tsc',
26
+ 'typecheck': 'tsc --noEmit',
27
+ },
28
+ dependencies: {
29
+ '@ifc-lite/server-bin': latestVersion,
30
+ '@ifc-lite/server-client': latestVersion,
31
+ },
32
+ devDependencies: {
33
+ 'typescript': '^5.3.0',
34
+ 'tsx': '^4.0.0',
35
+ '@types/node': '^20.0.0',
36
+ },
37
+ optionalDependencies: {
38
+ 'parquet-wasm': '^0.6.0',
39
+ 'apache-arrow': '^17.0.0',
40
+ },
41
+ }, null, 2));
42
+ // tsconfig.json
43
+ writeFileSync(join(targetDir, 'tsconfig.json'), JSON.stringify({
44
+ compilerOptions: {
45
+ target: 'ES2022',
46
+ module: 'ESNext',
47
+ moduleResolution: 'bundler',
48
+ strict: true,
49
+ esModuleInterop: true,
50
+ skipLibCheck: true,
51
+ outDir: 'dist',
52
+ declaration: true,
53
+ lib: ['ES2022'],
54
+ },
55
+ include: ['src'],
56
+ exclude: ['node_modules', 'dist'],
57
+ }, null, 2));
58
+ // .env.example
59
+ writeFileSync(join(targetDir, '.env.example'), `# IFC-Lite Server Configuration (Native Binary)
60
+ # These environment variables configure the server
61
+
62
+ # =============================================================================
63
+ # SERVER SETTINGS
64
+ # =============================================================================
65
+
66
+ # Server port
67
+ PORT=8080
68
+
69
+ # Log level: error, warn, info, debug, trace
70
+ RUST_LOG=info
71
+
72
+ # =============================================================================
73
+ # FILE PROCESSING
74
+ # =============================================================================
75
+
76
+ # Maximum IFC file size in megabytes
77
+ MAX_FILE_SIZE_MB=500
78
+
79
+ # Request timeout in seconds
80
+ REQUEST_TIMEOUT_SECS=300
81
+
82
+ # Number of worker threads for parallel processing
83
+ # Default: number of CPU cores
84
+ WORKER_THREADS=4
85
+
86
+ # =============================================================================
87
+ # STREAMING
88
+ # =============================================================================
89
+
90
+ # Initial batch size for fast first frame
91
+ INITIAL_BATCH_SIZE=100
92
+
93
+ # Maximum batch size for throughput
94
+ MAX_BATCH_SIZE=1000
95
+
96
+ # =============================================================================
97
+ # CACHING
98
+ # =============================================================================
99
+
100
+ # Cache directory (relative or absolute path)
101
+ CACHE_DIR=./.cache
102
+
103
+ # Cache retention in days
104
+ CACHE_MAX_AGE_DAYS=7
105
+ `);
106
+ // .gitignore
107
+ writeFileSync(join(targetDir, '.gitignore'), `# Dependencies
108
+ node_modules/
109
+
110
+ # Build output
111
+ dist/
112
+
113
+ # Environment files
114
+ .env
115
+ .env.local
116
+ .env.*.local
117
+
118
+ # Cache directory
119
+ .cache/
120
+
121
+ # IDE
122
+ .idea/
123
+ .vscode/
124
+ *.swp
125
+ *.swo
126
+
127
+ # OS
128
+ .DS_Store
129
+ Thumbs.db
130
+
131
+ # Logs
132
+ *.log
133
+ npm-debug.log*
134
+ `);
135
+ // Create src directory
136
+ mkdirSync(join(targetDir, 'src'));
137
+ // src/example.ts
138
+ writeFileSync(join(targetDir, 'src', 'example.ts'), `/**
139
+ * IFC-Lite Native Server Example
140
+ *
141
+ * This example demonstrates using the IFC-Lite server with native binary.
142
+ * No Docker required - the binary is downloaded and run automatically.
143
+ *
144
+ * Usage:
145
+ * 1. Start the server: npm run server:start
146
+ * 2. In another terminal: npm run example ./your-model.ifc
147
+ */
148
+
149
+ import { IfcServerClient } from '@ifc-lite/server-client';
150
+ import { readFileSync, existsSync } from 'fs';
151
+
152
+ const SERVER_URL = process.env.SERVER_URL || 'http://localhost:8080';
153
+
154
+ async function main() {
155
+ const client = new IfcServerClient({
156
+ baseUrl: SERVER_URL,
157
+ timeout: 300000,
158
+ });
159
+
160
+ // Check server
161
+ console.log('Checking server health...');
162
+ try {
163
+ const health = await client.health();
164
+ console.log(\`Server status: \${health.status}\`);
165
+ } catch (error) {
166
+ console.error('Failed to connect to server.');
167
+ console.error('Start it with: npm run server:start');
168
+ process.exit(1);
169
+ }
170
+
171
+ const ifcPath = process.argv[2];
172
+ if (!ifcPath) {
173
+ console.log(\`
174
+ Usage: npm run example <path-to-ifc-file>
175
+
176
+ Example:
177
+ npm run example ./model.ifc
178
+ \`);
179
+ return;
180
+ }
181
+
182
+ if (!existsSync(ifcPath)) {
183
+ console.error(\`File not found: \${ifcPath}\`);
184
+ process.exit(1);
185
+ }
186
+
187
+ const buffer = readFileSync(ifcPath);
188
+ console.log(\`\\nParsing: \${ifcPath}\`);
189
+ console.log(\`File size: \${(buffer.length / 1024 / 1024).toFixed(2)} MB\`);
190
+
191
+ const startTime = performance.now();
192
+
193
+ try {
194
+ const parquetAvailable = await client.isParquetSupported();
195
+
196
+ if (parquetAvailable) {
197
+ console.log('Using Parquet format (15x smaller)');
198
+ const result = await client.parseParquet(buffer);
199
+ const elapsed = performance.now() - startTime;
200
+
201
+ console.log(\`\\nComplete in \${elapsed.toFixed(0)}ms\`);
202
+ console.log(\` Meshes: \${result.meshes.length}\`);
203
+ console.log(\` Payload: \${(result.parquet_stats.payload_size / 1024).toFixed(1)} KB\`);
204
+
205
+ if (result.stats) {
206
+ console.log(\` Triangles: \${result.stats.total_triangles}\`);
207
+ }
208
+ } else {
209
+ console.log('Using JSON format');
210
+ const result = await client.parse(buffer);
211
+ const elapsed = performance.now() - startTime;
212
+
213
+ console.log(\`\\nComplete in \${elapsed.toFixed(0)}ms\`);
214
+ console.log(\` Meshes: \${result.meshes.length}\`);
215
+ }
216
+ } catch (error) {
217
+ console.error('Parse failed:', error);
218
+ process.exit(1);
219
+ }
220
+ }
221
+
222
+ main().catch(console.error);
223
+ `);
224
+ // src/example-stream.ts
225
+ writeFileSync(join(targetDir, 'src', 'example-stream.ts'), `/**
226
+ * IFC-Lite Native Server Streaming Example
227
+ *
228
+ * For large files (>50MB) - geometry arrives in batches.
229
+ *
230
+ * Usage:
231
+ * 1. Start the server: npm run server:start
232
+ * 2. In another terminal: npm run example:stream ./large-model.ifc
233
+ */
234
+
235
+ import { IfcServerClient } from '@ifc-lite/server-client';
236
+ import { readFileSync, existsSync } from 'fs';
237
+
238
+ const SERVER_URL = process.env.SERVER_URL || 'http://localhost:8080';
239
+
240
+ async function main() {
241
+ const client = new IfcServerClient({
242
+ baseUrl: SERVER_URL,
243
+ timeout: 600000,
244
+ });
245
+
246
+ try {
247
+ await client.health();
248
+ console.log('Server connected');
249
+ } catch {
250
+ console.error('Server not available. Start with: npm run server:start');
251
+ process.exit(1);
252
+ }
253
+
254
+ const ifcPath = process.argv[2];
255
+ if (!ifcPath || !existsSync(ifcPath)) {
256
+ console.log('Usage: npm run example:stream <path-to-ifc-file>');
257
+ process.exit(1);
258
+ }
259
+
260
+ const parquetAvailable = await client.isParquetSupported();
261
+ if (!parquetAvailable) {
262
+ console.error('Streaming requires parquet-wasm and apache-arrow.');
263
+ console.error('Install with: npm install parquet-wasm apache-arrow');
264
+ process.exit(1);
265
+ }
266
+
267
+ const buffer = readFileSync(ifcPath);
268
+ console.log(\`\\nStreaming: \${ifcPath} (\${(buffer.length / 1024 / 1024).toFixed(1)} MB)\`);
269
+
270
+ const startTime = performance.now();
271
+ let totalMeshes = 0;
272
+
273
+ try {
274
+ const result = await client.parseParquetStream(buffer, (batch) => {
275
+ totalMeshes += batch.meshes.length;
276
+ console.log(\` Batch #\${batch.batch_number}: +\${batch.meshes.length} meshes (total: \${totalMeshes})\`);
277
+ });
278
+
279
+ const elapsed = performance.now() - startTime;
280
+ console.log(\`\\nComplete in \${elapsed.toFixed(0)}ms\`);
281
+ console.log(\` Total meshes: \${result.total_meshes}\`);
282
+
283
+ } catch (error) {
284
+ console.error('Streaming failed:', error);
285
+ process.exit(1);
286
+ }
287
+ }
288
+
289
+ main().catch(console.error);
290
+ `);
291
+ // src/index.ts
292
+ writeFileSync(join(targetDir, 'src', 'index.ts'), `/**
293
+ * ${projectName} - IFC Processing Server (Native Binary)
294
+ *
295
+ * Re-exports for custom integrations.
296
+ */
297
+
298
+ export { IfcServerClient } from '@ifc-lite/server-client';
299
+ export type {
300
+ ServerConfig,
301
+ ParseResponse,
302
+ ParquetParseResponse,
303
+ StreamEvent,
304
+ HealthResponse,
305
+ MetadataResponse,
306
+ } from '@ifc-lite/server-client';
307
+
308
+ export const DEFAULT_SERVER_URL = 'http://localhost:8080';
309
+ `);
310
+ // README.md
311
+ writeFileSync(join(targetDir, 'README.md'), `# ${projectName}
312
+
313
+ IFC processing server using native binary - no Docker required.
314
+
315
+ ## Quick Start
316
+
317
+ \`\`\`bash
318
+ # Install dependencies (downloads server binary automatically)
319
+ npm install
320
+
321
+ # Start the server
322
+ npm run server:start
323
+
324
+ # In another terminal, run the example
325
+ npm run example ./your-model.ifc
326
+ \`\`\`
327
+
328
+ ## Features
329
+
330
+ | Feature | Description |
331
+ |---------|-------------|
332
+ | **No Docker Required** | Native binary runs directly |
333
+ | **Auto-Download** | Binary downloaded on first run |
334
+ | **Cross-Platform** | macOS, Linux, Windows support |
335
+ | **Content-Addressable Cache** | Same file = instant response |
336
+
337
+ ## Scripts
338
+
339
+ | Command | Description |
340
+ |---------|-------------|
341
+ | \`npm run server:start\` | Start the IFC-Lite server |
342
+ | \`npm run server:download\` | Download binary without starting |
343
+ | \`npm run server:info\` | Show platform and binary info |
344
+ | \`npm run example\` | Basic parsing example |
345
+ | \`npm run example:stream\` | Streaming example for large files |
346
+
347
+ ## Configuration
348
+
349
+ Set environment variables to configure the server:
350
+
351
+ \`\`\`bash
352
+ # Custom port
353
+ PORT=3001 npm run server:start
354
+
355
+ # Debug logging
356
+ RUST_LOG=debug npm run server:start
357
+
358
+ # Multiple options
359
+ PORT=3001 WORKER_THREADS=8 npm run server:start
360
+ \`\`\`
361
+
362
+ See \`.env.example\` for all options.
363
+
364
+ ## API Endpoints
365
+
366
+ | Endpoint | Description |
367
+ |----------|-------------|
368
+ | \`GET /api/v1/health\` | Health check |
369
+ | \`POST /api/v1/parse\` | Full parse (JSON) |
370
+ | \`POST /api/v1/parse/parquet\` | Full parse (Parquet, 15x smaller) |
371
+ | \`POST /api/v1/parse/parquet-stream\` | Streaming parse |
372
+ | \`GET /api/v1/cache/check/:hash\` | Check cache |
373
+
374
+ ## Supported Platforms
375
+
376
+ | Platform | Architecture | Status |
377
+ |----------|--------------|--------|
378
+ | macOS | Intel (x64) | ✅ |
379
+ | macOS | Apple Silicon (arm64) | ✅ |
380
+ | Linux | x64 | ✅ |
381
+ | Linux | arm64 | ✅ |
382
+ | Windows | x64 | ✅ |
383
+
384
+ ## Alternatives
385
+
386
+ If native binaries don't work for your platform:
387
+
388
+ \`\`\`bash
389
+ # Use Docker instead
390
+ npx create-ifc-lite my-app --template server
391
+ \`\`\`
392
+
393
+ ## Learn More
394
+
395
+ - [IFC-Lite Documentation](https://louistrue.github.io/ifc-lite/)
396
+ - [GitHub Repository](https://github.com/louistrue/ifc-lite)
397
+ `);
398
+ console.log(' Created package.json');
399
+ console.log(' Created tsconfig.json');
400
+ console.log(' Created .env.example');
401
+ console.log(' Created .gitignore');
402
+ console.log(' Created src/example.ts');
403
+ console.log(' Created src/example-stream.ts');
404
+ console.log(' Created src/index.ts');
405
+ console.log(' Created README.md');
406
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Scaffold a Docker-based IFC processing server with TypeScript client examples.
3
+ */
4
+ export declare function createServerTemplate(targetDir: string, projectName: string): void;