@iwsdk/create 0.3.1 → 0.4.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.
Files changed (2) hide show
  1. package/dist/cli.js +150 -79
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import require$$0$2, { execSync, spawn as spawn$1 } from 'child_process';
2
+ import require$$0$2, { execSync, spawn as spawn$1, execFileSync } from 'child_process';
3
3
  import fs$2 from 'fs';
4
4
  import path$4, { dirname, join } from 'path';
5
5
  import { fileURLToPath } from 'url';
@@ -10960,6 +10960,12 @@ async function installDependenciesFromBundle(outDir, source) {
10960
10960
  throw e;
10961
10961
  }
10962
10962
  }
10963
+ function printReferenceWarmupGuidance() {
10964
+ console.log(stdoutColor.gray(' # @iwsdk/reference downloads its pinned model automatically during warmup'));
10965
+ console.log(stdoutColor.gray(' # optional for bundle/internal or unpublished corpus payloads: set IWSDK_REFERENCE_ASSETS_BASE_URL to the hosted reference-assets dist URL'));
10966
+ console.log(stdoutColor.gray(' # warmup still needs access to the baked public model file URLs unless the shared cache is already pre-warmed'));
10967
+ console.log(stdoutColor.gray(' # then run: npx iwsdk reference warmup'));
10968
+ }
10963
10969
  function printNextSteps(appName, installed, actionItems = []) {
10964
10970
  const startCmd = 'npm run dev';
10965
10971
  console.log('\nNext steps:');
@@ -10983,6 +10989,7 @@ function printNextSteps(appName, installed, actionItems = []) {
10983
10989
  if (!installed) {
10984
10990
  console.log(stdoutColor.gray(' npm install'));
10985
10991
  }
10992
+ printReferenceWarmupGuidance();
10986
10993
  console.log(stdoutColor.gray(` ${startCmd}`));
10987
10994
  }
10988
10995
  function printPrerequisites(prereqs = []) {
@@ -19526,7 +19533,11 @@ async function detectMSEVersion(platform) {
19526
19533
  }
19527
19534
  function isVersionSufficient(installed, required = MSE_MIN_VERSION) {
19528
19535
  try {
19529
- return semver$1.gte(installed, required);
19536
+ const coerced = semver$1.coerce(installed);
19537
+ if (!coerced) {
19538
+ return false;
19539
+ }
19540
+ return semver$1.gte(coerced, required);
19530
19541
  }
19531
19542
  catch {
19532
19543
  return false;
@@ -19797,7 +19808,7 @@ async function installMSE() {
19797
19808
  * This source code is licensed under the MIT license found in the
19798
19809
  * LICENSE file in the root directory of this source tree.
19799
19810
  */
19800
- async function promptFlow(nameArg) {
19811
+ async function promptFlow(nameArg, defaults = {}) {
19801
19812
  let cancelled = false;
19802
19813
  const onCancel = () => {
19803
19814
  cancelled = true;
@@ -19838,41 +19849,58 @@ async function promptFlow(nameArg) {
19838
19849
  const resolvedAiTools = aiTools?.includes('none')
19839
19850
  ? []
19840
19851
  : aiTools || [];
19841
- const { language, mode } = await prompts$1([
19842
- {
19843
- type: 'select',
19844
- name: 'language',
19845
- message: 'Which language do you want to use?',
19846
- choices: [
19847
- { title: 'TypeScript', value: 'ts' },
19848
- { title: 'JavaScript', value: 'js' },
19849
- ],
19850
- initial: 0,
19851
- },
19852
- {
19852
+ const { language } = await prompts$1({
19853
+ type: 'select',
19854
+ name: 'language',
19855
+ message: 'Which language do you want to use?',
19856
+ choices: [
19857
+ { title: 'TypeScript', value: 'ts' },
19858
+ { title: 'JavaScript', value: 'js' },
19859
+ ],
19860
+ initial: 0,
19861
+ }, { onCancel });
19862
+ if (cancelled) {
19863
+ throw new Error('Input cancelled');
19864
+ }
19865
+ const xrEnabled = defaults.xrEnabled ??
19866
+ !!(await prompts$1({
19867
+ type: 'toggle',
19868
+ name: 'xrEnabled',
19869
+ message: 'Enable XR support?',
19870
+ initial: true,
19871
+ active: 'Yes',
19872
+ inactive: 'No',
19873
+ }, { onCancel })).xrEnabled;
19874
+ if (cancelled) {
19875
+ throw new Error('Input cancelled');
19876
+ }
19877
+ const { mode = 'vr' } = xrEnabled
19878
+ ? await prompts$1({
19853
19879
  type: 'select',
19854
19880
  name: 'mode',
19855
- message: 'What type of experience are you building?',
19881
+ message: 'What type of XR experience are you building?',
19856
19882
  choices: [
19857
19883
  { title: 'Virtual Reality', value: 'vr' },
19858
19884
  { title: 'Augmented Reality', value: 'ar' },
19859
19885
  ],
19860
19886
  initial: 0,
19861
- },
19862
- ], { onCancel });
19887
+ }, { onCancel })
19888
+ : { mode: 'vr' };
19863
19889
  if (cancelled) {
19864
19890
  throw new Error('Input cancelled');
19865
19891
  }
19866
- const xrFeatureKeys = mode === 'vr'
19867
- ? ['handTracking', 'layers']
19868
- : [
19869
- 'handTracking',
19870
- 'anchors',
19871
- 'hitTest',
19872
- 'planeDetection',
19873
- 'meshDetection',
19874
- 'layers',
19875
- ];
19892
+ const xrFeatureKeys = !xrEnabled
19893
+ ? []
19894
+ : mode === 'vr'
19895
+ ? ['handTracking', 'layers']
19896
+ : [
19897
+ 'handTracking',
19898
+ 'anchors',
19899
+ 'hitTest',
19900
+ 'planeDetection',
19901
+ 'meshDetection',
19902
+ 'layers',
19903
+ ];
19876
19904
  const xrFeatureStates = {};
19877
19905
  for (const key of xrFeatureKeys) {
19878
19906
  const initial = mode === 'ar' ? 1 : key === 'handTracking' || key === 'layers' ? 1 : 0;
@@ -19913,7 +19941,7 @@ async function promptFlow(nameArg) {
19913
19941
  let locomotionUseWorker = undefined;
19914
19942
  let sceneUnderstandingEnabled = false;
19915
19943
  let environmentRaycastEnabled = false;
19916
- if (mode === 'vr') {
19944
+ if (xrEnabled && mode === 'vr') {
19917
19945
  // Locomotion (VR only)
19918
19946
  const ans = await prompts$1({
19919
19947
  type: 'toggle',
@@ -19944,7 +19972,7 @@ async function promptFlow(nameArg) {
19944
19972
  locomotionUseWorker = !!followUp.useWorker;
19945
19973
  }
19946
19974
  }
19947
- else {
19975
+ else if (xrEnabled) {
19948
19976
  // AR: Scene Understanding first (requires room scanning)
19949
19977
  const sceneAns = await prompts$1({
19950
19978
  type: 'toggle',
@@ -19972,17 +20000,20 @@ async function promptFlow(nameArg) {
19972
20000
  }
19973
20001
  environmentRaycastEnabled = !!raycastAns.environmentRaycastEnabled;
19974
20002
  }
19975
- // Grabbing (default: enabled)
19976
- const { grabbingEnabled } = await prompts$1({
19977
- type: 'toggle',
19978
- name: 'grabbingEnabled',
19979
- message: 'Enable grabbing (one/two-hand, distance)?',
19980
- initial: true,
19981
- active: 'Yes',
19982
- inactive: 'No',
19983
- }, { onCancel });
19984
- if (cancelled) {
19985
- throw new Error('Input cancelled');
20003
+ let grabbingEnabled = false;
20004
+ if (xrEnabled) {
20005
+ const grabbingAnswer = await prompts$1({
20006
+ type: 'toggle',
20007
+ name: 'grabbingEnabled',
20008
+ message: 'Enable grabbing (one/two-hand, distance)?',
20009
+ initial: true,
20010
+ active: 'Yes',
20011
+ inactive: 'No',
20012
+ }, { onCancel });
20013
+ if (cancelled) {
20014
+ throw new Error('Input cancelled');
20015
+ }
20016
+ grabbingEnabled = !!grabbingAnswer.grabbingEnabled;
19986
20017
  }
19987
20018
  // Physics (default: disabled)
19988
20019
  const { physicsEnabled } = await prompts$1({
@@ -20055,6 +20086,7 @@ async function promptFlow(nameArg) {
20055
20086
  id,
20056
20087
  installNow,
20057
20088
  metaspatial,
20089
+ xrEnabled,
20058
20090
  mode,
20059
20091
  language,
20060
20092
  features: [],
@@ -20404,8 +20436,8 @@ async function scaffoldProject(recipes, outDir) {
20404
20436
  }
20405
20437
  }
20406
20438
 
20407
- const VERSION = "0.3.1";
20408
- const NODE_ENGINE = ">=20.19.0";
20439
+ const VERSION = "0.4.0";
20440
+ const NODE_ENGINE = ">=20.19.0 <21.0.0-0 || >=22.12.0 <23.0.0-0 || >=24.0.0";
20409
20441
 
20410
20442
  /**
20411
20443
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -20455,6 +20487,10 @@ async function fetchRecipeByFileName(fileName, base = DEFAULT_ASSETS_BASE) {
20455
20487
  * references between packages (e.g., core → glxf) resolve correctly.
20456
20488
  */
20457
20489
  const SDK_PACKAGES_DIR = '.sdk-packages';
20490
+ /**
20491
+ * Default CDN URL for the canary SDK bundle.
20492
+ */
20493
+ const DEFAULT_BUNDLE_URL = 'https://d1erq8v22udnml.cloudfront.net/sdk-bundle';
20458
20494
  /**
20459
20495
  * Prepend a base URL to relative `url` edits in a recipe.
20460
20496
  * Absolute URLs pass through unchanged (backwards compatible).
@@ -20529,13 +20565,13 @@ class NpmSource {
20529
20565
  * Resolves @iwsdk/* packages to local file: paths after downloading tarballs.
20530
20566
  */
20531
20567
  class BundleSource {
20532
- constructor(fromFlag) {
20568
+ constructor(bundleUrl) {
20533
20569
  this.isBundleMode = true;
20534
20570
  this.manifest = null;
20535
- if (!fromFlag.startsWith('http://') && !fromFlag.startsWith('https://')) {
20536
- throw new Error(`--from must be an HTTP or HTTPS URL. Got: "${fromFlag}"`);
20571
+ if (!bundleUrl.startsWith('http://') && !bundleUrl.startsWith('https://')) {
20572
+ throw new Error(`Bundle URL must be an HTTP or HTTPS URL. Got: "${bundleUrl}"`);
20537
20573
  }
20538
- this.baseUrl = fromFlag;
20574
+ this.baseUrl = bundleUrl;
20539
20575
  }
20540
20576
  async prepare() {
20541
20577
  const manifestContent = await this.readContent('bundle.json');
@@ -20615,13 +20651,18 @@ class BundleSource {
20615
20651
  }
20616
20652
  }
20617
20653
  /**
20618
- * Factory: create the appropriate source based on the --from flag.
20654
+ * Factory: create the appropriate source based on the --canary flag.
20655
+ *
20656
+ * - `undefined` / `false` → NpmSource (default)
20657
+ * - `true` (bare --canary) → BundleSource with DEFAULT_BUNDLE_URL
20658
+ * - `string` → BundleSource with the provided URL
20619
20659
  */
20620
- function resolveSource(fromFlag) {
20621
- if (!fromFlag) {
20660
+ function resolveSource(canaryFlag) {
20661
+ if (!canaryFlag) {
20622
20662
  return new NpmSource();
20623
20663
  }
20624
- return new BundleSource(fromFlag);
20664
+ const url = typeof canaryFlag === 'string' ? canaryFlag : DEFAULT_BUNDLE_URL;
20665
+ return new BundleSource(url);
20625
20666
  }
20626
20667
 
20627
20668
  /**
@@ -20667,10 +20708,12 @@ IWSDK Create CLI v${VERSION}\nNode ${process.version}`;
20667
20708
  .description('Official CLI for creating Immersive Web SDK projects')
20668
20709
  .version(version)
20669
20710
  .argument('[name]', 'Project name')
20670
- .option('--from <url>', 'Use SDK bundle from HTTP(S) URL')
20711
+ .option('--canary [url]', 'Use canary SDK bundle (optionally from a custom URL)')
20671
20712
  .option('-y, --yes', 'Use defaults and skip prompts')
20672
20713
  .option('--mode <mode>', 'Experience mode: vr or ar', 'vr')
20673
20714
  .option('--language <lang>', 'Language: ts or js', 'ts')
20715
+ .option('--xr', 'Enable XR support', true)
20716
+ .option('--no-xr', 'Disable XR support for a browser-only 3D project')
20674
20717
  .option('--metaspatial', 'Use Meta Spatial Editor workflow', false)
20675
20718
  .option('--no-metaspatial', 'Use manual workflow (default)')
20676
20719
  .option('--install', 'Install dependencies after scaffolding', true)
@@ -20707,11 +20750,11 @@ IWSDK Create CLI v${VERSION}\nNode ${process.version}`;
20707
20750
  console.error(chalk.red(`Invalid --language "${cliOpts.language}". Must be "ts" or "js".`));
20708
20751
  process.exit(1);
20709
20752
  }
20710
- if (cliOpts.from) {
20711
- const isUrl = cliOpts.from.startsWith('http://') ||
20712
- cliOpts.from.startsWith('https://');
20753
+ if (typeof cliOpts.canary === 'string') {
20754
+ const isUrl = cliOpts.canary.startsWith('http://') ||
20755
+ cliOpts.canary.startsWith('https://');
20713
20756
  if (!isUrl) {
20714
- console.error(chalk.red(`--from must be an HTTP or HTTPS URL. Got: "${cliOpts.from}".`));
20757
+ console.error(chalk.red(`--canary URL must be an HTTP or HTTPS URL. Got: "${cliOpts.canary}".`));
20715
20758
  process.exit(1);
20716
20759
  }
20717
20760
  }
@@ -20747,6 +20790,7 @@ IWSDK Create CLI v${VERSION}\nNode ${process.version}`;
20747
20790
  if (cliOpts.yes) {
20748
20791
  const mode = (cliOpts.mode || 'vr');
20749
20792
  const language = (cliOpts.language || 'ts');
20793
+ const xrEnabled = cliOpts.xr ?? true;
20750
20794
  const metaspatial = cliOpts.metaspatial ?? false;
20751
20795
  // Meta Spatial Editor is only available as a GUI app on macOS/Windows.
20752
20796
  // The Linux CLI can build metaspatial projects but cannot author content.
@@ -20764,7 +20808,7 @@ IWSDK Create CLI v${VERSION}\nNode ${process.version}`;
20764
20808
  const aiTools = rawAiTools.includes('none')
20765
20809
  ? []
20766
20810
  : rawAiTools.filter((t) => validAiTools.includes(t));
20767
- const locomotionEnabled = mode === 'vr' ? (cliOpts.locomotion ?? true) : false;
20811
+ const locomotionEnabled = xrEnabled && mode === 'vr' ? (cliOpts.locomotion ?? true) : false;
20768
20812
  // MSE detection for scripted mode (no auto-install — requires TOS consent)
20769
20813
  let mseInstallResult;
20770
20814
  if (metaspatial) {
@@ -20794,41 +20838,49 @@ IWSDK Create CLI v${VERSION}\nNode ${process.version}`;
20794
20838
  id: variantId,
20795
20839
  installNow: cliOpts.install ?? true,
20796
20840
  metaspatial,
20841
+ xrEnabled,
20797
20842
  mode,
20798
20843
  language,
20799
20844
  features: [],
20800
20845
  featureFlags: {
20801
20846
  locomotionEnabled,
20802
20847
  locomotionUseWorker: locomotionEnabled ? true : undefined,
20803
- grabbingEnabled: cliOpts.grabbing ?? true,
20848
+ grabbingEnabled: xrEnabled ? (cliOpts.grabbing ?? true) : false,
20804
20849
  physicsEnabled: cliOpts.physics ?? false,
20805
- sceneUnderstandingEnabled: mode === 'ar' ? (cliOpts.sceneUnderstanding ?? true) : false,
20806
- environmentRaycastEnabled: mode === 'ar' ? (cliOpts.environmentRaycast ?? true) : false,
20850
+ sceneUnderstandingEnabled: xrEnabled && mode === 'ar'
20851
+ ? (cliOpts.sceneUnderstanding ?? true)
20852
+ : false,
20853
+ environmentRaycastEnabled: xrEnabled && mode === 'ar'
20854
+ ? (cliOpts.environmentRaycast ?? true)
20855
+ : false,
20807
20856
  },
20808
20857
  gitInit: cliOpts.git ?? true,
20809
20858
  aiTools,
20810
- xrFeatureStates: mode === 'ar'
20811
- ? {
20812
- handTracking: 'optional',
20813
- anchors: 'optional',
20814
- hitTest: 'optional',
20815
- planeDetection: 'optional',
20816
- meshDetection: 'optional',
20817
- layers: 'optional',
20818
- }
20819
- : { handTracking: 'optional', layers: 'optional' },
20859
+ xrFeatureStates: !xrEnabled
20860
+ ? {}
20861
+ : mode === 'ar'
20862
+ ? {
20863
+ handTracking: 'optional',
20864
+ anchors: 'optional',
20865
+ hitTest: 'optional',
20866
+ planeDetection: 'optional',
20867
+ meshDetection: 'optional',
20868
+ layers: 'optional',
20869
+ }
20870
+ : { handTracking: 'optional', layers: 'optional' },
20820
20871
  mseInstallResult,
20821
20872
  };
20822
20873
  }
20823
20874
  else {
20824
- res = await promptFlow(nameArg);
20875
+ const xrFlagProvided = process.argv.includes('--xr') || process.argv.includes('--no-xr');
20876
+ res = await promptFlow(nameArg, xrFlagProvided ? { xrEnabled: cliOpts.xr ?? true } : {});
20825
20877
  }
20826
20878
  // Validate project name (both interactive and non-interactive paths)
20827
20879
  if (!/^[a-zA-Z0-9._@-]+$/.test(res.name)) {
20828
20880
  throw new Error(`Invalid project name "${res.name}". ` +
20829
20881
  'Use only letters, numbers, hyphens, underscores, dots, and @.');
20830
20882
  }
20831
- const source = resolveSource(cliOpts.from);
20883
+ const source = resolveSource(cliOpts.canary);
20832
20884
  // Prepare source (downloads tgz files for remote bundles)
20833
20885
  if (source.isBundleMode) {
20834
20886
  const prepSpinner = ora({
@@ -20870,9 +20922,9 @@ IWSDK Create CLI v${VERSION}\nNode ${process.version}`;
20870
20922
  resolvedRecipe.edits['@appName'] = res.name;
20871
20923
  // World features (stringified JS object-literal expected by recipes)
20872
20924
  const ff = res.featureFlags || {
20873
- locomotionEnabled: res.mode === 'vr',
20925
+ locomotionEnabled: res.xrEnabled && res.mode === 'vr',
20874
20926
  locomotionUseWorker: true,
20875
- grabbingEnabled: true,
20927
+ grabbingEnabled: res.xrEnabled,
20876
20928
  physicsEnabled: false,
20877
20929
  sceneUnderstandingEnabled: false,
20878
20930
  environmentRaycastEnabled: false,
@@ -20882,8 +20934,12 @@ IWSDK Create CLI v${VERSION}\nNode ${process.version}`;
20882
20934
  ? '{ useWorker: true }'
20883
20935
  : 'true'
20884
20936
  : 'false';
20885
- const sceneUnderstandingLiteral = res.mode === 'ar' && ff.sceneUnderstandingEnabled ? 'true' : 'false';
20886
- const environmentRaycastLiteral = res.mode === 'ar' && ff.environmentRaycastEnabled ? 'true' : 'false';
20937
+ const sceneUnderstandingLiteral = res.xrEnabled && res.mode === 'ar' && ff.sceneUnderstandingEnabled
20938
+ ? 'true'
20939
+ : 'false';
20940
+ const environmentRaycastLiteral = res.xrEnabled && res.mode === 'ar' && ff.environmentRaycastEnabled
20941
+ ? 'true'
20942
+ : 'false';
20887
20943
  resolvedRecipe.edits['@appFeaturesStr'] =
20888
20944
  `{ locomotion: ${locomotionLiteral}, grabbing: ${ff.grabbingEnabled ? 'true' : 'false'}, physics: ${ff.physicsEnabled ? 'true' : 'false'}, sceneUnderstanding: ${sceneUnderstandingLiteral}, environmentRaycast: ${environmentRaycastLiteral} }`;
20889
20945
  // XR features (tri-state -> JS object literal)
@@ -20898,9 +20954,9 @@ IWSDK Create CLI v${VERSION}\nNode ${process.version}`;
20898
20954
  }
20899
20955
  const xrLiteral = `{ ${entries.join(', ')} }`;
20900
20956
  resolvedRecipe.edits['@xrFeaturesStr'] = xrLiteral;
20901
- // MCP tool selection for vite.config.ts
20902
- const mcpToolsLiteral = `[${res.aiTools.map((t) => `'${t}'`).join(', ')}]`;
20903
- resolvedRecipe.edits['@mcpToolsStr'] = mcpToolsLiteral;
20957
+ resolvedRecipe.edits['@xrConfigStr'] = res.xrEnabled
20958
+ ? `{ sessionMode: SessionMode.Immersive${res.mode === 'ar' ? 'AR' : 'VR'}, offer: 'always', features: ${xrLiteral} }`
20959
+ : 'false';
20904
20960
  const outDir = join(process.cwd(), res.name);
20905
20961
  // Check if target directory already exists and is non-empty
20906
20962
  if (fs$2.existsSync(outDir) && fs$2.readdirSync(outDir).length > 0) {
@@ -21006,6 +21062,21 @@ IWSDK Create CLI v${VERSION}\nNode ${process.version}`;
21006
21062
  await installDependencies(outDir);
21007
21063
  }
21008
21064
  }
21065
+ // Write MCP adapter configs for the selected AI tools
21066
+ if (res.installNow && res.aiTools.length > 0) {
21067
+ try {
21068
+ execFileSync(process.execPath, [
21069
+ join(outDir, 'node_modules/@iwsdk/cli/dist/cli.js'),
21070
+ 'adapter',
21071
+ 'sync',
21072
+ '--tools',
21073
+ res.aiTools.join(','),
21074
+ ], { cwd: outDir, stdio: 'ignore', timeout: 15000 });
21075
+ }
21076
+ catch {
21077
+ // Non-fatal: adapter sync failure shouldn't block project creation
21078
+ }
21079
+ }
21009
21080
  // Build prerequisites list (e.g., Meta Spatial Editor), including path-aware notes
21010
21081
  const prereqs = [...(res.prerequisites || [])];
21011
21082
  if (res.metaspatial) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iwsdk/create",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Interactive CLI to scaffold Immersive Web SDK starter apps",
5
5
  "type": "module",
6
6
  "private": false,
@@ -26,7 +26,7 @@
26
26
  "url": "git+https://github.com/facebook/immersive-web-sdk.git"
27
27
  },
28
28
  "engines": {
29
- "node": ">=20.19.0"
29
+ "node": ">=20.19.0 <21.0.0-0 || >=22.12.0 <23.0.0-0 || >=24.0.0"
30
30
  },
31
31
  "dependencies": {
32
32
  "@pmndrs/chef": "^0.1.9",