imxc 0.3.0 → 0.3.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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { parseArgs } from 'node:util';
3
3
  import * as path from 'node:path';
4
- import { initProject } from './init.js';
4
+ import { initProject, addToProject } from './init.js';
5
5
  import { compile } from './compile.js';
6
6
  import { startWatch } from './watch.js';
7
7
  // Handle `imxc init [dir]` subcommand
@@ -11,6 +11,13 @@ if (process.argv[2] === 'init') {
11
11
  initProject(absDir, path.basename(absDir));
12
12
  process.exit(0);
13
13
  }
14
+ // Handle `imxc add [dir]` subcommand
15
+ if (process.argv[2] === 'add') {
16
+ const dir = process.argv[3] ?? '.';
17
+ const absDir = path.resolve(dir);
18
+ addToProject(absDir);
19
+ process.exit(0);
20
+ }
14
21
  // Handle `imxc watch <dir> -o <output-dir>` subcommand
15
22
  if (process.argv[2] === 'watch') {
16
23
  const watchDir = process.argv[3];
@@ -35,6 +42,7 @@ else {
35
42
  if (positionals.length === 0) {
36
43
  console.error('Usage: imxc <input.tsx ...> -o <output-dir>');
37
44
  console.error(' imxc init [project-dir]');
45
+ console.error(' imxc add [project-dir]');
38
46
  console.error(' imxc watch <dir> -o <output-dir>');
39
47
  process.exit(1);
40
48
  }
package/dist/init.d.ts CHANGED
@@ -1 +1,2 @@
1
+ export declare function addToProject(projectDir: string): void;
1
2
  export declare function initProject(projectDir: string, projectName?: string): void;
package/dist/init.js CHANGED
@@ -98,6 +98,11 @@ int main() {
98
98
  glfwTerminate();
99
99
  return 0;
100
100
  }
101
+
102
+ #ifdef _WIN32
103
+ #include <windows.h>
104
+ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { return main(); }
105
+ #endif
101
106
  `;
102
107
  const APP_TSX = `export default function App() {
103
108
  const [count, setCount] = useState(0);
@@ -354,12 +359,15 @@ set(CMAKE_CXX_STANDARD 20)
354
359
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
355
360
 
356
361
  include(FetchContent)
362
+ set(FETCHCONTENT_QUIET OFF)
357
363
 
358
364
  FetchContent_Declare(
359
365
  imx
360
366
  GIT_REPOSITORY ${repoUrl}
361
367
  GIT_TAG main
368
+ GIT_PROGRESS TRUE
362
369
  )
370
+ message(STATUS "Fetching IMX (includes ImGui + GLFW)...")
363
371
  FetchContent_MakeAvailable(imx)
364
372
 
365
373
  include(ImxCompile)
@@ -373,6 +381,7 @@ add_executable(${projectName}
373
381
  src/main.cpp
374
382
  \${GENERATED}
375
383
  )
384
+ set_target_properties(${projectName} PROPERTIES WIN32_EXECUTABLE $<CONFIG:Release>)
376
385
  target_link_libraries(${projectName} PRIVATE imx::renderer)
377
386
  target_include_directories(${projectName} PRIVATE \${CMAKE_BINARY_DIR}/generated)
378
387
 
@@ -385,6 +394,61 @@ add_custom_command(TARGET ${projectName} POST_BUILD
385
394
  )
386
395
  `;
387
396
  }
397
+ export function addToProject(projectDir) {
398
+ const srcDir = path.join(projectDir, 'src');
399
+ if (fs.existsSync(path.join(srcDir, 'App.tsx'))) {
400
+ console.error(`Error: ${srcDir}/App.tsx already exists. Aborting.`);
401
+ process.exit(1);
402
+ }
403
+ fs.mkdirSync(srcDir, { recursive: true });
404
+ const publicDir = path.join(projectDir, 'public');
405
+ fs.mkdirSync(publicDir, { recursive: true });
406
+ // Write TSX source files only — no CMakeLists.txt or main.cpp
407
+ fs.writeFileSync(path.join(srcDir, 'App.tsx'), APP_TSX);
408
+ fs.writeFileSync(path.join(srcDir, 'imx.d.ts'), IMX_DTS);
409
+ fs.writeFileSync(path.join(projectDir, 'tsconfig.json'), TSCONFIG);
410
+ console.log(`imxc: added IMX sources to project`);
411
+ console.log('');
412
+ console.log(' Created:');
413
+ console.log(` src/App.tsx — your root component`);
414
+ console.log(` src/imx.d.ts — type definitions for IDE support`);
415
+ console.log(` tsconfig.json — TypeScript config`);
416
+ console.log(` public/ — static assets (copied to exe directory)`);
417
+ console.log('');
418
+ console.log(' Add to your CMakeLists.txt:');
419
+ console.log('');
420
+ console.log(' # --- IMX integration ---');
421
+ console.log(' include(FetchContent)');
422
+ console.log(' FetchContent_Declare(imx');
423
+ console.log(' GIT_REPOSITORY https://github.com/bgocumlu/imx.git');
424
+ console.log(' GIT_TAG main');
425
+ console.log(' )');
426
+ console.log(' FetchContent_MakeAvailable(imx)');
427
+ console.log(' include(ImxCompile)');
428
+ console.log('');
429
+ console.log(' imx_compile_tsx(GENERATED');
430
+ console.log(' SOURCES src/App.tsx');
431
+ console.log(' OUTPUT_DIR ${CMAKE_BINARY_DIR}/generated');
432
+ console.log(' )');
433
+ console.log('');
434
+ console.log(' # Add ${GENERATED} to your target sources:');
435
+ console.log(' target_sources(your_app PRIVATE ${GENERATED})');
436
+ console.log(' target_link_libraries(your_app PRIVATE imx::renderer)');
437
+ console.log(' target_include_directories(your_app PRIVATE ${CMAKE_BINARY_DIR}/generated)');
438
+ console.log('');
439
+ console.log(' # Copy assets to exe directory:');
440
+ console.log(' add_custom_command(TARGET your_app POST_BUILD');
441
+ console.log(' COMMAND ${CMAKE_COMMAND} -E copy_directory');
442
+ console.log(' ${CMAKE_CURRENT_SOURCE_DIR}/public $<TARGET_FILE_DIR:your_app>');
443
+ console.log(' )');
444
+ console.log('');
445
+ console.log(' Then add the IMX render call to your main loop:');
446
+ console.log('');
447
+ console.log(' #include <imx/runtime.h>');
448
+ console.log(' imx::Runtime runtime;');
449
+ console.log(' // In your frame loop, between NewFrame() and Render():');
450
+ console.log(' imx::render_root(runtime);');
451
+ }
388
452
  export function initProject(projectDir, projectName) {
389
453
  const name = projectName ?? path.basename(projectDir);
390
454
  const srcDir = path.join(projectDir, 'src');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imxc",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Compiler for IMX — compiles React-like .tsx to native Dear ImGui C++",
5
5
  "type": "module",
6
6
  "bin": {