@iwsdk/create 0.4.2 → 0.5.1
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/README.md +103 -41
- package/dist/cli.js +1003 -3418
- package/dist/guidance/agents/.agents/skills/iwsdk-debug/SKILL.md +96 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-depth-occlusion/SKILL.md +135 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-grab/SKILL.md +129 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-physics/SKILL.md +92 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-physics/references/component-reference.md +154 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-physics/references/tuning-and-config.md +88 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-physics/references/workflows.md +303 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-planner/SKILL.md +364 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-planner/references/api-reference.md +1489 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-planner/references/build-milestones.md +241 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-planner/references/design-deck.md +101 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-planner/references/grounding.md +176 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-planner/references/ideation.md +156 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-planner/references/verification.md +199 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-ray/SKILL.md +159 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-scene-composer/SKILL.md +255 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-scene-composer/agents/openai.yaml +5 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-scene-composer/references/asset-authoring.md +295 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-scene-composer/references/composition-patterns.md +243 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-scene-composer/references/image-intake.md +191 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-scene-composer/references/review-and-stop.md +99 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-scene-composer/references/scene-format.md +458 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-scene-composer/references/text-intake.md +82 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-ui/SKILL.md +208 -0
- package/dist/guidance/claude/.claude/agents/iwsdk-project-code-reviewer.md +450 -0
- package/dist/guidance/claude/.claude/rules/assets-and-manifest.md +55 -0
- package/dist/guidance/claude/.claude/rules/ecs-api.md +102 -0
- package/dist/guidance/claude/.claude/rules/scene-json.md +64 -0
- package/dist/guidance/claude/.claude/rules/uikitml.md +60 -0
- package/dist/guidance/claude/.claude/settings.json +19 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-debug/SKILL.md +96 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-depth-occlusion/SKILL.md +135 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-grab/SKILL.md +129 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-physics/SKILL.md +92 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-physics/references/component-reference.md +154 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-physics/references/tuning-and-config.md +88 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-physics/references/workflows.md +303 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-planner/SKILL.md +364 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-planner/references/api-reference.md +1489 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-planner/references/build-milestones.md +241 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-planner/references/design-deck.md +101 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-planner/references/grounding.md +176 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-planner/references/ideation.md +156 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-planner/references/verification.md +199 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-ray/SKILL.md +159 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-scene-composer/SKILL.md +255 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-scene-composer/agents/openai.yaml +5 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-scene-composer/references/asset-authoring.md +295 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-scene-composer/references/composition-patterns.md +243 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-scene-composer/references/image-intake.md +191 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-scene-composer/references/review-and-stop.md +99 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-scene-composer/references/scene-format.md +458 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-scene-composer/references/text-intake.md +82 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-ui/SKILL.md +208 -0
- package/dist/guidance/claude/CLAUDE.md +142 -0
- package/dist/guidance/codex/.codex/config.toml +2 -0
- package/dist/guidance/common/AGENTS.md +151 -0
- package/dist/guidance/copilot/.github/instructions/assets-and-manifest.instructions.md +52 -0
- package/dist/guidance/copilot/.github/instructions/ecs-api.instructions.md +100 -0
- package/dist/guidance/copilot/.github/instructions/scene-json.instructions.md +63 -0
- package/dist/guidance/copilot/.github/instructions/uikitml.instructions.md +59 -0
- package/dist/guidance/cursor/.cursor/rules/assets-and-manifest.mdc +57 -0
- package/dist/guidance/cursor/.cursor/rules/ecs-api.mdc +104 -0
- package/dist/guidance/cursor/.cursor/rules/scene-json.mdc +66 -0
- package/dist/guidance/cursor/.cursor/rules/uikitml.mdc +62 -0
- package/dist/guidance/scoped-agents/public/scenes/AGENTS.md +63 -0
- package/dist/guidance/scoped-agents/public/ui/AGENTS.md +59 -0
- package/dist/guidance/scoped-agents/src/AGENTS.md +149 -0
- package/dist/template/common/README.md +13 -0
- package/dist/template/common/gitignore.template +45 -0
- package/dist/template/common/index.html +16 -0
- package/dist/template/common/nvmrc.template +1 -0
- package/dist/template/common/public/audio/chime.mp3 +0 -0
- package/dist/template/common/public/gltf/webxr-banner/banner.gltf +68 -0
- package/dist/template/common/public/textures/webxr.png +0 -0
- package/dist/template/common/public/ui/welcome.uikitml +98 -0
- package/dist/template/common/src/assets.ts +54 -0
- package/dist/template/common/src/components.ts +11 -0
- package/dist/template/common/src/index.ts +19 -0
- package/dist/template/common/src/panel.ts +38 -0
- package/dist/template/common/src/robot-component.ts +10 -0
- package/dist/template/common/src/robot.ts +38 -0
- package/dist/template/common/src/vite-env.d.ts +2 -0
- package/dist/template/common/tsconfig.json +15 -0
- package/dist/template/common/vite.config.ts +27 -0
- package/dist/template/common-js/README.md +13 -0
- package/dist/template/common-js/gitignore.template +45 -0
- package/dist/template/common-js/index.html +16 -0
- package/dist/template/common-js/nvmrc.template +1 -0
- package/dist/template/common-js/public/audio/chime.mp3 +0 -0
- package/dist/template/common-js/public/gltf/webxr-banner/banner.gltf +68 -0
- package/dist/template/common-js/public/textures/webxr.png +0 -0
- package/dist/template/common-js/public/ui/welcome.uikitml +98 -0
- package/dist/template/common-js/src/assets.js +45 -0
- package/dist/template/common-js/src/components.js +9 -0
- package/dist/template/common-js/src/index.js +14 -0
- package/dist/template/common-js/src/panel.js +31 -0
- package/dist/template/common-js/src/robot-component.js +8 -0
- package/dist/template/common-js/src/robot.js +37 -0
- package/dist/template/common-js/vite.config.js +25 -0
- package/dist/template/scenes/ar.iwsdk.scene.json +96 -0
- package/dist/template/scenes/immersive.iwsdk.scene.json +109 -0
- package/package.json +17 -12
- package/scripts/verify-release-ready.mjs +76 -0
package/dist/cli.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import require$$0$2, {
|
|
3
|
-
import fs$2 from 'fs';
|
|
4
|
-
import path$
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
2
|
+
import require$$0$2, { spawn as spawn$1, execFileSync } from 'child_process';
|
|
3
|
+
import fs$2, { constants as constants$2 } from 'fs';
|
|
4
|
+
import path$5, { dirname, join } from 'path';
|
|
5
|
+
import { fileURLToPath as fileURLToPath$1 } from 'url';
|
|
6
6
|
import require$$0$1 from 'node:events';
|
|
7
7
|
import require$$1 from 'node:child_process';
|
|
8
|
-
import
|
|
9
|
-
import require$$3 from 'node:fs';
|
|
8
|
+
import path$4 from 'node:path';
|
|
9
|
+
import require$$3, { existsSync } from 'node:fs';
|
|
10
10
|
import process$3 from 'node:process';
|
|
11
|
-
import
|
|
11
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
12
13
|
import require$$0$3 from 'readline';
|
|
13
|
-
import require$$2
|
|
14
|
-
import
|
|
15
|
-
import
|
|
14
|
+
import require$$2 from 'events';
|
|
15
|
+
import { randomUUID } from 'crypto';
|
|
16
|
+
import fsp from 'fs/promises';
|
|
16
17
|
|
|
17
18
|
const ANSI_BACKGROUND_OFFSET = 10;
|
|
18
19
|
|
|
@@ -1943,7 +1944,7 @@ suggestSimilar$2.suggestSimilar = suggestSimilar$1;
|
|
|
1943
1944
|
|
|
1944
1945
|
const EventEmitter = require$$0$1.EventEmitter;
|
|
1945
1946
|
const childProcess = require$$1;
|
|
1946
|
-
const path$3 =
|
|
1947
|
+
const path$3 = path$4;
|
|
1947
1948
|
const fs$1 = require$$3;
|
|
1948
1949
|
const process$2 = process$3;
|
|
1949
1950
|
|
|
@@ -7935,7 +7936,7 @@ const debug$1 = (
|
|
|
7935
7936
|
|
|
7936
7937
|
var debug_1 = debug$1;
|
|
7937
7938
|
|
|
7938
|
-
(function (module, exports
|
|
7939
|
+
(function (module, exports) {
|
|
7939
7940
|
|
|
7940
7941
|
const {
|
|
7941
7942
|
MAX_SAFE_COMPONENT_LENGTH,
|
|
@@ -7943,14 +7944,14 @@ var debug_1 = debug$1;
|
|
|
7943
7944
|
MAX_LENGTH,
|
|
7944
7945
|
} = constants$1;
|
|
7945
7946
|
const debug = debug_1;
|
|
7946
|
-
exports
|
|
7947
|
+
exports = module.exports = {};
|
|
7947
7948
|
|
|
7948
7949
|
// The actual regexps go on exports.re
|
|
7949
|
-
const re = exports
|
|
7950
|
-
const safeRe = exports
|
|
7951
|
-
const src = exports
|
|
7952
|
-
const safeSrc = exports
|
|
7953
|
-
const t = exports
|
|
7950
|
+
const re = exports.re = [];
|
|
7951
|
+
const safeRe = exports.safeRe = [];
|
|
7952
|
+
const src = exports.src = [];
|
|
7953
|
+
const safeSrc = exports.safeSrc = [];
|
|
7954
|
+
const t = exports.t = {};
|
|
7954
7955
|
let R = 0;
|
|
7955
7956
|
|
|
7956
7957
|
const LETTERDASHNUMBER = '[a-zA-Z0-9-]';
|
|
@@ -8114,7 +8115,7 @@ var debug_1 = debug$1;
|
|
|
8114
8115
|
createToken('LONETILDE', '(?:~>?)');
|
|
8115
8116
|
|
|
8116
8117
|
createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
|
|
8117
|
-
exports
|
|
8118
|
+
exports.tildeTrimReplace = '$1~';
|
|
8118
8119
|
|
|
8119
8120
|
createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
|
|
8120
8121
|
createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
@@ -8124,7 +8125,7 @@ var debug_1 = debug$1;
|
|
|
8124
8125
|
createToken('LONECARET', '(?:\\^)');
|
|
8125
8126
|
|
|
8126
8127
|
createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
|
|
8127
|
-
exports
|
|
8128
|
+
exports.caretTrimReplace = '$1^';
|
|
8128
8129
|
|
|
8129
8130
|
createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
|
|
8130
8131
|
createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
@@ -8137,7 +8138,7 @@ var debug_1 = debug$1;
|
|
|
8137
8138
|
// it modifies, so that `> 1.2.3` ==> `>1.2.3`
|
|
8138
8139
|
createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
|
|
8139
8140
|
}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
|
|
8140
|
-
exports
|
|
8141
|
+
exports.comparatorTrimReplace = '$1$2$3';
|
|
8141
8142
|
|
|
8142
8143
|
// Something like `1.2.3 - 1.2.4`
|
|
8143
8144
|
// Note that these all use the loose form, because they'll be
|
|
@@ -10233,6 +10234,215 @@ var semver = {
|
|
|
10233
10234
|
|
|
10234
10235
|
var semver$1 = /*@__PURE__*/getDefaultExportFromCjs(semver);
|
|
10235
10236
|
|
|
10237
|
+
/**
|
|
10238
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10239
|
+
*
|
|
10240
|
+
* This source code is licensed under the MIT license found in the
|
|
10241
|
+
* LICENSE file in the root directory of this source tree.
|
|
10242
|
+
*/
|
|
10243
|
+
const EXPERIENCE_TARGETS = {
|
|
10244
|
+
vr: {
|
|
10245
|
+
label: 'Virtual reality',
|
|
10246
|
+
description: 'Start inside an authored virtual environment.',
|
|
10247
|
+
xrEnabled: true,
|
|
10248
|
+
mode: 'vr',
|
|
10249
|
+
},
|
|
10250
|
+
ar: {
|
|
10251
|
+
label: 'Mixed reality / passthrough',
|
|
10252
|
+
description: 'Start with virtual content in the physical environment.',
|
|
10253
|
+
xrEnabled: true,
|
|
10254
|
+
mode: 'ar',
|
|
10255
|
+
},
|
|
10256
|
+
browser: {
|
|
10257
|
+
label: 'Desktop 3D',
|
|
10258
|
+
description: 'Start in a desktop browser without an immersive session.',
|
|
10259
|
+
xrEnabled: false,
|
|
10260
|
+
},
|
|
10261
|
+
};
|
|
10262
|
+
const FEATURE_CATALOG = {
|
|
10263
|
+
locomotionEnabled: {
|
|
10264
|
+
label: 'Locomotion',
|
|
10265
|
+
description: 'Let people move through a larger virtual environment.',
|
|
10266
|
+
targets: ['vr', 'browser'],
|
|
10267
|
+
defaults: { vr: true, browser: true },
|
|
10268
|
+
xrFeatures: [],
|
|
10269
|
+
selection: 'boolean',
|
|
10270
|
+
configPath: 'features.locomotion',
|
|
10271
|
+
documentation: 'docs/concepts/locomotion/index.md',
|
|
10272
|
+
reversible: 'Change features.locomotion in src/index.ts.',
|
|
10273
|
+
},
|
|
10274
|
+
locomotionUseWorker: {
|
|
10275
|
+
label: 'Locomotion worker',
|
|
10276
|
+
description: 'Run locomotion collision work off the main thread.',
|
|
10277
|
+
targets: ['vr', 'browser'],
|
|
10278
|
+
defaults: { vr: true, browser: true },
|
|
10279
|
+
xrFeatures: [],
|
|
10280
|
+
selection: 'boolean',
|
|
10281
|
+
configPath: 'features.locomotion.useWorker',
|
|
10282
|
+
documentation: 'docs/concepts/locomotion/performance.md',
|
|
10283
|
+
reversible: 'Change features.locomotion.useWorker in src/index.ts.',
|
|
10284
|
+
},
|
|
10285
|
+
locomotionBrowserControls: {
|
|
10286
|
+
label: 'Browser locomotion controls',
|
|
10287
|
+
description: 'Bind keyboard and browser gamepad movement actions.',
|
|
10288
|
+
targets: ['browser'],
|
|
10289
|
+
defaults: { browser: true },
|
|
10290
|
+
xrFeatures: [],
|
|
10291
|
+
selection: 'boolean',
|
|
10292
|
+
configPath: 'features.locomotion.browserControls',
|
|
10293
|
+
documentation: 'docs/guides/16-browser-first-systems.md',
|
|
10294
|
+
reversible: 'Change features.locomotion.browserControls in src/index.ts.',
|
|
10295
|
+
},
|
|
10296
|
+
grabbingEnabled: {
|
|
10297
|
+
label: 'Grabbing',
|
|
10298
|
+
description: 'Enable hand and controller object manipulation.',
|
|
10299
|
+
targets: ['vr', 'ar', 'browser'],
|
|
10300
|
+
defaults: { vr: true, ar: true, browser: true },
|
|
10301
|
+
xrFeatures: [],
|
|
10302
|
+
selection: 'boolean',
|
|
10303
|
+
configPath: 'features.grabbing',
|
|
10304
|
+
documentation: 'docs/concepts/grabbing/index.md',
|
|
10305
|
+
reversible: 'Change features.grabbing in src/index.ts.',
|
|
10306
|
+
},
|
|
10307
|
+
physicsEnabled: {
|
|
10308
|
+
label: 'Physics',
|
|
10309
|
+
description: 'Load Havok for gravity, collisions, and dynamic rigid bodies.',
|
|
10310
|
+
targets: ['vr', 'ar', 'browser'],
|
|
10311
|
+
defaults: { vr: false, ar: false, browser: false },
|
|
10312
|
+
xrFeatures: [],
|
|
10313
|
+
selection: 'boolean',
|
|
10314
|
+
configPath: 'features.physics',
|
|
10315
|
+
documentation: 'docs/guides/12-physics.md',
|
|
10316
|
+
reversible: 'Change features.physics in src/index.ts.',
|
|
10317
|
+
},
|
|
10318
|
+
sceneUnderstandingEnabled: {
|
|
10319
|
+
label: 'Room surfaces and anchors',
|
|
10320
|
+
description: 'Use scanned planes, meshes, and anchors in mixed reality.',
|
|
10321
|
+
targets: ['ar'],
|
|
10322
|
+
defaults: { ar: false },
|
|
10323
|
+
xrFeatures: ['anchors', 'planeDetection', 'meshDetection'],
|
|
10324
|
+
selection: 'boolean',
|
|
10325
|
+
configPath: 'features.sceneUnderstanding',
|
|
10326
|
+
documentation: 'docs/guides/11-scene-understanding.md',
|
|
10327
|
+
reversible: 'Change features.sceneUnderstanding in src/index.ts.',
|
|
10328
|
+
},
|
|
10329
|
+
environmentRaycastEnabled: {
|
|
10330
|
+
label: 'Real-world placement',
|
|
10331
|
+
description: 'Use WebXR hit testing to place content on physical surfaces.',
|
|
10332
|
+
targets: ['ar'],
|
|
10333
|
+
defaults: { ar: false },
|
|
10334
|
+
xrFeatures: ['hitTest'],
|
|
10335
|
+
selection: 'boolean',
|
|
10336
|
+
configPath: 'features.environmentRaycast',
|
|
10337
|
+
documentation: 'docs/guides/14-environment-raycast.md',
|
|
10338
|
+
reversible: 'Change features.environmentRaycast in src/index.ts.',
|
|
10339
|
+
},
|
|
10340
|
+
};
|
|
10341
|
+
function deriveXRFeatureStates(target, features) {
|
|
10342
|
+
if (target === 'browser') {
|
|
10343
|
+
return {};
|
|
10344
|
+
}
|
|
10345
|
+
const states = { handTracking: 'optional' };
|
|
10346
|
+
for (const key of Object.keys(FEATURE_CATALOG)) {
|
|
10347
|
+
const definition = FEATURE_CATALOG[key];
|
|
10348
|
+
if (!features[key] ||
|
|
10349
|
+
!definition.targets.includes(target)) {
|
|
10350
|
+
continue;
|
|
10351
|
+
}
|
|
10352
|
+
for (const xrFeature of definition.xrFeatures) {
|
|
10353
|
+
states[xrFeature] = 'optional';
|
|
10354
|
+
}
|
|
10355
|
+
}
|
|
10356
|
+
return states;
|
|
10357
|
+
}
|
|
10358
|
+
function getRecommendedConfiguration(target, overrides = {}) {
|
|
10359
|
+
const definition = EXPERIENCE_TARGETS[target];
|
|
10360
|
+
const features = {};
|
|
10361
|
+
const mutableFeatures = features;
|
|
10362
|
+
for (const key of Object.keys(FEATURE_CATALOG)) {
|
|
10363
|
+
mutableFeatures[key] =
|
|
10364
|
+
FEATURE_CATALOG[key].defaults[target] ?? false;
|
|
10365
|
+
}
|
|
10366
|
+
Object.assign(features, overrides);
|
|
10367
|
+
if (target !== 'vr') {
|
|
10368
|
+
if (target === 'ar') {
|
|
10369
|
+
features.locomotionEnabled = false;
|
|
10370
|
+
features.locomotionUseWorker = undefined;
|
|
10371
|
+
features.locomotionBrowserControls = false;
|
|
10372
|
+
}
|
|
10373
|
+
}
|
|
10374
|
+
else if (features.locomotionEnabled) {
|
|
10375
|
+
features.locomotionUseWorker ??= true;
|
|
10376
|
+
features.locomotionBrowserControls = false;
|
|
10377
|
+
}
|
|
10378
|
+
else {
|
|
10379
|
+
features.locomotionUseWorker = undefined;
|
|
10380
|
+
features.locomotionBrowserControls = false;
|
|
10381
|
+
}
|
|
10382
|
+
if (target === 'browser') {
|
|
10383
|
+
features.sceneUnderstandingEnabled = false;
|
|
10384
|
+
features.environmentRaycastEnabled = false;
|
|
10385
|
+
if (features.locomotionEnabled) {
|
|
10386
|
+
features.locomotionUseWorker ??= true;
|
|
10387
|
+
features.locomotionBrowserControls ??= true;
|
|
10388
|
+
}
|
|
10389
|
+
else {
|
|
10390
|
+
features.locomotionUseWorker = undefined;
|
|
10391
|
+
features.locomotionBrowserControls = false;
|
|
10392
|
+
}
|
|
10393
|
+
}
|
|
10394
|
+
else if (target === 'vr') {
|
|
10395
|
+
features.sceneUnderstandingEnabled = false;
|
|
10396
|
+
features.environmentRaycastEnabled = false;
|
|
10397
|
+
}
|
|
10398
|
+
return {
|
|
10399
|
+
target,
|
|
10400
|
+
xrEnabled: definition.xrEnabled,
|
|
10401
|
+
mode: target === 'browser' ? undefined : target,
|
|
10402
|
+
featureFlags: features,
|
|
10403
|
+
xrFeatureStates: deriveXRFeatureStates(target, features),
|
|
10404
|
+
};
|
|
10405
|
+
}
|
|
10406
|
+
|
|
10407
|
+
/**
|
|
10408
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10409
|
+
*
|
|
10410
|
+
* This source code is licensed under the MIT license found in the
|
|
10411
|
+
* LICENSE file in the root directory of this source tree.
|
|
10412
|
+
*/
|
|
10413
|
+
const FEATURE_OPTIONS = [
|
|
10414
|
+
{
|
|
10415
|
+
key: 'locomotionEnabled',
|
|
10416
|
+
options: ['--locomotion', '--no-locomotion'],
|
|
10417
|
+
},
|
|
10418
|
+
{ key: 'grabbingEnabled', options: ['--grabbing', '--no-grabbing'] },
|
|
10419
|
+
{ key: 'physicsEnabled', options: ['--physics', '--no-physics'] },
|
|
10420
|
+
{
|
|
10421
|
+
key: 'sceneUnderstandingEnabled',
|
|
10422
|
+
options: ['--scene-understanding', '--no-scene-understanding'],
|
|
10423
|
+
},
|
|
10424
|
+
{
|
|
10425
|
+
key: 'environmentRaycastEnabled',
|
|
10426
|
+
options: ['--environment-raycast', '--no-environment-raycast'],
|
|
10427
|
+
},
|
|
10428
|
+
];
|
|
10429
|
+
function hasCliOption(args, option) {
|
|
10430
|
+
return args.some((argument) => argument === option || argument.startsWith(`${option}=`));
|
|
10431
|
+
}
|
|
10432
|
+
function validateFeatureOptionsForTarget(target, args) {
|
|
10433
|
+
for (const definition of FEATURE_OPTIONS) {
|
|
10434
|
+
const option = definition.options.find((candidate) => hasCliOption(args, candidate));
|
|
10435
|
+
if (option === undefined) {
|
|
10436
|
+
continue;
|
|
10437
|
+
}
|
|
10438
|
+
const supportedTargets = FEATURE_CATALOG[definition.key].targets;
|
|
10439
|
+
if (!supportedTargets.includes(target)) {
|
|
10440
|
+
throw new Error(`${option} is not available for --target ${target}. ` +
|
|
10441
|
+
`Supported targets: ${supportedTargets.join(', ')}.`);
|
|
10442
|
+
}
|
|
10443
|
+
}
|
|
10444
|
+
}
|
|
10445
|
+
|
|
10236
10446
|
var crossSpawn = {exports: {}};
|
|
10237
10447
|
|
|
10238
10448
|
var windows;
|
|
@@ -10397,7 +10607,7 @@ const isWindows = process.platform === 'win32' ||
|
|
|
10397
10607
|
process.env.OSTYPE === 'cygwin' ||
|
|
10398
10608
|
process.env.OSTYPE === 'msys';
|
|
10399
10609
|
|
|
10400
|
-
const path$2 = path$
|
|
10610
|
+
const path$2 = path$5;
|
|
10401
10611
|
const COLON = isWindows ? ';' : ':';
|
|
10402
10612
|
const isexe = isexe_1;
|
|
10403
10613
|
|
|
@@ -10538,7 +10748,7 @@ pathKey$1.exports.default = pathKey;
|
|
|
10538
10748
|
|
|
10539
10749
|
var pathKeyExports = pathKey$1.exports;
|
|
10540
10750
|
|
|
10541
|
-
const path$1 = path$
|
|
10751
|
+
const path$1 = path$5;
|
|
10542
10752
|
const which = which_1;
|
|
10543
10753
|
const getPathKey = pathKeyExports;
|
|
10544
10754
|
|
|
@@ -10680,7 +10890,7 @@ function readShebang$1(command) {
|
|
|
10680
10890
|
|
|
10681
10891
|
var readShebang_1 = readShebang$1;
|
|
10682
10892
|
|
|
10683
|
-
const path = path$
|
|
10893
|
+
const path = path$5;
|
|
10684
10894
|
const resolveCommand = resolveCommand_1;
|
|
10685
10895
|
const escape = _escape;
|
|
10686
10896
|
const readShebang = readShebang_1;
|
|
@@ -10913,7 +11123,7 @@ async function installDependencies(outDir) {
|
|
|
10913
11123
|
* reproducible as long as the .sdk-packages/ directory is present.
|
|
10914
11124
|
*/
|
|
10915
11125
|
async function installDependenciesFromBundle(outDir, source) {
|
|
10916
|
-
const pkgPath = path$
|
|
11126
|
+
const pkgPath = path$5.join(outDir, 'package.json');
|
|
10917
11127
|
const installSpinner = ora({
|
|
10918
11128
|
text: 'Installing dependencies from bundle ...',
|
|
10919
11129
|
stream: process.stderr,
|
|
@@ -10924,6 +11134,7 @@ async function installDependenciesFromBundle(outDir, source) {
|
|
|
10924
11134
|
try {
|
|
10925
11135
|
// Rewrite @iwsdk/* deps to file: paths in both dependencies and devDependencies
|
|
10926
11136
|
const pkg = JSON.parse(fs$2.readFileSync(pkgPath, 'utf-8'));
|
|
11137
|
+
const directDependencyNames = new Set();
|
|
10927
11138
|
for (const depsKey of ['dependencies', 'devDependencies']) {
|
|
10928
11139
|
const deps = pkg[depsKey];
|
|
10929
11140
|
if (!deps) {
|
|
@@ -10931,6 +11142,7 @@ async function installDependenciesFromBundle(outDir, source) {
|
|
|
10931
11142
|
}
|
|
10932
11143
|
for (const name of Object.keys(deps)) {
|
|
10933
11144
|
if (name.startsWith('@iwsdk/')) {
|
|
11145
|
+
directDependencyNames.add(name);
|
|
10934
11146
|
const spec = source.getPackageInstallSpec(name);
|
|
10935
11147
|
if (spec) {
|
|
10936
11148
|
deps[name] = spec;
|
|
@@ -10938,6 +11150,24 @@ async function installDependenciesFromBundle(outDir, source) {
|
|
|
10938
11150
|
}
|
|
10939
11151
|
}
|
|
10940
11152
|
}
|
|
11153
|
+
const allPackageSpecs = source.getPackageInstallSpecs();
|
|
11154
|
+
const bundleOverrides = {};
|
|
11155
|
+
for (const [name, spec] of Object.entries(allPackageSpecs)) {
|
|
11156
|
+
if (!directDependencyNames.has(name)) {
|
|
11157
|
+
bundleOverrides[name] = spec;
|
|
11158
|
+
}
|
|
11159
|
+
}
|
|
11160
|
+
if (Object.keys(bundleOverrides).length > 0) {
|
|
11161
|
+
const existingOverrides = pkg.overrides != null &&
|
|
11162
|
+
typeof pkg.overrides === 'object' &&
|
|
11163
|
+
!Array.isArray(pkg.overrides)
|
|
11164
|
+
? pkg.overrides
|
|
11165
|
+
: {};
|
|
11166
|
+
pkg.overrides = {
|
|
11167
|
+
...existingOverrides,
|
|
11168
|
+
...bundleOverrides,
|
|
11169
|
+
};
|
|
11170
|
+
}
|
|
10941
11171
|
fs$2.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
10942
11172
|
// Run npm install
|
|
10943
11173
|
const child = spawn_1('npm', ['install'], {
|
|
@@ -10960,13 +11190,47 @@ async function installDependenciesFromBundle(outDir, source) {
|
|
|
10960
11190
|
throw e;
|
|
10961
11191
|
}
|
|
10962
11192
|
}
|
|
11193
|
+
/** Initialize the shared reference corpus/model cache after dependencies exist. */
|
|
11194
|
+
async function warmupReference(outDir) {
|
|
11195
|
+
const spinner = ora({
|
|
11196
|
+
text: 'Initializing IWSDK reference tools (one-time shared download) ...',
|
|
11197
|
+
stream: process.stderr,
|
|
11198
|
+
discardStdin: false,
|
|
11199
|
+
hideCursor: false,
|
|
11200
|
+
isEnabled: process.stderr.isTTY,
|
|
11201
|
+
}).start();
|
|
11202
|
+
const cliEntrypoint = path$5.join(outDir, 'node_modules', '@iwsdk', 'cli', 'dist', 'cli.js');
|
|
11203
|
+
try {
|
|
11204
|
+
const child = spawn_1(process.execPath, [cliEntrypoint, 'reference', 'warmup'], {
|
|
11205
|
+
cwd: outDir,
|
|
11206
|
+
stdio: 'inherit',
|
|
11207
|
+
});
|
|
11208
|
+
await new Promise((resolve, reject) => {
|
|
11209
|
+
child.on('error', reject);
|
|
11210
|
+
child.on('exit', (code) => code === 0
|
|
11211
|
+
? resolve()
|
|
11212
|
+
: reject(new Error(`Reference initialization failed (${code})`)));
|
|
11213
|
+
});
|
|
11214
|
+
spinner.stopAndPersist({
|
|
11215
|
+
symbol: stderrColor.green('✔'),
|
|
11216
|
+
text: 'IWSDK reference tools ready',
|
|
11217
|
+
});
|
|
11218
|
+
}
|
|
11219
|
+
catch (error) {
|
|
11220
|
+
spinner.stopAndPersist({
|
|
11221
|
+
symbol: stderrColor.red('✖'),
|
|
11222
|
+
text: 'IWSDK reference initialization failed',
|
|
11223
|
+
});
|
|
11224
|
+
throw error;
|
|
11225
|
+
}
|
|
11226
|
+
}
|
|
10963
11227
|
function printReferenceWarmupGuidance() {
|
|
10964
11228
|
console.log(stdoutColor.gray(' # @iwsdk/reference downloads its pinned model automatically during warmup'));
|
|
10965
11229
|
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
11230
|
console.log(stdoutColor.gray(' # warmup still needs access to the baked public model file URLs unless the shared cache is already pre-warmed'));
|
|
10967
11231
|
console.log(stdoutColor.gray(' # then run: npx iwsdk reference warmup'));
|
|
10968
11232
|
}
|
|
10969
|
-
function printNextSteps(appName, installed, actionItems = []) {
|
|
11233
|
+
function printNextSteps(appName, installed, actionItems = [], inPlace = false, referenceReady = false) {
|
|
10970
11234
|
const startCmd = 'npm run dev';
|
|
10971
11235
|
console.log('\nNext steps:');
|
|
10972
11236
|
// Choose the best stream for colored action items
|
|
@@ -10985,11 +11249,15 @@ function printNextSteps(appName, installed, actionItems = []) {
|
|
|
10985
11249
|
itemStream.write(`${itemColor.bold.yellow(prefix)} ${item.message}\n`);
|
|
10986
11250
|
}
|
|
10987
11251
|
// Commands go to stdout
|
|
10988
|
-
|
|
11252
|
+
if (!inPlace) {
|
|
11253
|
+
console.log(stdoutColor.gray(` cd ${appName}`));
|
|
11254
|
+
}
|
|
10989
11255
|
if (!installed) {
|
|
10990
11256
|
console.log(stdoutColor.gray(' npm install'));
|
|
10991
11257
|
}
|
|
10992
|
-
|
|
11258
|
+
if (!referenceReady) {
|
|
11259
|
+
printReferenceWarmupGuidance();
|
|
11260
|
+
}
|
|
10993
11261
|
console.log(stdoutColor.gray(` ${startCmd}`));
|
|
10994
11262
|
}
|
|
10995
11263
|
function printPrerequisites(prereqs = []) {
|
|
@@ -11034,2113 +11302,273 @@ function printPrerequisites(prereqs = []) {
|
|
|
11034
11302
|
* This source code is licensed under the MIT license found in the
|
|
11035
11303
|
* LICENSE file in the root directory of this source tree.
|
|
11036
11304
|
*/
|
|
11037
|
-
|
|
11038
|
-
|
|
11039
|
-
/** App names in TEDI registry (internally called "Cosmo Studio") */
|
|
11040
|
-
const MSE_APP_NAMES = {
|
|
11041
|
-
darwin: 'cosmo_studio_for_macos',
|
|
11042
|
-
win32: 'cosmo_studio_for_windows',
|
|
11043
|
-
linux: 'cosmo_studio_cli_for_linux',
|
|
11044
|
-
};
|
|
11045
|
-
/** Release channel: 'production', 'alpha', 'beta', 'experimental' */
|
|
11046
|
-
const MSE_RELEASE_CHANNEL = process.env.IWSDK_MSE_CHANNEL || 'production';
|
|
11047
|
-
function getAppcastUrl(platform) {
|
|
11048
|
-
const appName = MSE_APP_NAMES[platform];
|
|
11049
|
-
return `${MSE_APPCAST_BASE}/${appName}/${MSE_RELEASE_CHANNEL}/appcast.xml`;
|
|
11305
|
+
function featureFlag(state) {
|
|
11306
|
+
return state === 'required' ? { required: true } : state === 'optional';
|
|
11050
11307
|
}
|
|
11051
|
-
/**
|
|
11052
|
-
|
|
11053
|
-
|
|
11054
|
-
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
|
|
11058
|
-
const
|
|
11059
|
-
|
|
11060
|
-
|
|
11061
|
-
|
|
11062
|
-
|
|
11063
|
-
|
|
11064
|
-
|
|
11065
|
-
|
|
11066
|
-
|
|
11067
|
-
|
|
11068
|
-
and acknowledge you've read:
|
|
11069
|
-
|
|
11070
|
-
3. The Supplemental Privacy Policy
|
|
11071
|
-
https://www.meta.com/legal/privacy-policy/
|
|
11072
|
-
`;
|
|
11073
|
-
/** Installation paths by platform */
|
|
11074
|
-
const MSE_INSTALL_PATHS = {
|
|
11075
|
-
darwin: '/Applications/Meta Spatial Editor.app',
|
|
11076
|
-
win32: 'C:\\Program Files\\Meta Spatial Editor',
|
|
11077
|
-
linux: `${process.env.HOME}/.local/lib/meta-spatial-editor-cli`,
|
|
11078
|
-
};
|
|
11079
|
-
const MSE_LINUX_CLI_NAME = 'MetaSpatialEditorCLI';
|
|
11080
|
-
|
|
11081
|
-
var validator$2 = {};
|
|
11082
|
-
|
|
11083
|
-
var util$5 = {};
|
|
11084
|
-
|
|
11085
|
-
(function (exports$1) {
|
|
11086
|
-
|
|
11087
|
-
const nameStartChar = ':A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD';
|
|
11088
|
-
const nameChar = nameStartChar + '\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040';
|
|
11089
|
-
const nameRegexp = '[' + nameStartChar + '][' + nameChar + ']*';
|
|
11090
|
-
const regexName = new RegExp('^' + nameRegexp + '$');
|
|
11091
|
-
|
|
11092
|
-
const getAllMatches = function(string, regex) {
|
|
11093
|
-
const matches = [];
|
|
11094
|
-
let match = regex.exec(string);
|
|
11095
|
-
while (match) {
|
|
11096
|
-
const allmatches = [];
|
|
11097
|
-
allmatches.startIndex = regex.lastIndex - match[0].length;
|
|
11098
|
-
const len = match.length;
|
|
11099
|
-
for (let index = 0; index < len; index++) {
|
|
11100
|
-
allmatches.push(match[index]);
|
|
11101
|
-
}
|
|
11102
|
-
matches.push(allmatches);
|
|
11103
|
-
match = regex.exec(string);
|
|
11104
|
-
}
|
|
11105
|
-
return matches;
|
|
11106
|
-
};
|
|
11107
|
-
|
|
11108
|
-
const isName = function(string) {
|
|
11109
|
-
const match = regexName.exec(string);
|
|
11110
|
-
return !(match === null || typeof match === 'undefined');
|
|
11111
|
-
};
|
|
11112
|
-
|
|
11113
|
-
exports$1.isExist = function(v) {
|
|
11114
|
-
return typeof v !== 'undefined';
|
|
11115
|
-
};
|
|
11116
|
-
|
|
11117
|
-
exports$1.isEmptyObject = function(obj) {
|
|
11118
|
-
return Object.keys(obj).length === 0;
|
|
11119
|
-
};
|
|
11120
|
-
|
|
11121
|
-
/**
|
|
11122
|
-
* Copy all the properties of a into b.
|
|
11123
|
-
* @param {*} target
|
|
11124
|
-
* @param {*} a
|
|
11125
|
-
*/
|
|
11126
|
-
exports$1.merge = function(target, a, arrayMode) {
|
|
11127
|
-
if (a) {
|
|
11128
|
-
const keys = Object.keys(a); // will return an array of own properties
|
|
11129
|
-
const len = keys.length; //don't make it inline
|
|
11130
|
-
for (let i = 0; i < len; i++) {
|
|
11131
|
-
if (arrayMode === 'strict') {
|
|
11132
|
-
target[keys[i]] = [ a[keys[i]] ];
|
|
11133
|
-
} else {
|
|
11134
|
-
target[keys[i]] = a[keys[i]];
|
|
11135
|
-
}
|
|
11136
|
-
}
|
|
11137
|
-
}
|
|
11138
|
-
};
|
|
11139
|
-
/* exports.merge =function (b,a){
|
|
11140
|
-
return Object.assign(b,a);
|
|
11141
|
-
} */
|
|
11142
|
-
|
|
11143
|
-
exports$1.getValue = function(v) {
|
|
11144
|
-
if (exports$1.isExist(v)) {
|
|
11145
|
-
return v;
|
|
11146
|
-
} else {
|
|
11147
|
-
return '';
|
|
11148
|
-
}
|
|
11149
|
-
};
|
|
11150
|
-
|
|
11151
|
-
// const fakeCall = function(a) {return a;};
|
|
11152
|
-
// const fakeCallNoReturn = function() {};
|
|
11153
|
-
|
|
11154
|
-
exports$1.isName = isName;
|
|
11155
|
-
exports$1.getAllMatches = getAllMatches;
|
|
11156
|
-
exports$1.nameRegexp = nameRegexp;
|
|
11157
|
-
} (util$5));
|
|
11158
|
-
|
|
11159
|
-
const util$4 = util$5;
|
|
11160
|
-
|
|
11161
|
-
const defaultOptions$2 = {
|
|
11162
|
-
allowBooleanAttributes: false, //A tag can have attributes without any value
|
|
11163
|
-
unpairedTags: []
|
|
11164
|
-
};
|
|
11165
|
-
|
|
11166
|
-
//const tagsPattern = new RegExp("<\\/?([\\w:\\-_\.]+)\\s*\/?>","g");
|
|
11167
|
-
validator$2.validate = function (xmlData, options) {
|
|
11168
|
-
options = Object.assign({}, defaultOptions$2, options);
|
|
11169
|
-
|
|
11170
|
-
//xmlData = xmlData.replace(/(\r\n|\n|\r)/gm,"");//make it single line
|
|
11171
|
-
//xmlData = xmlData.replace(/(^\s*<\?xml.*?\?>)/g,"");//Remove XML starting tag
|
|
11172
|
-
//xmlData = xmlData.replace(/(<!DOCTYPE[\s\w\"\.\/\-\:]+(\[.*\])*\s*>)/g,"");//Remove DOCTYPE
|
|
11173
|
-
const tags = [];
|
|
11174
|
-
let tagFound = false;
|
|
11175
|
-
|
|
11176
|
-
//indicates that the root tag has been closed (aka. depth 0 has been reached)
|
|
11177
|
-
let reachedRoot = false;
|
|
11178
|
-
|
|
11179
|
-
if (xmlData[0] === '\ufeff') {
|
|
11180
|
-
// check for byte order mark (BOM)
|
|
11181
|
-
xmlData = xmlData.substr(1);
|
|
11182
|
-
}
|
|
11183
|
-
|
|
11184
|
-
for (let i = 0; i < xmlData.length; i++) {
|
|
11185
|
-
|
|
11186
|
-
if (xmlData[i] === '<' && xmlData[i+1] === '?') {
|
|
11187
|
-
i+=2;
|
|
11188
|
-
i = readPI(xmlData,i);
|
|
11189
|
-
if (i.err) return i;
|
|
11190
|
-
}else if (xmlData[i] === '<') {
|
|
11191
|
-
//starting of tag
|
|
11192
|
-
//read until you reach to '>' avoiding any '>' in attribute value
|
|
11193
|
-
let tagStartPos = i;
|
|
11194
|
-
i++;
|
|
11195
|
-
|
|
11196
|
-
if (xmlData[i] === '!') {
|
|
11197
|
-
i = readCommentAndCDATA(xmlData, i);
|
|
11198
|
-
continue;
|
|
11199
|
-
} else {
|
|
11200
|
-
let closingTag = false;
|
|
11201
|
-
if (xmlData[i] === '/') {
|
|
11202
|
-
//closing tag
|
|
11203
|
-
closingTag = true;
|
|
11204
|
-
i++;
|
|
11205
|
-
}
|
|
11206
|
-
//read tagname
|
|
11207
|
-
let tagName = '';
|
|
11208
|
-
for (; i < xmlData.length &&
|
|
11209
|
-
xmlData[i] !== '>' &&
|
|
11210
|
-
xmlData[i] !== ' ' &&
|
|
11211
|
-
xmlData[i] !== '\t' &&
|
|
11212
|
-
xmlData[i] !== '\n' &&
|
|
11213
|
-
xmlData[i] !== '\r'; i++
|
|
11214
|
-
) {
|
|
11215
|
-
tagName += xmlData[i];
|
|
11216
|
-
}
|
|
11217
|
-
tagName = tagName.trim();
|
|
11218
|
-
//console.log(tagName);
|
|
11219
|
-
|
|
11220
|
-
if (tagName[tagName.length - 1] === '/') {
|
|
11221
|
-
//self closing tag without attributes
|
|
11222
|
-
tagName = tagName.substring(0, tagName.length - 1);
|
|
11223
|
-
//continue;
|
|
11224
|
-
i--;
|
|
11225
|
-
}
|
|
11226
|
-
if (!validateTagName(tagName)) {
|
|
11227
|
-
let msg;
|
|
11228
|
-
if (tagName.trim().length === 0) {
|
|
11229
|
-
msg = "Invalid space after '<'.";
|
|
11230
|
-
} else {
|
|
11231
|
-
msg = "Tag '"+tagName+"' is an invalid name.";
|
|
11232
|
-
}
|
|
11233
|
-
return getErrorObject('InvalidTag', msg, getLineNumberForPosition(xmlData, i));
|
|
11234
|
-
}
|
|
11235
|
-
|
|
11236
|
-
const result = readAttributeStr(xmlData, i);
|
|
11237
|
-
if (result === false) {
|
|
11238
|
-
return getErrorObject('InvalidAttr', "Attributes for '"+tagName+"' have open quote.", getLineNumberForPosition(xmlData, i));
|
|
11308
|
+
/** Build the committed, JSON-safe authority for one starter target. */
|
|
11309
|
+
function createProjectManifest(configuration) {
|
|
11310
|
+
const { featureFlags, target, xrFeatureStates } = configuration;
|
|
11311
|
+
const xrFeatures = Object.fromEntries(Object.entries(xrFeatureStates).map(([name, state]) => [
|
|
11312
|
+
name,
|
|
11313
|
+
featureFlag(state),
|
|
11314
|
+
]));
|
|
11315
|
+
const locomotion = featureFlags.locomotionEnabled
|
|
11316
|
+
? {
|
|
11317
|
+
useWorker: featureFlags.locomotionUseWorker !== false,
|
|
11318
|
+
...(target === 'browser'
|
|
11319
|
+
? { initialPlayerPosition: [-4, 0, -6] }
|
|
11320
|
+
: {}),
|
|
11321
|
+
...(featureFlags.locomotionBrowserControls
|
|
11322
|
+
? { browserControls: true }
|
|
11323
|
+
: {}),
|
|
11239
11324
|
}
|
|
11240
|
-
|
|
11241
|
-
|
|
11242
|
-
|
|
11243
|
-
|
|
11244
|
-
|
|
11245
|
-
|
|
11246
|
-
|
|
11247
|
-
|
|
11248
|
-
|
|
11249
|
-
|
|
11250
|
-
|
|
11251
|
-
|
|
11252
|
-
|
|
11253
|
-
|
|
11254
|
-
|
|
11255
|
-
|
|
11256
|
-
|
|
11257
|
-
|
|
11258
|
-
|
|
11259
|
-
|
|
11260
|
-
|
|
11261
|
-
|
|
11262
|
-
|
|
11263
|
-
|
|
11264
|
-
|
|
11265
|
-
|
|
11266
|
-
|
|
11267
|
-
|
|
11268
|
-
|
|
11269
|
-
|
|
11270
|
-
|
|
11271
|
-
|
|
11325
|
+
: false;
|
|
11326
|
+
return {
|
|
11327
|
+
$schema: './node_modules/@iwsdk/core/dist/schemas/iwsdk-project.v1.schema.json',
|
|
11328
|
+
version: 'iwsdk.project.v1',
|
|
11329
|
+
scene: './public/scenes/main.iwsdk.scene.json',
|
|
11330
|
+
assets: { module: './src/assets' },
|
|
11331
|
+
components: { module: './src/components' },
|
|
11332
|
+
world: {
|
|
11333
|
+
xr: target === 'browser'
|
|
11334
|
+
? false
|
|
11335
|
+
: {
|
|
11336
|
+
mode: target,
|
|
11337
|
+
offer: 'always',
|
|
11338
|
+
features: xrFeatures,
|
|
11339
|
+
},
|
|
11340
|
+
input: { canvasPointerEvents: true },
|
|
11341
|
+
render: {
|
|
11342
|
+
near: 0.001,
|
|
11343
|
+
far: 200,
|
|
11344
|
+
camera: target === 'browser'
|
|
11345
|
+
? {
|
|
11346
|
+
position: [0, 1.5, 0],
|
|
11347
|
+
lookAt: [4, 1.1, 4.2],
|
|
11348
|
+
}
|
|
11349
|
+
: target === 'ar'
|
|
11350
|
+
? { position: [0, 1, 0.5] }
|
|
11351
|
+
: {
|
|
11352
|
+
position: [-4, 1.5, -6],
|
|
11353
|
+
lookAt: [0, 1.1, -1.8],
|
|
11354
|
+
},
|
|
11355
|
+
},
|
|
11356
|
+
features: {
|
|
11357
|
+
locomotion,
|
|
11358
|
+
grabbing: featureFlags.grabbingEnabled,
|
|
11359
|
+
physics: featureFlags.physicsEnabled,
|
|
11360
|
+
sceneUnderstanding: featureFlags.sceneUnderstandingEnabled,
|
|
11361
|
+
environmentRaycast: featureFlags.environmentRaycastEnabled,
|
|
11362
|
+
spatialUI: { kit: 'horizon' },
|
|
11363
|
+
},
|
|
11364
|
+
},
|
|
11365
|
+
dev: {
|
|
11366
|
+
emulator: {
|
|
11367
|
+
device: 'metaQuest3',
|
|
11368
|
+
...(target === 'ar' ? { environment: 'living_room' } : {}),
|
|
11369
|
+
},
|
|
11370
|
+
},
|
|
11371
|
+
};
|
|
11372
|
+
}
|
|
11272
11373
|
|
|
11273
|
-
|
|
11274
|
-
|
|
11275
|
-
reachedRoot = true;
|
|
11276
|
-
}
|
|
11277
|
-
}
|
|
11278
|
-
} else {
|
|
11279
|
-
const isValid = validateAttributeString(attrStr, options);
|
|
11280
|
-
if (isValid !== true) {
|
|
11281
|
-
//the result from the nested function returns the position of the error within the attribute
|
|
11282
|
-
//in order to get the 'true' error line, we need to calculate the position where the attribute begins (i - attrStr.length) and then add the position within the attribute
|
|
11283
|
-
//this gives us the absolute index in the entire xml, which we can use to find the line at last
|
|
11284
|
-
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
|
|
11285
|
-
}
|
|
11374
|
+
const VERSION = "0.5.1";
|
|
11375
|
+
const NODE_ENGINE = ">=20.19.0 <21.0.0-0 || >=22.12.0 <23.0.0-0 || >=24.0.0";
|
|
11286
11376
|
|
|
11287
|
-
|
|
11288
|
-
|
|
11289
|
-
|
|
11290
|
-
|
|
11291
|
-
|
|
11292
|
-
|
|
11293
|
-
|
|
11377
|
+
/**
|
|
11378
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
11379
|
+
*
|
|
11380
|
+
* This source code is licensed under the MIT license found in the
|
|
11381
|
+
* LICENSE file in the root directory of this source tree.
|
|
11382
|
+
*/
|
|
11383
|
+
/** Materialize one target/language output from the packaged common source. */
|
|
11384
|
+
async function buildStarterProjectFiles({ appName, configuration, language, packageSource, templateRoot = resolvePackagedTemplateRoot(), }) {
|
|
11385
|
+
const sourceDirectory = path$4.join(templateRoot, language === 'ts' ? 'common' : 'common-js');
|
|
11386
|
+
const files = await readDirectoryFiles(sourceDirectory);
|
|
11387
|
+
for (const guidanceGroup of GUIDANCE_GROUPS) {
|
|
11388
|
+
files.push(...(await readDirectoryFiles(path$4.join(templateRoot, '..', 'guidance', guidanceGroup))));
|
|
11389
|
+
}
|
|
11390
|
+
const sceneSource = path$4.join(templateRoot, 'scenes', configuration.target === 'ar'
|
|
11391
|
+
? 'ar.iwsdk.scene.json'
|
|
11392
|
+
: 'immersive.iwsdk.scene.json');
|
|
11393
|
+
files.push({
|
|
11394
|
+
path: 'public/scenes/main.iwsdk.scene.json',
|
|
11395
|
+
contents: await readFile(sceneSource),
|
|
11396
|
+
});
|
|
11397
|
+
files.push({
|
|
11398
|
+
path: 'iwsdk.config.json',
|
|
11399
|
+
contents: `${JSON.stringify(createProjectManifest(configuration), null, 2)}\n`,
|
|
11400
|
+
});
|
|
11401
|
+
files.push({
|
|
11402
|
+
path: 'package.json',
|
|
11403
|
+
contents: `${JSON.stringify(createProjectPackageJson(appName, language, packageSource), null, 2)}\n`,
|
|
11404
|
+
});
|
|
11405
|
+
const index = files.find((file) => file.path === 'index.html');
|
|
11406
|
+
if (index != null && typeof index.contents === 'string') {
|
|
11407
|
+
index.contents = index.contents.replace('<title>IWSDK App</title>', `<title>${escapeHtml(appName)}</title>`);
|
|
11408
|
+
}
|
|
11409
|
+
return files.sort((left, right) => left.path.localeCompare(right.path));
|
|
11410
|
+
}
|
|
11411
|
+
function createProjectPackageJson(appName, language, source) {
|
|
11412
|
+
const packageSpec = (name) => source.getPackageInstallSpec(name) ?? VERSION;
|
|
11413
|
+
return {
|
|
11414
|
+
name: appName,
|
|
11415
|
+
version: '0.1.0',
|
|
11416
|
+
private: true,
|
|
11417
|
+
type: 'module',
|
|
11418
|
+
scripts: {
|
|
11419
|
+
dev: 'iwsdk dev up --open --foreground',
|
|
11420
|
+
'dev:runtime': 'vite',
|
|
11421
|
+
'dev:down': 'iwsdk dev down',
|
|
11422
|
+
'dev:status': 'iwsdk dev status',
|
|
11423
|
+
'reference:status': 'iwsdk reference status',
|
|
11424
|
+
'reference:warmup': 'iwsdk reference warmup',
|
|
11425
|
+
...(language === 'ts' ? { typecheck: 'tsc --noEmit' } : {}),
|
|
11426
|
+
build: 'vite build',
|
|
11427
|
+
preview: 'vite preview',
|
|
11428
|
+
},
|
|
11429
|
+
dependencies: {
|
|
11430
|
+
'@iwsdk/core': packageSpec('@iwsdk/core'),
|
|
11431
|
+
three: 'npm:super-three@0.181.0',
|
|
11432
|
+
},
|
|
11433
|
+
devDependencies: {
|
|
11434
|
+
'@iwsdk/reference': packageSpec('@iwsdk/reference'),
|
|
11435
|
+
'@iwsdk/cli': packageSpec('@iwsdk/cli'),
|
|
11436
|
+
'@iwsdk/vite-plugin-dev': packageSpec('@iwsdk/vite-plugin-dev'),
|
|
11437
|
+
'@meta-quest/metavr': '^1.3.2',
|
|
11438
|
+
...(language === 'ts'
|
|
11439
|
+
? { '@types/three': '^0.181.0', typescript: '^5.5.0' }
|
|
11440
|
+
: {}),
|
|
11441
|
+
vite: '^7.1.4',
|
|
11442
|
+
},
|
|
11443
|
+
overrides: { sharp: '0.35.3' },
|
|
11444
|
+
engines: {
|
|
11445
|
+
node: '>=20.19.0 <21.0.0-0 || >=22.12.0 <23.0.0-0 || >=24.0.0',
|
|
11446
|
+
},
|
|
11447
|
+
};
|
|
11448
|
+
}
|
|
11449
|
+
async function readDirectoryFiles(root, relative = '') {
|
|
11450
|
+
const directory = path$4.join(root, relative);
|
|
11451
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
11452
|
+
const files = [];
|
|
11453
|
+
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
11454
|
+
const childRelative = path$4.posix.join(relative, entry.name);
|
|
11455
|
+
if (entry.isDirectory()) {
|
|
11456
|
+
files.push(...(await readDirectoryFiles(root, childRelative)));
|
|
11457
|
+
continue;
|
|
11294
11458
|
}
|
|
11295
|
-
|
|
11296
|
-
|
|
11297
|
-
//It may include comments and CDATA value
|
|
11298
|
-
for (i++; i < xmlData.length; i++) {
|
|
11299
|
-
if (xmlData[i] === '<') {
|
|
11300
|
-
if (xmlData[i + 1] === '!') {
|
|
11301
|
-
//comment or CADATA
|
|
11302
|
-
i++;
|
|
11303
|
-
i = readCommentAndCDATA(xmlData, i);
|
|
11304
|
-
continue;
|
|
11305
|
-
} else if (xmlData[i+1] === '?') {
|
|
11306
|
-
i = readPI(xmlData, ++i);
|
|
11307
|
-
if (i.err) return i;
|
|
11308
|
-
} else {
|
|
11309
|
-
break;
|
|
11310
|
-
}
|
|
11311
|
-
} else if (xmlData[i] === '&') {
|
|
11312
|
-
const afterAmp = validateAmpersand(xmlData, i);
|
|
11313
|
-
if (afterAmp == -1)
|
|
11314
|
-
return getErrorObject('InvalidChar', "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
11315
|
-
i = afterAmp;
|
|
11316
|
-
}else {
|
|
11317
|
-
if (reachedRoot === true && !isWhiteSpace(xmlData[i])) {
|
|
11318
|
-
return getErrorObject('InvalidXml', "Extra text at the end", getLineNumberForPosition(xmlData, i));
|
|
11319
|
-
}
|
|
11320
|
-
}
|
|
11321
|
-
} //end of reading tag text value
|
|
11322
|
-
if (xmlData[i] === '<') {
|
|
11323
|
-
i--;
|
|
11459
|
+
if (!entry.isFile()) {
|
|
11460
|
+
throw new Error(`Template entry is not a regular file: ${childRelative}`);
|
|
11324
11461
|
}
|
|
11325
|
-
|
|
11326
|
-
|
|
11327
|
-
|
|
11328
|
-
|
|
11329
|
-
|
|
11330
|
-
|
|
11462
|
+
const outputPath = templateOutputPath(childRelative);
|
|
11463
|
+
const contents = await readFile(path$4.join(root, childRelative));
|
|
11464
|
+
files.push({
|
|
11465
|
+
path: outputPath,
|
|
11466
|
+
contents: isTextTemplate(outputPath)
|
|
11467
|
+
? contents.toString('utf8')
|
|
11468
|
+
: contents,
|
|
11469
|
+
});
|
|
11331
11470
|
}
|
|
11332
|
-
|
|
11333
|
-
|
|
11334
|
-
if (!tagFound) {
|
|
11335
|
-
return getErrorObject('InvalidXml', 'Start tag expected.', 1);
|
|
11336
|
-
}else if (tags.length == 1) {
|
|
11337
|
-
return getErrorObject('InvalidTag', "Unclosed tag '"+tags[0].tagName+"'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
|
|
11338
|
-
}else if (tags.length > 0) {
|
|
11339
|
-
return getErrorObject('InvalidXml', "Invalid '"+
|
|
11340
|
-
JSON.stringify(tags.map(t => t.tagName), null, 4).replace(/\r?\n/g, '')+
|
|
11341
|
-
"' found.", {line: 1, col: 1});
|
|
11342
|
-
}
|
|
11343
|
-
|
|
11344
|
-
return true;
|
|
11345
|
-
};
|
|
11346
|
-
|
|
11347
|
-
function isWhiteSpace(char){
|
|
11348
|
-
return char === ' ' || char === '\t' || char === '\n' || char === '\r';
|
|
11471
|
+
return files;
|
|
11349
11472
|
}
|
|
11350
|
-
|
|
11351
|
-
|
|
11352
|
-
|
|
11353
|
-
* @param {*} i
|
|
11354
|
-
*/
|
|
11355
|
-
function readPI(xmlData, i) {
|
|
11356
|
-
const start = i;
|
|
11357
|
-
for (; i < xmlData.length; i++) {
|
|
11358
|
-
if (xmlData[i] == '?' || xmlData[i] == ' ') {
|
|
11359
|
-
//tagname
|
|
11360
|
-
const tagname = xmlData.substr(start, i - start);
|
|
11361
|
-
if (i > 5 && tagname === 'xml') {
|
|
11362
|
-
return getErrorObject('InvalidXml', 'XML declaration allowed only at the start of the document.', getLineNumberForPosition(xmlData, i));
|
|
11363
|
-
} else if (xmlData[i] == '?' && xmlData[i + 1] == '>') {
|
|
11364
|
-
//check if valid attribut string
|
|
11365
|
-
i++;
|
|
11366
|
-
break;
|
|
11367
|
-
} else {
|
|
11368
|
-
continue;
|
|
11369
|
-
}
|
|
11473
|
+
function templateOutputPath(relativePath) {
|
|
11474
|
+
if (relativePath === 'gitignore.template') {
|
|
11475
|
+
return '.gitignore';
|
|
11370
11476
|
}
|
|
11371
|
-
|
|
11372
|
-
|
|
11477
|
+
if (relativePath === 'nvmrc.template') {
|
|
11478
|
+
return '.nvmrc';
|
|
11479
|
+
}
|
|
11480
|
+
return relativePath;
|
|
11373
11481
|
}
|
|
11374
|
-
|
|
11375
|
-
|
|
11376
|
-
|
|
11377
|
-
|
|
11378
|
-
|
|
11379
|
-
|
|
11380
|
-
|
|
11381
|
-
|
|
11382
|
-
|
|
11482
|
+
function isTextTemplate(filePath) {
|
|
11483
|
+
return !filePath.endsWith('.mp3') && !filePath.endsWith('.png');
|
|
11484
|
+
}
|
|
11485
|
+
const GUIDANCE_GROUPS = [
|
|
11486
|
+
'common',
|
|
11487
|
+
'claude',
|
|
11488
|
+
'agents',
|
|
11489
|
+
'codex',
|
|
11490
|
+
'cursor',
|
|
11491
|
+
'copilot',
|
|
11492
|
+
'scoped-agents',
|
|
11493
|
+
];
|
|
11494
|
+
function resolvePackagedTemplateRoot() {
|
|
11495
|
+
const adjacent = fileURLToPath(new URL('./template/', import.meta.url));
|
|
11496
|
+
if (existsSync(adjacent)) {
|
|
11497
|
+
return adjacent;
|
|
11383
11498
|
}
|
|
11384
|
-
|
|
11385
|
-
|
|
11386
|
-
|
|
11387
|
-
xmlData[i + 2] === 'O' &&
|
|
11388
|
-
xmlData[i + 3] === 'C' &&
|
|
11389
|
-
xmlData[i + 4] === 'T' &&
|
|
11390
|
-
xmlData[i + 5] === 'Y' &&
|
|
11391
|
-
xmlData[i + 6] === 'P' &&
|
|
11392
|
-
xmlData[i + 7] === 'E'
|
|
11393
|
-
) {
|
|
11394
|
-
let angleBracketsCount = 1;
|
|
11395
|
-
for (i += 8; i < xmlData.length; i++) {
|
|
11396
|
-
if (xmlData[i] === '<') {
|
|
11397
|
-
angleBracketsCount++;
|
|
11398
|
-
} else if (xmlData[i] === '>') {
|
|
11399
|
-
angleBracketsCount--;
|
|
11400
|
-
if (angleBracketsCount === 0) {
|
|
11401
|
-
break;
|
|
11402
|
-
}
|
|
11403
|
-
}
|
|
11499
|
+
const source = fileURLToPath(new URL('../template/', import.meta.url));
|
|
11500
|
+
if (existsSync(path$4.join(source, 'common-js'))) {
|
|
11501
|
+
return source;
|
|
11404
11502
|
}
|
|
11405
|
-
|
|
11406
|
-
|
|
11407
|
-
|
|
11408
|
-
xmlData[i + 2] === 'C' &&
|
|
11409
|
-
xmlData[i + 3] === 'D' &&
|
|
11410
|
-
xmlData[i + 4] === 'A' &&
|
|
11411
|
-
xmlData[i + 5] === 'T' &&
|
|
11412
|
-
xmlData[i + 6] === 'A' &&
|
|
11413
|
-
xmlData[i + 7] === '['
|
|
11414
|
-
) {
|
|
11415
|
-
for (i += 8; i < xmlData.length; i++) {
|
|
11416
|
-
if (xmlData[i] === ']' && xmlData[i + 1] === ']' && xmlData[i + 2] === '>') {
|
|
11417
|
-
i += 2;
|
|
11418
|
-
break;
|
|
11419
|
-
}
|
|
11503
|
+
const builtFromSource = fileURLToPath(new URL('../dist/template/', import.meta.url));
|
|
11504
|
+
if (existsSync(builtFromSource)) {
|
|
11505
|
+
return builtFromSource;
|
|
11420
11506
|
}
|
|
11421
|
-
|
|
11422
|
-
|
|
11423
|
-
return i;
|
|
11507
|
+
throw new Error('The @iwsdk/create package is missing its packaged starter templates.');
|
|
11424
11508
|
}
|
|
11425
|
-
|
|
11426
|
-
|
|
11427
|
-
|
|
11428
|
-
|
|
11429
|
-
|
|
11430
|
-
|
|
11431
|
-
|
|
11432
|
-
* @param {number} i
|
|
11433
|
-
*/
|
|
11434
|
-
function readAttributeStr(xmlData, i) {
|
|
11435
|
-
let attrStr = '';
|
|
11436
|
-
let startChar = '';
|
|
11437
|
-
let tagClosed = false;
|
|
11438
|
-
for (; i < xmlData.length; i++) {
|
|
11439
|
-
if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {
|
|
11440
|
-
if (startChar === '') {
|
|
11441
|
-
startChar = xmlData[i];
|
|
11442
|
-
} else if (startChar !== xmlData[i]) ; else {
|
|
11443
|
-
startChar = '';
|
|
11444
|
-
}
|
|
11445
|
-
} else if (xmlData[i] === '>') {
|
|
11446
|
-
if (startChar === '') {
|
|
11447
|
-
tagClosed = true;
|
|
11448
|
-
break;
|
|
11449
|
-
}
|
|
11450
|
-
}
|
|
11451
|
-
attrStr += xmlData[i];
|
|
11452
|
-
}
|
|
11453
|
-
if (startChar !== '') {
|
|
11454
|
-
return false;
|
|
11455
|
-
}
|
|
11456
|
-
|
|
11457
|
-
return {
|
|
11458
|
-
value: attrStr,
|
|
11459
|
-
index: i,
|
|
11460
|
-
tagClosed: tagClosed
|
|
11461
|
-
};
|
|
11509
|
+
function escapeHtml(value) {
|
|
11510
|
+
return value
|
|
11511
|
+
.replaceAll('&', '&')
|
|
11512
|
+
.replaceAll('<', '<')
|
|
11513
|
+
.replaceAll('>', '>')
|
|
11514
|
+
.replaceAll('"', '"')
|
|
11515
|
+
.replaceAll("'", ''');
|
|
11462
11516
|
}
|
|
11463
11517
|
|
|
11464
11518
|
/**
|
|
11465
|
-
*
|
|
11519
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
11520
|
+
*
|
|
11521
|
+
* This source code is licensed under the MIT license found in the
|
|
11522
|
+
* LICENSE file in the root directory of this source tree.
|
|
11466
11523
|
*/
|
|
11467
|
-
|
|
11468
|
-
|
|
11469
|
-
|
|
11470
|
-
|
|
11471
|
-
function validateAttributeString(attrStr, options) {
|
|
11472
|
-
//console.log("start:"+attrStr+":end");
|
|
11473
|
-
|
|
11474
|
-
//if(attrStr.trim().length === 0) return true; //empty string
|
|
11475
|
-
|
|
11476
|
-
const matches = util$4.getAllMatches(attrStr, validAttrStrRegxp);
|
|
11477
|
-
const attrNames = {};
|
|
11478
|
-
|
|
11479
|
-
for (let i = 0; i < matches.length; i++) {
|
|
11480
|
-
if (matches[i][1].length === 0) {
|
|
11481
|
-
//nospace before attribute name: a="sd"b="saf"
|
|
11482
|
-
return getErrorObject('InvalidAttr', "Attribute '"+matches[i][2]+"' has no space in starting.", getPositionFromMatch(matches[i]))
|
|
11483
|
-
} else if (matches[i][3] !== undefined && matches[i][4] === undefined) {
|
|
11484
|
-
return getErrorObject('InvalidAttr', "Attribute '"+matches[i][2]+"' is without value.", getPositionFromMatch(matches[i]));
|
|
11485
|
-
} else if (matches[i][3] === undefined && !options.allowBooleanAttributes) {
|
|
11486
|
-
//independent attribute: ab
|
|
11487
|
-
return getErrorObject('InvalidAttr', "boolean attribute '"+matches[i][2]+"' is not allowed.", getPositionFromMatch(matches[i]));
|
|
11488
|
-
}
|
|
11489
|
-
/* else if(matches[i][6] === undefined){//attribute without value: ab=
|
|
11490
|
-
return { err: { code:"InvalidAttr",msg:"attribute " + matches[i][2] + " has no value assigned."}};
|
|
11491
|
-
} */
|
|
11492
|
-
const attrName = matches[i][2];
|
|
11493
|
-
if (!validateAttrName(attrName)) {
|
|
11494
|
-
return getErrorObject('InvalidAttr', "Attribute '"+attrName+"' is an invalid name.", getPositionFromMatch(matches[i]));
|
|
11495
|
-
}
|
|
11496
|
-
if (!attrNames.hasOwnProperty(attrName)) {
|
|
11497
|
-
//check for duplicate attribute.
|
|
11498
|
-
attrNames[attrName] = 1;
|
|
11499
|
-
} else {
|
|
11500
|
-
return getErrorObject('InvalidAttr', "Attribute '"+attrName+"' is repeated.", getPositionFromMatch(matches[i]));
|
|
11501
|
-
}
|
|
11502
|
-
}
|
|
11503
|
-
|
|
11504
|
-
return true;
|
|
11524
|
+
function isValidProjectTarget(value) {
|
|
11525
|
+
const name = value.trim();
|
|
11526
|
+
return (name === '.' ||
|
|
11527
|
+
(name !== '..' && /^[a-zA-Z0-9][a-zA-Z0-9._@-]*$/.test(name)));
|
|
11505
11528
|
}
|
|
11506
|
-
|
|
11507
|
-
|
|
11508
|
-
|
|
11509
|
-
|
|
11510
|
-
|
|
11511
|
-
|
|
11512
|
-
|
|
11513
|
-
|
|
11514
|
-
|
|
11515
|
-
return i;
|
|
11516
|
-
if (!xmlData[i].match(re))
|
|
11517
|
-
break;
|
|
11518
|
-
}
|
|
11519
|
-
return -1;
|
|
11529
|
+
function resolveProjectTarget(requestedName, cwd) {
|
|
11530
|
+
const targetName = requestedName.trim();
|
|
11531
|
+
const inPlace = targetName === '.';
|
|
11532
|
+
return {
|
|
11533
|
+
appName: inPlace ? toPackageName(path$5.basename(cwd)) : targetName,
|
|
11534
|
+
displayPath: inPlace ? '.' : targetName,
|
|
11535
|
+
inPlace,
|
|
11536
|
+
outDir: inPlace ? cwd : path$5.join(cwd, targetName),
|
|
11537
|
+
};
|
|
11520
11538
|
}
|
|
11521
|
-
|
|
11522
|
-
|
|
11523
|
-
|
|
11524
|
-
|
|
11525
|
-
|
|
11526
|
-
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
return validateNumberAmpersand(xmlData, i);
|
|
11530
|
-
}
|
|
11531
|
-
let count = 0;
|
|
11532
|
-
for (; i < xmlData.length; i++, count++) {
|
|
11533
|
-
if (xmlData[i].match(/\w/) && count < 20)
|
|
11534
|
-
continue;
|
|
11535
|
-
if (xmlData[i] === ';')
|
|
11536
|
-
break;
|
|
11537
|
-
return -1;
|
|
11538
|
-
}
|
|
11539
|
-
return i;
|
|
11539
|
+
function targetHasContent(target) {
|
|
11540
|
+
if (!fs$2.existsSync(target.outDir)) {
|
|
11541
|
+
return false;
|
|
11542
|
+
}
|
|
11543
|
+
if (!fs$2.statSync(target.outDir).isDirectory()) {
|
|
11544
|
+
throw new Error(`Target "${target.displayPath}" is not a directory.`);
|
|
11545
|
+
}
|
|
11546
|
+
return fs$2.readdirSync(target.outDir).length > 0;
|
|
11540
11547
|
}
|
|
11541
|
-
|
|
11542
|
-
|
|
11543
|
-
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
|
|
11547
|
-
|
|
11548
|
-
|
|
11549
|
-
|
|
11550
|
-
};
|
|
11548
|
+
function toPackageName(value) {
|
|
11549
|
+
const normalized = value
|
|
11550
|
+
.trim()
|
|
11551
|
+
.toLowerCase()
|
|
11552
|
+
.replace(/\s+/g, '-')
|
|
11553
|
+
.replace(/^[._]+/, '')
|
|
11554
|
+
.replace(/[^a-z0-9~.-]+/g, '-')
|
|
11555
|
+
.replace(/^-+|-+$/g, '');
|
|
11556
|
+
return normalized || 'iwsdk-app';
|
|
11551
11557
|
}
|
|
11552
11558
|
|
|
11553
|
-
|
|
11554
|
-
return util$4.isName(attrName);
|
|
11555
|
-
}
|
|
11559
|
+
var prompts$3 = {};
|
|
11556
11560
|
|
|
11557
|
-
|
|
11561
|
+
var kleur;
|
|
11562
|
+
var hasRequiredKleur;
|
|
11558
11563
|
|
|
11559
|
-
function
|
|
11560
|
-
|
|
11561
|
-
|
|
11564
|
+
function requireKleur () {
|
|
11565
|
+
if (hasRequiredKleur) return kleur;
|
|
11566
|
+
hasRequiredKleur = 1;
|
|
11562
11567
|
|
|
11563
|
-
|
|
11564
|
-
function getLineNumberForPosition(xmlData, index) {
|
|
11565
|
-
const lines = xmlData.substring(0, index).split(/\r?\n/);
|
|
11566
|
-
return {
|
|
11567
|
-
line: lines.length,
|
|
11568
|
+
const { FORCE_COLOR, NODE_DISABLE_COLORS, TERM } = process.env;
|
|
11568
11569
|
|
|
11569
|
-
|
|
11570
|
-
|
|
11571
|
-
};
|
|
11572
|
-
}
|
|
11573
|
-
|
|
11574
|
-
//this function returns the position of the first character of match within attrStr
|
|
11575
|
-
function getPositionFromMatch(match) {
|
|
11576
|
-
return match.startIndex + match[1].length;
|
|
11577
|
-
}
|
|
11578
|
-
|
|
11579
|
-
var OptionsBuilder = {};
|
|
11580
|
-
|
|
11581
|
-
const defaultOptions$1 = {
|
|
11582
|
-
preserveOrder: false,
|
|
11583
|
-
attributeNamePrefix: '@_',
|
|
11584
|
-
attributesGroupName: false,
|
|
11585
|
-
textNodeName: '#text',
|
|
11586
|
-
ignoreAttributes: true,
|
|
11587
|
-
removeNSPrefix: false, // remove NS from tag name or attribute name if true
|
|
11588
|
-
allowBooleanAttributes: false, //a tag can have attributes without any value
|
|
11589
|
-
//ignoreRootElement : false,
|
|
11590
|
-
parseTagValue: true,
|
|
11591
|
-
parseAttributeValue: false,
|
|
11592
|
-
trimValues: true, //Trim string values of tag and attributes
|
|
11593
|
-
cdataPropName: false,
|
|
11594
|
-
numberParseOptions: {
|
|
11595
|
-
hex: true,
|
|
11596
|
-
leadingZeros: true,
|
|
11597
|
-
eNotation: true
|
|
11598
|
-
},
|
|
11599
|
-
tagValueProcessor: function(tagName, val) {
|
|
11600
|
-
return val;
|
|
11601
|
-
},
|
|
11602
|
-
attributeValueProcessor: function(attrName, val) {
|
|
11603
|
-
return val;
|
|
11604
|
-
},
|
|
11605
|
-
stopNodes: [], //nested tags will not be parsed even for errors
|
|
11606
|
-
alwaysCreateTextNode: false,
|
|
11607
|
-
isArray: () => false,
|
|
11608
|
-
commentPropName: false,
|
|
11609
|
-
unpairedTags: [],
|
|
11610
|
-
processEntities: true,
|
|
11611
|
-
htmlEntities: false,
|
|
11612
|
-
ignoreDeclaration: false,
|
|
11613
|
-
ignorePiTags: false,
|
|
11614
|
-
transformTagName: false,
|
|
11615
|
-
transformAttributeName: false,
|
|
11616
|
-
updateTag: function(tagName, jPath, attrs){
|
|
11617
|
-
return tagName
|
|
11618
|
-
},
|
|
11619
|
-
// skipEmptyListItem: false
|
|
11620
|
-
};
|
|
11621
|
-
|
|
11622
|
-
const buildOptions$1 = function(options) {
|
|
11623
|
-
return Object.assign({}, defaultOptions$1, options);
|
|
11624
|
-
};
|
|
11625
|
-
|
|
11626
|
-
OptionsBuilder.buildOptions = buildOptions$1;
|
|
11627
|
-
OptionsBuilder.defaultOptions = defaultOptions$1;
|
|
11628
|
-
|
|
11629
|
-
class XmlNode{
|
|
11630
|
-
constructor(tagname) {
|
|
11631
|
-
this.tagname = tagname;
|
|
11632
|
-
this.child = []; //nested tags, text, cdata, comments in order
|
|
11633
|
-
this[":@"] = {}; //attributes map
|
|
11634
|
-
}
|
|
11635
|
-
add(key,val){
|
|
11636
|
-
// this.child.push( {name : key, val: val, isCdata: isCdata });
|
|
11637
|
-
if(key === "__proto__") key = "#__proto__";
|
|
11638
|
-
this.child.push( {[key]: val });
|
|
11639
|
-
}
|
|
11640
|
-
addChild(node) {
|
|
11641
|
-
if(node.tagname === "__proto__") node.tagname = "#__proto__";
|
|
11642
|
-
if(node[":@"] && Object.keys(node[":@"]).length > 0){
|
|
11643
|
-
this.child.push( { [node.tagname]: node.child, [":@"]: node[":@"] });
|
|
11644
|
-
}else {
|
|
11645
|
-
this.child.push( { [node.tagname]: node.child });
|
|
11646
|
-
}
|
|
11647
|
-
};
|
|
11648
|
-
}
|
|
11649
|
-
|
|
11650
|
-
var xmlNode$1 = XmlNode;
|
|
11651
|
-
|
|
11652
|
-
const util$3 = util$5;
|
|
11653
|
-
|
|
11654
|
-
//TODO: handle comments
|
|
11655
|
-
function readDocType$1(xmlData, i){
|
|
11656
|
-
|
|
11657
|
-
const entities = {};
|
|
11658
|
-
if( xmlData[i + 3] === 'O' &&
|
|
11659
|
-
xmlData[i + 4] === 'C' &&
|
|
11660
|
-
xmlData[i + 5] === 'T' &&
|
|
11661
|
-
xmlData[i + 6] === 'Y' &&
|
|
11662
|
-
xmlData[i + 7] === 'P' &&
|
|
11663
|
-
xmlData[i + 8] === 'E')
|
|
11664
|
-
{
|
|
11665
|
-
i = i+9;
|
|
11666
|
-
let angleBracketsCount = 1;
|
|
11667
|
-
let hasBody = false, comment = false;
|
|
11668
|
-
let exp = "";
|
|
11669
|
-
for(;i<xmlData.length;i++){
|
|
11670
|
-
if (xmlData[i] === '<' && !comment) { //Determine the tag type
|
|
11671
|
-
if( hasBody && isEntity(xmlData, i)){
|
|
11672
|
-
i += 7;
|
|
11673
|
-
let entityName, val;
|
|
11674
|
-
[entityName, val,i] = readEntityExp(xmlData,i+1);
|
|
11675
|
-
if(val.indexOf("&") === -1) //Parameter entities are not supported
|
|
11676
|
-
entities[ validateEntityName(entityName) ] = {
|
|
11677
|
-
regx : RegExp( `&${entityName};`,"g"),
|
|
11678
|
-
val: val
|
|
11679
|
-
};
|
|
11680
|
-
}
|
|
11681
|
-
else if( hasBody && isElement(xmlData, i)) i += 8;//Not supported
|
|
11682
|
-
else if( hasBody && isAttlist(xmlData, i)) i += 8;//Not supported
|
|
11683
|
-
else if( hasBody && isNotation(xmlData, i)) i += 9;//Not supported
|
|
11684
|
-
else if( isComment) comment = true;
|
|
11685
|
-
else throw new Error("Invalid DOCTYPE");
|
|
11686
|
-
|
|
11687
|
-
angleBracketsCount++;
|
|
11688
|
-
exp = "";
|
|
11689
|
-
} else if (xmlData[i] === '>') { //Read tag content
|
|
11690
|
-
if(comment){
|
|
11691
|
-
if( xmlData[i - 1] === "-" && xmlData[i - 2] === "-"){
|
|
11692
|
-
comment = false;
|
|
11693
|
-
angleBracketsCount--;
|
|
11694
|
-
}
|
|
11695
|
-
}else {
|
|
11696
|
-
angleBracketsCount--;
|
|
11697
|
-
}
|
|
11698
|
-
if (angleBracketsCount === 0) {
|
|
11699
|
-
break;
|
|
11700
|
-
}
|
|
11701
|
-
}else if( xmlData[i] === '['){
|
|
11702
|
-
hasBody = true;
|
|
11703
|
-
}else {
|
|
11704
|
-
exp += xmlData[i];
|
|
11705
|
-
}
|
|
11706
|
-
}
|
|
11707
|
-
if(angleBracketsCount !== 0){
|
|
11708
|
-
throw new Error(`Unclosed DOCTYPE`);
|
|
11709
|
-
}
|
|
11710
|
-
}else {
|
|
11711
|
-
throw new Error(`Invalid Tag instead of DOCTYPE`);
|
|
11712
|
-
}
|
|
11713
|
-
return {entities, i};
|
|
11714
|
-
}
|
|
11715
|
-
|
|
11716
|
-
function readEntityExp(xmlData,i){
|
|
11717
|
-
//External entities are not supported
|
|
11718
|
-
// <!ENTITY ext SYSTEM "http://normal-website.com" >
|
|
11719
|
-
|
|
11720
|
-
//Parameter entities are not supported
|
|
11721
|
-
// <!ENTITY entityname "&anotherElement;">
|
|
11722
|
-
|
|
11723
|
-
//Internal entities are supported
|
|
11724
|
-
// <!ENTITY entityname "replacement text">
|
|
11725
|
-
|
|
11726
|
-
//read EntityName
|
|
11727
|
-
let entityName = "";
|
|
11728
|
-
for (; i < xmlData.length && (xmlData[i] !== "'" && xmlData[i] !== '"' ); i++) {
|
|
11729
|
-
// if(xmlData[i] === " ") continue;
|
|
11730
|
-
// else
|
|
11731
|
-
entityName += xmlData[i];
|
|
11732
|
-
}
|
|
11733
|
-
entityName = entityName.trim();
|
|
11734
|
-
if(entityName.indexOf(" ") !== -1) throw new Error("External entites are not supported");
|
|
11735
|
-
|
|
11736
|
-
//read Entity Value
|
|
11737
|
-
const startChar = xmlData[i++];
|
|
11738
|
-
let val = "";
|
|
11739
|
-
for (; i < xmlData.length && xmlData[i] !== startChar ; i++) {
|
|
11740
|
-
val += xmlData[i];
|
|
11741
|
-
}
|
|
11742
|
-
return [entityName, val, i];
|
|
11743
|
-
}
|
|
11744
|
-
|
|
11745
|
-
function isComment(xmlData, i){
|
|
11746
|
-
if(xmlData[i+1] === '!' &&
|
|
11747
|
-
xmlData[i+2] === '-' &&
|
|
11748
|
-
xmlData[i+3] === '-') return true
|
|
11749
|
-
return false
|
|
11750
|
-
}
|
|
11751
|
-
function isEntity(xmlData, i){
|
|
11752
|
-
if(xmlData[i+1] === '!' &&
|
|
11753
|
-
xmlData[i+2] === 'E' &&
|
|
11754
|
-
xmlData[i+3] === 'N' &&
|
|
11755
|
-
xmlData[i+4] === 'T' &&
|
|
11756
|
-
xmlData[i+5] === 'I' &&
|
|
11757
|
-
xmlData[i+6] === 'T' &&
|
|
11758
|
-
xmlData[i+7] === 'Y') return true
|
|
11759
|
-
return false
|
|
11760
|
-
}
|
|
11761
|
-
function isElement(xmlData, i){
|
|
11762
|
-
if(xmlData[i+1] === '!' &&
|
|
11763
|
-
xmlData[i+2] === 'E' &&
|
|
11764
|
-
xmlData[i+3] === 'L' &&
|
|
11765
|
-
xmlData[i+4] === 'E' &&
|
|
11766
|
-
xmlData[i+5] === 'M' &&
|
|
11767
|
-
xmlData[i+6] === 'E' &&
|
|
11768
|
-
xmlData[i+7] === 'N' &&
|
|
11769
|
-
xmlData[i+8] === 'T') return true
|
|
11770
|
-
return false
|
|
11771
|
-
}
|
|
11772
|
-
|
|
11773
|
-
function isAttlist(xmlData, i){
|
|
11774
|
-
if(xmlData[i+1] === '!' &&
|
|
11775
|
-
xmlData[i+2] === 'A' &&
|
|
11776
|
-
xmlData[i+3] === 'T' &&
|
|
11777
|
-
xmlData[i+4] === 'T' &&
|
|
11778
|
-
xmlData[i+5] === 'L' &&
|
|
11779
|
-
xmlData[i+6] === 'I' &&
|
|
11780
|
-
xmlData[i+7] === 'S' &&
|
|
11781
|
-
xmlData[i+8] === 'T') return true
|
|
11782
|
-
return false
|
|
11783
|
-
}
|
|
11784
|
-
function isNotation(xmlData, i){
|
|
11785
|
-
if(xmlData[i+1] === '!' &&
|
|
11786
|
-
xmlData[i+2] === 'N' &&
|
|
11787
|
-
xmlData[i+3] === 'O' &&
|
|
11788
|
-
xmlData[i+4] === 'T' &&
|
|
11789
|
-
xmlData[i+5] === 'A' &&
|
|
11790
|
-
xmlData[i+6] === 'T' &&
|
|
11791
|
-
xmlData[i+7] === 'I' &&
|
|
11792
|
-
xmlData[i+8] === 'O' &&
|
|
11793
|
-
xmlData[i+9] === 'N') return true
|
|
11794
|
-
return false
|
|
11795
|
-
}
|
|
11796
|
-
|
|
11797
|
-
function validateEntityName(name){
|
|
11798
|
-
if (util$3.isName(name))
|
|
11799
|
-
return name;
|
|
11800
|
-
else
|
|
11801
|
-
throw new Error(`Invalid entity name ${name}`);
|
|
11802
|
-
}
|
|
11803
|
-
|
|
11804
|
-
var DocTypeReader = readDocType$1;
|
|
11805
|
-
|
|
11806
|
-
const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
|
|
11807
|
-
const numRegex = /^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/;
|
|
11808
|
-
// const octRegex = /^0x[a-z0-9]+/;
|
|
11809
|
-
// const binRegex = /0x[a-z0-9]+/;
|
|
11810
|
-
|
|
11811
|
-
|
|
11812
|
-
const consider = {
|
|
11813
|
-
hex : true,
|
|
11814
|
-
// oct: false,
|
|
11815
|
-
leadingZeros: true,
|
|
11816
|
-
decimalPoint: "\.",
|
|
11817
|
-
eNotation: true,
|
|
11818
|
-
//skipLike: /regex/
|
|
11819
|
-
};
|
|
11820
|
-
|
|
11821
|
-
function toNumber$1(str, options = {}){
|
|
11822
|
-
options = Object.assign({}, consider, options );
|
|
11823
|
-
if(!str || typeof str !== "string" ) return str;
|
|
11824
|
-
|
|
11825
|
-
let trimmedStr = str.trim();
|
|
11826
|
-
|
|
11827
|
-
if(options.skipLike !== undefined && options.skipLike.test(trimmedStr)) return str;
|
|
11828
|
-
else if(str==="0") return 0;
|
|
11829
|
-
else if (options.hex && hexRegex.test(trimmedStr)) {
|
|
11830
|
-
return parse_int(trimmedStr, 16);
|
|
11831
|
-
// }else if (options.oct && octRegex.test(str)) {
|
|
11832
|
-
// return Number.parseInt(val, 8);
|
|
11833
|
-
}else if (trimmedStr.search(/[eE]/)!== -1) { //eNotation
|
|
11834
|
-
const notation = trimmedStr.match(/^([-\+])?(0*)([0-9]*(\.[0-9]*)?[eE][-\+]?[0-9]+)$/);
|
|
11835
|
-
// +00.123 => [ , '+', '00', '.123', ..
|
|
11836
|
-
if(notation){
|
|
11837
|
-
// console.log(notation)
|
|
11838
|
-
if(options.leadingZeros){ //accept with leading zeros
|
|
11839
|
-
trimmedStr = (notation[1] || "") + notation[3];
|
|
11840
|
-
}else {
|
|
11841
|
-
if(notation[2] === "0" && notation[3][0]=== ".");else {
|
|
11842
|
-
return str;
|
|
11843
|
-
}
|
|
11844
|
-
}
|
|
11845
|
-
return options.eNotation ? Number(trimmedStr) : str;
|
|
11846
|
-
}else {
|
|
11847
|
-
return str;
|
|
11848
|
-
}
|
|
11849
|
-
// }else if (options.parseBin && binRegex.test(str)) {
|
|
11850
|
-
// return Number.parseInt(val, 2);
|
|
11851
|
-
}else {
|
|
11852
|
-
//separate negative sign, leading zeros, and rest number
|
|
11853
|
-
const match = numRegex.exec(trimmedStr);
|
|
11854
|
-
// +00.123 => [ , '+', '00', '.123', ..
|
|
11855
|
-
if(match){
|
|
11856
|
-
const sign = match[1];
|
|
11857
|
-
const leadingZeros = match[2];
|
|
11858
|
-
let numTrimmedByZeros = trimZeros(match[3]); //complete num without leading zeros
|
|
11859
|
-
//trim ending zeros for floating number
|
|
11860
|
-
|
|
11861
|
-
if(!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== ".") return str; //-0123
|
|
11862
|
-
else if(!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== ".") return str; //0123
|
|
11863
|
-
else if(options.leadingZeros && leadingZeros===str) return 0; //00
|
|
11864
|
-
|
|
11865
|
-
else {//no leading zeros or leading zeros are allowed
|
|
11866
|
-
const num = Number(trimmedStr);
|
|
11867
|
-
const numStr = "" + num;
|
|
11868
|
-
|
|
11869
|
-
if(numStr.search(/[eE]/) !== -1){ //given number is long and parsed to eNotation
|
|
11870
|
-
if(options.eNotation) return num;
|
|
11871
|
-
else return str;
|
|
11872
|
-
}else if(trimmedStr.indexOf(".") !== -1){ //floating number
|
|
11873
|
-
if(numStr === "0" && (numTrimmedByZeros === "") ) return num; //0.0
|
|
11874
|
-
else if(numStr === numTrimmedByZeros) return num; //0.456. 0.79000
|
|
11875
|
-
else if( sign && numStr === "-"+numTrimmedByZeros) return num;
|
|
11876
|
-
else return str;
|
|
11877
|
-
}
|
|
11878
|
-
|
|
11879
|
-
if(leadingZeros){
|
|
11880
|
-
return (numTrimmedByZeros === numStr) || (sign+numTrimmedByZeros === numStr) ? num : str
|
|
11881
|
-
}else {
|
|
11882
|
-
return (trimmedStr === numStr) || (trimmedStr === sign+numStr) ? num : str
|
|
11883
|
-
}
|
|
11884
|
-
}
|
|
11885
|
-
}else { //non-numeric string
|
|
11886
|
-
return str;
|
|
11887
|
-
}
|
|
11888
|
-
}
|
|
11889
|
-
}
|
|
11890
|
-
|
|
11891
|
-
/**
|
|
11892
|
-
*
|
|
11893
|
-
* @param {string} numStr without leading zeros
|
|
11894
|
-
* @returns
|
|
11895
|
-
*/
|
|
11896
|
-
function trimZeros(numStr){
|
|
11897
|
-
if(numStr && numStr.indexOf(".") !== -1){//float
|
|
11898
|
-
numStr = numStr.replace(/0+$/, ""); //remove ending zeros
|
|
11899
|
-
if(numStr === ".") numStr = "0";
|
|
11900
|
-
else if(numStr[0] === ".") numStr = "0"+numStr;
|
|
11901
|
-
else if(numStr[numStr.length-1] === ".") numStr = numStr.substr(0,numStr.length-1);
|
|
11902
|
-
return numStr;
|
|
11903
|
-
}
|
|
11904
|
-
return numStr;
|
|
11905
|
-
}
|
|
11906
|
-
|
|
11907
|
-
function parse_int(numStr, base){
|
|
11908
|
-
//polyfill
|
|
11909
|
-
if(parseInt) return parseInt(numStr, base);
|
|
11910
|
-
else if(Number.parseInt) return Number.parseInt(numStr, base);
|
|
11911
|
-
else if(window && window.parseInt) return window.parseInt(numStr, base);
|
|
11912
|
-
else throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")
|
|
11913
|
-
}
|
|
11914
|
-
|
|
11915
|
-
var strnum = toNumber$1;
|
|
11916
|
-
|
|
11917
|
-
function getIgnoreAttributesFn$2(ignoreAttributes) {
|
|
11918
|
-
if (typeof ignoreAttributes === 'function') {
|
|
11919
|
-
return ignoreAttributes
|
|
11920
|
-
}
|
|
11921
|
-
if (Array.isArray(ignoreAttributes)) {
|
|
11922
|
-
return (attrName) => {
|
|
11923
|
-
for (const pattern of ignoreAttributes) {
|
|
11924
|
-
if (typeof pattern === 'string' && attrName === pattern) {
|
|
11925
|
-
return true
|
|
11926
|
-
}
|
|
11927
|
-
if (pattern instanceof RegExp && pattern.test(attrName)) {
|
|
11928
|
-
return true
|
|
11929
|
-
}
|
|
11930
|
-
}
|
|
11931
|
-
}
|
|
11932
|
-
}
|
|
11933
|
-
return () => false
|
|
11934
|
-
}
|
|
11935
|
-
|
|
11936
|
-
var ignoreAttributes = getIgnoreAttributesFn$2;
|
|
11937
|
-
|
|
11938
|
-
///@ts-check
|
|
11939
|
-
|
|
11940
|
-
const util$2 = util$5;
|
|
11941
|
-
const xmlNode = xmlNode$1;
|
|
11942
|
-
const readDocType = DocTypeReader;
|
|
11943
|
-
const toNumber = strnum;
|
|
11944
|
-
const getIgnoreAttributesFn$1 = ignoreAttributes;
|
|
11945
|
-
|
|
11946
|
-
// const regx =
|
|
11947
|
-
// '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)'
|
|
11948
|
-
// .replace(/NAME/g, util.nameRegexp);
|
|
11949
|
-
|
|
11950
|
-
//const tagsRegx = new RegExp("<(\\/?[\\w:\\-\._]+)([^>]*)>(\\s*"+cdataRegx+")*([^<]+)?","g");
|
|
11951
|
-
//const tagsRegx = new RegExp("<(\\/?)((\\w*:)?([\\w:\\-\._]+))([^>]*)>([^<]*)("+cdataRegx+"([^<]*))*([^<]+)?","g");
|
|
11952
|
-
|
|
11953
|
-
let OrderedObjParser$1 = class OrderedObjParser{
|
|
11954
|
-
constructor(options){
|
|
11955
|
-
this.options = options;
|
|
11956
|
-
this.currentNode = null;
|
|
11957
|
-
this.tagsNodeStack = [];
|
|
11958
|
-
this.docTypeEntities = {};
|
|
11959
|
-
this.lastEntities = {
|
|
11960
|
-
"apos" : { regex: /&(apos|#39|#x27);/g, val : "'"},
|
|
11961
|
-
"gt" : { regex: /&(gt|#62|#x3E);/g, val : ">"},
|
|
11962
|
-
"lt" : { regex: /&(lt|#60|#x3C);/g, val : "<"},
|
|
11963
|
-
"quot" : { regex: /&(quot|#34|#x22);/g, val : "\""},
|
|
11964
|
-
};
|
|
11965
|
-
this.ampEntity = { regex: /&(amp|#38|#x26);/g, val : "&"};
|
|
11966
|
-
this.htmlEntities = {
|
|
11967
|
-
"space": { regex: /&(nbsp|#160);/g, val: " " },
|
|
11968
|
-
// "lt" : { regex: /&(lt|#60);/g, val: "<" },
|
|
11969
|
-
// "gt" : { regex: /&(gt|#62);/g, val: ">" },
|
|
11970
|
-
// "amp" : { regex: /&(amp|#38);/g, val: "&" },
|
|
11971
|
-
// "quot" : { regex: /&(quot|#34);/g, val: "\"" },
|
|
11972
|
-
// "apos" : { regex: /&(apos|#39);/g, val: "'" },
|
|
11973
|
-
"cent" : { regex: /&(cent|#162);/g, val: "¢" },
|
|
11974
|
-
"pound" : { regex: /&(pound|#163);/g, val: "£" },
|
|
11975
|
-
"yen" : { regex: /&(yen|#165);/g, val: "¥" },
|
|
11976
|
-
"euro" : { regex: /&(euro|#8364);/g, val: "€" },
|
|
11977
|
-
"copyright" : { regex: /&(copy|#169);/g, val: "©" },
|
|
11978
|
-
"reg" : { regex: /&(reg|#174);/g, val: "®" },
|
|
11979
|
-
"inr" : { regex: /&(inr|#8377);/g, val: "₹" },
|
|
11980
|
-
"num_dec": { regex: /&#([0-9]{1,7});/g, val : (_, str) => String.fromCharCode(Number.parseInt(str, 10)) },
|
|
11981
|
-
"num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val : (_, str) => String.fromCharCode(Number.parseInt(str, 16)) },
|
|
11982
|
-
};
|
|
11983
|
-
this.addExternalEntities = addExternalEntities;
|
|
11984
|
-
this.parseXml = parseXml;
|
|
11985
|
-
this.parseTextData = parseTextData;
|
|
11986
|
-
this.resolveNameSpace = resolveNameSpace;
|
|
11987
|
-
this.buildAttributesMap = buildAttributesMap;
|
|
11988
|
-
this.isItStopNode = isItStopNode;
|
|
11989
|
-
this.replaceEntitiesValue = replaceEntitiesValue$1;
|
|
11990
|
-
this.readStopNodeData = readStopNodeData;
|
|
11991
|
-
this.saveTextToParentTag = saveTextToParentTag;
|
|
11992
|
-
this.addChild = addChild;
|
|
11993
|
-
this.ignoreAttributesFn = getIgnoreAttributesFn$1(this.options.ignoreAttributes);
|
|
11994
|
-
}
|
|
11995
|
-
|
|
11996
|
-
};
|
|
11997
|
-
|
|
11998
|
-
function addExternalEntities(externalEntities){
|
|
11999
|
-
const entKeys = Object.keys(externalEntities);
|
|
12000
|
-
for (let i = 0; i < entKeys.length; i++) {
|
|
12001
|
-
const ent = entKeys[i];
|
|
12002
|
-
this.lastEntities[ent] = {
|
|
12003
|
-
regex: new RegExp("&"+ent+";","g"),
|
|
12004
|
-
val : externalEntities[ent]
|
|
12005
|
-
};
|
|
12006
|
-
}
|
|
12007
|
-
}
|
|
12008
|
-
|
|
12009
|
-
/**
|
|
12010
|
-
* @param {string} val
|
|
12011
|
-
* @param {string} tagName
|
|
12012
|
-
* @param {string} jPath
|
|
12013
|
-
* @param {boolean} dontTrim
|
|
12014
|
-
* @param {boolean} hasAttributes
|
|
12015
|
-
* @param {boolean} isLeafNode
|
|
12016
|
-
* @param {boolean} escapeEntities
|
|
12017
|
-
*/
|
|
12018
|
-
function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
|
|
12019
|
-
if (val !== undefined) {
|
|
12020
|
-
if (this.options.trimValues && !dontTrim) {
|
|
12021
|
-
val = val.trim();
|
|
12022
|
-
}
|
|
12023
|
-
if(val.length > 0){
|
|
12024
|
-
if(!escapeEntities) val = this.replaceEntitiesValue(val);
|
|
12025
|
-
|
|
12026
|
-
const newval = this.options.tagValueProcessor(tagName, val, jPath, hasAttributes, isLeafNode);
|
|
12027
|
-
if(newval === null || newval === undefined){
|
|
12028
|
-
//don't parse
|
|
12029
|
-
return val;
|
|
12030
|
-
}else if(typeof newval !== typeof val || newval !== val){
|
|
12031
|
-
//overwrite
|
|
12032
|
-
return newval;
|
|
12033
|
-
}else if(this.options.trimValues){
|
|
12034
|
-
return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
|
|
12035
|
-
}else {
|
|
12036
|
-
const trimmedVal = val.trim();
|
|
12037
|
-
if(trimmedVal === val){
|
|
12038
|
-
return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
|
|
12039
|
-
}else {
|
|
12040
|
-
return val;
|
|
12041
|
-
}
|
|
12042
|
-
}
|
|
12043
|
-
}
|
|
12044
|
-
}
|
|
12045
|
-
}
|
|
12046
|
-
|
|
12047
|
-
function resolveNameSpace(tagname) {
|
|
12048
|
-
if (this.options.removeNSPrefix) {
|
|
12049
|
-
const tags = tagname.split(':');
|
|
12050
|
-
const prefix = tagname.charAt(0) === '/' ? '/' : '';
|
|
12051
|
-
if (tags[0] === 'xmlns') {
|
|
12052
|
-
return '';
|
|
12053
|
-
}
|
|
12054
|
-
if (tags.length === 2) {
|
|
12055
|
-
tagname = prefix + tags[1];
|
|
12056
|
-
}
|
|
12057
|
-
}
|
|
12058
|
-
return tagname;
|
|
12059
|
-
}
|
|
12060
|
-
|
|
12061
|
-
//TODO: change regex to capture NS
|
|
12062
|
-
//const attrsRegx = new RegExp("([\\w\\-\\.\\:]+)\\s*=\\s*(['\"])((.|\n)*?)\\2","gm");
|
|
12063
|
-
const attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])([\\s\\S]*?)\\3)?', 'gm');
|
|
12064
|
-
|
|
12065
|
-
function buildAttributesMap(attrStr, jPath, tagName) {
|
|
12066
|
-
if (this.options.ignoreAttributes !== true && typeof attrStr === 'string') {
|
|
12067
|
-
// attrStr = attrStr.replace(/\r?\n/g, ' ');
|
|
12068
|
-
//attrStr = attrStr || attrStr.trim();
|
|
12069
|
-
|
|
12070
|
-
const matches = util$2.getAllMatches(attrStr, attrsRegx);
|
|
12071
|
-
const len = matches.length; //don't make it inline
|
|
12072
|
-
const attrs = {};
|
|
12073
|
-
for (let i = 0; i < len; i++) {
|
|
12074
|
-
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
12075
|
-
if (this.ignoreAttributesFn(attrName, jPath)) {
|
|
12076
|
-
continue
|
|
12077
|
-
}
|
|
12078
|
-
let oldVal = matches[i][4];
|
|
12079
|
-
let aName = this.options.attributeNamePrefix + attrName;
|
|
12080
|
-
if (attrName.length) {
|
|
12081
|
-
if (this.options.transformAttributeName) {
|
|
12082
|
-
aName = this.options.transformAttributeName(aName);
|
|
12083
|
-
}
|
|
12084
|
-
if(aName === "__proto__") aName = "#__proto__";
|
|
12085
|
-
if (oldVal !== undefined) {
|
|
12086
|
-
if (this.options.trimValues) {
|
|
12087
|
-
oldVal = oldVal.trim();
|
|
12088
|
-
}
|
|
12089
|
-
oldVal = this.replaceEntitiesValue(oldVal);
|
|
12090
|
-
const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath);
|
|
12091
|
-
if(newVal === null || newVal === undefined){
|
|
12092
|
-
//don't parse
|
|
12093
|
-
attrs[aName] = oldVal;
|
|
12094
|
-
}else if(typeof newVal !== typeof oldVal || newVal !== oldVal){
|
|
12095
|
-
//overwrite
|
|
12096
|
-
attrs[aName] = newVal;
|
|
12097
|
-
}else {
|
|
12098
|
-
//parse
|
|
12099
|
-
attrs[aName] = parseValue(
|
|
12100
|
-
oldVal,
|
|
12101
|
-
this.options.parseAttributeValue,
|
|
12102
|
-
this.options.numberParseOptions
|
|
12103
|
-
);
|
|
12104
|
-
}
|
|
12105
|
-
} else if (this.options.allowBooleanAttributes) {
|
|
12106
|
-
attrs[aName] = true;
|
|
12107
|
-
}
|
|
12108
|
-
}
|
|
12109
|
-
}
|
|
12110
|
-
if (!Object.keys(attrs).length) {
|
|
12111
|
-
return;
|
|
12112
|
-
}
|
|
12113
|
-
if (this.options.attributesGroupName) {
|
|
12114
|
-
const attrCollection = {};
|
|
12115
|
-
attrCollection[this.options.attributesGroupName] = attrs;
|
|
12116
|
-
return attrCollection;
|
|
12117
|
-
}
|
|
12118
|
-
return attrs
|
|
12119
|
-
}
|
|
12120
|
-
}
|
|
12121
|
-
|
|
12122
|
-
const parseXml = function(xmlData) {
|
|
12123
|
-
xmlData = xmlData.replace(/\r\n?/g, "\n"); //TODO: remove this line
|
|
12124
|
-
const xmlObj = new xmlNode('!xml');
|
|
12125
|
-
let currentNode = xmlObj;
|
|
12126
|
-
let textData = "";
|
|
12127
|
-
let jPath = "";
|
|
12128
|
-
for(let i=0; i< xmlData.length; i++){//for each char in XML data
|
|
12129
|
-
const ch = xmlData[i];
|
|
12130
|
-
if(ch === '<'){
|
|
12131
|
-
// const nextIndex = i+1;
|
|
12132
|
-
// const _2ndChar = xmlData[nextIndex];
|
|
12133
|
-
if( xmlData[i+1] === '/') {//Closing Tag
|
|
12134
|
-
const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.");
|
|
12135
|
-
let tagName = xmlData.substring(i+2,closeIndex).trim();
|
|
12136
|
-
|
|
12137
|
-
if(this.options.removeNSPrefix){
|
|
12138
|
-
const colonIndex = tagName.indexOf(":");
|
|
12139
|
-
if(colonIndex !== -1){
|
|
12140
|
-
tagName = tagName.substr(colonIndex+1);
|
|
12141
|
-
}
|
|
12142
|
-
}
|
|
12143
|
-
|
|
12144
|
-
if(this.options.transformTagName) {
|
|
12145
|
-
tagName = this.options.transformTagName(tagName);
|
|
12146
|
-
}
|
|
12147
|
-
|
|
12148
|
-
if(currentNode){
|
|
12149
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
12150
|
-
}
|
|
12151
|
-
|
|
12152
|
-
//check if last tag of nested tag was unpaired tag
|
|
12153
|
-
const lastTagName = jPath.substring(jPath.lastIndexOf(".")+1);
|
|
12154
|
-
if(tagName && this.options.unpairedTags.indexOf(tagName) !== -1 ){
|
|
12155
|
-
throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
|
|
12156
|
-
}
|
|
12157
|
-
let propIndex = 0;
|
|
12158
|
-
if(lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1 ){
|
|
12159
|
-
propIndex = jPath.lastIndexOf('.', jPath.lastIndexOf('.')-1);
|
|
12160
|
-
this.tagsNodeStack.pop();
|
|
12161
|
-
}else {
|
|
12162
|
-
propIndex = jPath.lastIndexOf(".");
|
|
12163
|
-
}
|
|
12164
|
-
jPath = jPath.substring(0, propIndex);
|
|
12165
|
-
|
|
12166
|
-
currentNode = this.tagsNodeStack.pop();//avoid recursion, set the parent tag scope
|
|
12167
|
-
textData = "";
|
|
12168
|
-
i = closeIndex;
|
|
12169
|
-
} else if( xmlData[i+1] === '?') {
|
|
12170
|
-
|
|
12171
|
-
let tagData = readTagExp(xmlData,i, false, "?>");
|
|
12172
|
-
if(!tagData) throw new Error("Pi Tag is not closed.");
|
|
12173
|
-
|
|
12174
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
12175
|
-
if( (this.options.ignoreDeclaration && tagData.tagName === "?xml") || this.options.ignorePiTags);else {
|
|
12176
|
-
|
|
12177
|
-
const childNode = new xmlNode(tagData.tagName);
|
|
12178
|
-
childNode.add(this.options.textNodeName, "");
|
|
12179
|
-
|
|
12180
|
-
if(tagData.tagName !== tagData.tagExp && tagData.attrExpPresent){
|
|
12181
|
-
childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName);
|
|
12182
|
-
}
|
|
12183
|
-
this.addChild(currentNode, childNode, jPath);
|
|
12184
|
-
|
|
12185
|
-
}
|
|
12186
|
-
|
|
12187
|
-
|
|
12188
|
-
i = tagData.closeIndex + 1;
|
|
12189
|
-
} else if(xmlData.substr(i + 1, 3) === '!--') {
|
|
12190
|
-
const endIndex = findClosingIndex(xmlData, "-->", i+4, "Comment is not closed.");
|
|
12191
|
-
if(this.options.commentPropName){
|
|
12192
|
-
const comment = xmlData.substring(i + 4, endIndex - 2);
|
|
12193
|
-
|
|
12194
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
12195
|
-
|
|
12196
|
-
currentNode.add(this.options.commentPropName, [ { [this.options.textNodeName] : comment } ]);
|
|
12197
|
-
}
|
|
12198
|
-
i = endIndex;
|
|
12199
|
-
} else if( xmlData.substr(i + 1, 2) === '!D') {
|
|
12200
|
-
const result = readDocType(xmlData, i);
|
|
12201
|
-
this.docTypeEntities = result.entities;
|
|
12202
|
-
i = result.i;
|
|
12203
|
-
}else if(xmlData.substr(i + 1, 2) === '![') {
|
|
12204
|
-
const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
|
|
12205
|
-
const tagExp = xmlData.substring(i + 9,closeIndex);
|
|
12206
|
-
|
|
12207
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
12208
|
-
|
|
12209
|
-
let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true, true);
|
|
12210
|
-
if(val == undefined) val = "";
|
|
12211
|
-
|
|
12212
|
-
//cdata should be set even if it is 0 length string
|
|
12213
|
-
if(this.options.cdataPropName){
|
|
12214
|
-
currentNode.add(this.options.cdataPropName, [ { [this.options.textNodeName] : tagExp } ]);
|
|
12215
|
-
}else {
|
|
12216
|
-
currentNode.add(this.options.textNodeName, val);
|
|
12217
|
-
}
|
|
12218
|
-
|
|
12219
|
-
i = closeIndex + 2;
|
|
12220
|
-
}else {//Opening tag
|
|
12221
|
-
let result = readTagExp(xmlData,i, this.options.removeNSPrefix);
|
|
12222
|
-
let tagName= result.tagName;
|
|
12223
|
-
const rawTagName = result.rawTagName;
|
|
12224
|
-
let tagExp = result.tagExp;
|
|
12225
|
-
let attrExpPresent = result.attrExpPresent;
|
|
12226
|
-
let closeIndex = result.closeIndex;
|
|
12227
|
-
|
|
12228
|
-
if (this.options.transformTagName) {
|
|
12229
|
-
tagName = this.options.transformTagName(tagName);
|
|
12230
|
-
}
|
|
12231
|
-
|
|
12232
|
-
//save text as child node
|
|
12233
|
-
if (currentNode && textData) {
|
|
12234
|
-
if(currentNode.tagname !== '!xml'){
|
|
12235
|
-
//when nested tag is found
|
|
12236
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath, false);
|
|
12237
|
-
}
|
|
12238
|
-
}
|
|
12239
|
-
|
|
12240
|
-
//check if last tag was unpaired tag
|
|
12241
|
-
const lastTag = currentNode;
|
|
12242
|
-
if(lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1 ){
|
|
12243
|
-
currentNode = this.tagsNodeStack.pop();
|
|
12244
|
-
jPath = jPath.substring(0, jPath.lastIndexOf("."));
|
|
12245
|
-
}
|
|
12246
|
-
if(tagName !== xmlObj.tagname){
|
|
12247
|
-
jPath += jPath ? "." + tagName : tagName;
|
|
12248
|
-
}
|
|
12249
|
-
if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {
|
|
12250
|
-
let tagContent = "";
|
|
12251
|
-
//self-closing tag
|
|
12252
|
-
if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){
|
|
12253
|
-
if(tagName[tagName.length - 1] === "/"){ //remove trailing '/'
|
|
12254
|
-
tagName = tagName.substr(0, tagName.length - 1);
|
|
12255
|
-
jPath = jPath.substr(0, jPath.length - 1);
|
|
12256
|
-
tagExp = tagName;
|
|
12257
|
-
}else {
|
|
12258
|
-
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
12259
|
-
}
|
|
12260
|
-
i = result.closeIndex;
|
|
12261
|
-
}
|
|
12262
|
-
//unpaired tag
|
|
12263
|
-
else if(this.options.unpairedTags.indexOf(tagName) !== -1){
|
|
12264
|
-
|
|
12265
|
-
i = result.closeIndex;
|
|
12266
|
-
}
|
|
12267
|
-
//normal tag
|
|
12268
|
-
else {
|
|
12269
|
-
//read until closing tag is found
|
|
12270
|
-
const result = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
|
|
12271
|
-
if(!result) throw new Error(`Unexpected end of ${rawTagName}`);
|
|
12272
|
-
i = result.i;
|
|
12273
|
-
tagContent = result.tagContent;
|
|
12274
|
-
}
|
|
12275
|
-
|
|
12276
|
-
const childNode = new xmlNode(tagName);
|
|
12277
|
-
if(tagName !== tagExp && attrExpPresent){
|
|
12278
|
-
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
12279
|
-
}
|
|
12280
|
-
if(tagContent) {
|
|
12281
|
-
tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
|
|
12282
|
-
}
|
|
12283
|
-
|
|
12284
|
-
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
12285
|
-
childNode.add(this.options.textNodeName, tagContent);
|
|
12286
|
-
|
|
12287
|
-
this.addChild(currentNode, childNode, jPath);
|
|
12288
|
-
}else {
|
|
12289
|
-
//selfClosing tag
|
|
12290
|
-
if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){
|
|
12291
|
-
if(tagName[tagName.length - 1] === "/"){ //remove trailing '/'
|
|
12292
|
-
tagName = tagName.substr(0, tagName.length - 1);
|
|
12293
|
-
jPath = jPath.substr(0, jPath.length - 1);
|
|
12294
|
-
tagExp = tagName;
|
|
12295
|
-
}else {
|
|
12296
|
-
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
12297
|
-
}
|
|
12298
|
-
|
|
12299
|
-
if(this.options.transformTagName) {
|
|
12300
|
-
tagName = this.options.transformTagName(tagName);
|
|
12301
|
-
}
|
|
12302
|
-
|
|
12303
|
-
const childNode = new xmlNode(tagName);
|
|
12304
|
-
if(tagName !== tagExp && attrExpPresent){
|
|
12305
|
-
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
12306
|
-
}
|
|
12307
|
-
this.addChild(currentNode, childNode, jPath);
|
|
12308
|
-
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
12309
|
-
}
|
|
12310
|
-
//opening tag
|
|
12311
|
-
else {
|
|
12312
|
-
const childNode = new xmlNode( tagName);
|
|
12313
|
-
this.tagsNodeStack.push(currentNode);
|
|
12314
|
-
|
|
12315
|
-
if(tagName !== tagExp && attrExpPresent){
|
|
12316
|
-
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
12317
|
-
}
|
|
12318
|
-
this.addChild(currentNode, childNode, jPath);
|
|
12319
|
-
currentNode = childNode;
|
|
12320
|
-
}
|
|
12321
|
-
textData = "";
|
|
12322
|
-
i = closeIndex;
|
|
12323
|
-
}
|
|
12324
|
-
}
|
|
12325
|
-
}else {
|
|
12326
|
-
textData += xmlData[i];
|
|
12327
|
-
}
|
|
12328
|
-
}
|
|
12329
|
-
return xmlObj.child;
|
|
12330
|
-
};
|
|
12331
|
-
|
|
12332
|
-
function addChild(currentNode, childNode, jPath){
|
|
12333
|
-
const result = this.options.updateTag(childNode.tagname, jPath, childNode[":@"]);
|
|
12334
|
-
if(result === false);else if(typeof result === "string"){
|
|
12335
|
-
childNode.tagname = result;
|
|
12336
|
-
currentNode.addChild(childNode);
|
|
12337
|
-
}else {
|
|
12338
|
-
currentNode.addChild(childNode);
|
|
12339
|
-
}
|
|
12340
|
-
}
|
|
12341
|
-
|
|
12342
|
-
const replaceEntitiesValue$1 = function(val){
|
|
12343
|
-
|
|
12344
|
-
if(this.options.processEntities){
|
|
12345
|
-
for(let entityName in this.docTypeEntities){
|
|
12346
|
-
const entity = this.docTypeEntities[entityName];
|
|
12347
|
-
val = val.replace( entity.regx, entity.val);
|
|
12348
|
-
}
|
|
12349
|
-
for(let entityName in this.lastEntities){
|
|
12350
|
-
const entity = this.lastEntities[entityName];
|
|
12351
|
-
val = val.replace( entity.regex, entity.val);
|
|
12352
|
-
}
|
|
12353
|
-
if(this.options.htmlEntities){
|
|
12354
|
-
for(let entityName in this.htmlEntities){
|
|
12355
|
-
const entity = this.htmlEntities[entityName];
|
|
12356
|
-
val = val.replace( entity.regex, entity.val);
|
|
12357
|
-
}
|
|
12358
|
-
}
|
|
12359
|
-
val = val.replace( this.ampEntity.regex, this.ampEntity.val);
|
|
12360
|
-
}
|
|
12361
|
-
return val;
|
|
12362
|
-
};
|
|
12363
|
-
function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {
|
|
12364
|
-
if (textData) { //store previously collected data as textNode
|
|
12365
|
-
if(isLeafNode === undefined) isLeafNode = currentNode.child.length === 0;
|
|
12366
|
-
|
|
12367
|
-
textData = this.parseTextData(textData,
|
|
12368
|
-
currentNode.tagname,
|
|
12369
|
-
jPath,
|
|
12370
|
-
false,
|
|
12371
|
-
currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false,
|
|
12372
|
-
isLeafNode);
|
|
12373
|
-
|
|
12374
|
-
if (textData !== undefined && textData !== "")
|
|
12375
|
-
currentNode.add(this.options.textNodeName, textData);
|
|
12376
|
-
textData = "";
|
|
12377
|
-
}
|
|
12378
|
-
return textData;
|
|
12379
|
-
}
|
|
12380
|
-
|
|
12381
|
-
//TODO: use jPath to simplify the logic
|
|
12382
|
-
/**
|
|
12383
|
-
*
|
|
12384
|
-
* @param {string[]} stopNodes
|
|
12385
|
-
* @param {string} jPath
|
|
12386
|
-
* @param {string} currentTagName
|
|
12387
|
-
*/
|
|
12388
|
-
function isItStopNode(stopNodes, jPath, currentTagName){
|
|
12389
|
-
const allNodesExp = "*." + currentTagName;
|
|
12390
|
-
for (const stopNodePath in stopNodes) {
|
|
12391
|
-
const stopNodeExp = stopNodes[stopNodePath];
|
|
12392
|
-
if( allNodesExp === stopNodeExp || jPath === stopNodeExp ) return true;
|
|
12393
|
-
}
|
|
12394
|
-
return false;
|
|
12395
|
-
}
|
|
12396
|
-
|
|
12397
|
-
/**
|
|
12398
|
-
* Returns the tag Expression and where it is ending handling single-double quotes situation
|
|
12399
|
-
* @param {string} xmlData
|
|
12400
|
-
* @param {number} i starting index
|
|
12401
|
-
* @returns
|
|
12402
|
-
*/
|
|
12403
|
-
function tagExpWithClosingIndex(xmlData, i, closingChar = ">"){
|
|
12404
|
-
let attrBoundary;
|
|
12405
|
-
let tagExp = "";
|
|
12406
|
-
for (let index = i; index < xmlData.length; index++) {
|
|
12407
|
-
let ch = xmlData[index];
|
|
12408
|
-
if (attrBoundary) {
|
|
12409
|
-
if (ch === attrBoundary) attrBoundary = "";//reset
|
|
12410
|
-
} else if (ch === '"' || ch === "'") {
|
|
12411
|
-
attrBoundary = ch;
|
|
12412
|
-
} else if (ch === closingChar[0]) {
|
|
12413
|
-
if(closingChar[1]){
|
|
12414
|
-
if(xmlData[index + 1] === closingChar[1]){
|
|
12415
|
-
return {
|
|
12416
|
-
data: tagExp,
|
|
12417
|
-
index: index
|
|
12418
|
-
}
|
|
12419
|
-
}
|
|
12420
|
-
}else {
|
|
12421
|
-
return {
|
|
12422
|
-
data: tagExp,
|
|
12423
|
-
index: index
|
|
12424
|
-
}
|
|
12425
|
-
}
|
|
12426
|
-
} else if (ch === '\t') {
|
|
12427
|
-
ch = " ";
|
|
12428
|
-
}
|
|
12429
|
-
tagExp += ch;
|
|
12430
|
-
}
|
|
12431
|
-
}
|
|
12432
|
-
|
|
12433
|
-
function findClosingIndex(xmlData, str, i, errMsg){
|
|
12434
|
-
const closingIndex = xmlData.indexOf(str, i);
|
|
12435
|
-
if(closingIndex === -1){
|
|
12436
|
-
throw new Error(errMsg)
|
|
12437
|
-
}else {
|
|
12438
|
-
return closingIndex + str.length - 1;
|
|
12439
|
-
}
|
|
12440
|
-
}
|
|
12441
|
-
|
|
12442
|
-
function readTagExp(xmlData,i, removeNSPrefix, closingChar = ">"){
|
|
12443
|
-
const result = tagExpWithClosingIndex(xmlData, i+1, closingChar);
|
|
12444
|
-
if(!result) return;
|
|
12445
|
-
let tagExp = result.data;
|
|
12446
|
-
const closeIndex = result.index;
|
|
12447
|
-
const separatorIndex = tagExp.search(/\s/);
|
|
12448
|
-
let tagName = tagExp;
|
|
12449
|
-
let attrExpPresent = true;
|
|
12450
|
-
if(separatorIndex !== -1){//separate tag name and attributes expression
|
|
12451
|
-
tagName = tagExp.substring(0, separatorIndex);
|
|
12452
|
-
tagExp = tagExp.substring(separatorIndex + 1).trimStart();
|
|
12453
|
-
}
|
|
12454
|
-
|
|
12455
|
-
const rawTagName = tagName;
|
|
12456
|
-
if(removeNSPrefix){
|
|
12457
|
-
const colonIndex = tagName.indexOf(":");
|
|
12458
|
-
if(colonIndex !== -1){
|
|
12459
|
-
tagName = tagName.substr(colonIndex+1);
|
|
12460
|
-
attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
|
|
12461
|
-
}
|
|
12462
|
-
}
|
|
12463
|
-
|
|
12464
|
-
return {
|
|
12465
|
-
tagName: tagName,
|
|
12466
|
-
tagExp: tagExp,
|
|
12467
|
-
closeIndex: closeIndex,
|
|
12468
|
-
attrExpPresent: attrExpPresent,
|
|
12469
|
-
rawTagName: rawTagName,
|
|
12470
|
-
}
|
|
12471
|
-
}
|
|
12472
|
-
/**
|
|
12473
|
-
* find paired tag for a stop node
|
|
12474
|
-
* @param {string} xmlData
|
|
12475
|
-
* @param {string} tagName
|
|
12476
|
-
* @param {number} i
|
|
12477
|
-
*/
|
|
12478
|
-
function readStopNodeData(xmlData, tagName, i){
|
|
12479
|
-
const startIndex = i;
|
|
12480
|
-
// Starting at 1 since we already have an open tag
|
|
12481
|
-
let openTagCount = 1;
|
|
12482
|
-
|
|
12483
|
-
for (; i < xmlData.length; i++) {
|
|
12484
|
-
if( xmlData[i] === "<"){
|
|
12485
|
-
if (xmlData[i+1] === "/") {//close tag
|
|
12486
|
-
const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
|
|
12487
|
-
let closeTagName = xmlData.substring(i+2,closeIndex).trim();
|
|
12488
|
-
if(closeTagName === tagName){
|
|
12489
|
-
openTagCount--;
|
|
12490
|
-
if (openTagCount === 0) {
|
|
12491
|
-
return {
|
|
12492
|
-
tagContent: xmlData.substring(startIndex, i),
|
|
12493
|
-
i : closeIndex
|
|
12494
|
-
}
|
|
12495
|
-
}
|
|
12496
|
-
}
|
|
12497
|
-
i=closeIndex;
|
|
12498
|
-
} else if(xmlData[i+1] === '?') {
|
|
12499
|
-
const closeIndex = findClosingIndex(xmlData, "?>", i+1, "StopNode is not closed.");
|
|
12500
|
-
i=closeIndex;
|
|
12501
|
-
} else if(xmlData.substr(i + 1, 3) === '!--') {
|
|
12502
|
-
const closeIndex = findClosingIndex(xmlData, "-->", i+3, "StopNode is not closed.");
|
|
12503
|
-
i=closeIndex;
|
|
12504
|
-
} else if(xmlData.substr(i + 1, 2) === '![') {
|
|
12505
|
-
const closeIndex = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
|
|
12506
|
-
i=closeIndex;
|
|
12507
|
-
} else {
|
|
12508
|
-
const tagData = readTagExp(xmlData, i, '>');
|
|
12509
|
-
|
|
12510
|
-
if (tagData) {
|
|
12511
|
-
const openTagName = tagData && tagData.tagName;
|
|
12512
|
-
if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length-1] !== "/") {
|
|
12513
|
-
openTagCount++;
|
|
12514
|
-
}
|
|
12515
|
-
i=tagData.closeIndex;
|
|
12516
|
-
}
|
|
12517
|
-
}
|
|
12518
|
-
}
|
|
12519
|
-
}//end for loop
|
|
12520
|
-
}
|
|
12521
|
-
|
|
12522
|
-
function parseValue(val, shouldParse, options) {
|
|
12523
|
-
if (shouldParse && typeof val === 'string') {
|
|
12524
|
-
//console.log(options)
|
|
12525
|
-
const newval = val.trim();
|
|
12526
|
-
if(newval === 'true' ) return true;
|
|
12527
|
-
else if(newval === 'false' ) return false;
|
|
12528
|
-
else return toNumber(val, options);
|
|
12529
|
-
} else {
|
|
12530
|
-
if (util$2.isExist(val)) {
|
|
12531
|
-
return val;
|
|
12532
|
-
} else {
|
|
12533
|
-
return '';
|
|
12534
|
-
}
|
|
12535
|
-
}
|
|
12536
|
-
}
|
|
12537
|
-
|
|
12538
|
-
|
|
12539
|
-
var OrderedObjParser_1 = OrderedObjParser$1;
|
|
12540
|
-
|
|
12541
|
-
var node2json = {};
|
|
12542
|
-
|
|
12543
|
-
/**
|
|
12544
|
-
*
|
|
12545
|
-
* @param {array} node
|
|
12546
|
-
* @param {any} options
|
|
12547
|
-
* @returns
|
|
12548
|
-
*/
|
|
12549
|
-
function prettify$1(node, options){
|
|
12550
|
-
return compress( node, options);
|
|
12551
|
-
}
|
|
12552
|
-
|
|
12553
|
-
/**
|
|
12554
|
-
*
|
|
12555
|
-
* @param {array} arr
|
|
12556
|
-
* @param {object} options
|
|
12557
|
-
* @param {string} jPath
|
|
12558
|
-
* @returns object
|
|
12559
|
-
*/
|
|
12560
|
-
function compress(arr, options, jPath){
|
|
12561
|
-
let text;
|
|
12562
|
-
const compressedObj = {};
|
|
12563
|
-
for (let i = 0; i < arr.length; i++) {
|
|
12564
|
-
const tagObj = arr[i];
|
|
12565
|
-
const property = propName$1(tagObj);
|
|
12566
|
-
let newJpath = "";
|
|
12567
|
-
if(jPath === undefined) newJpath = property;
|
|
12568
|
-
else newJpath = jPath + "." + property;
|
|
12569
|
-
|
|
12570
|
-
if(property === options.textNodeName){
|
|
12571
|
-
if(text === undefined) text = tagObj[property];
|
|
12572
|
-
else text += "" + tagObj[property];
|
|
12573
|
-
}else if(property === undefined){
|
|
12574
|
-
continue;
|
|
12575
|
-
}else if(tagObj[property]){
|
|
12576
|
-
|
|
12577
|
-
let val = compress(tagObj[property], options, newJpath);
|
|
12578
|
-
const isLeaf = isLeafTag(val, options);
|
|
12579
|
-
|
|
12580
|
-
if(tagObj[":@"]){
|
|
12581
|
-
assignAttributes( val, tagObj[":@"], newJpath, options);
|
|
12582
|
-
}else if(Object.keys(val).length === 1 && val[options.textNodeName] !== undefined && !options.alwaysCreateTextNode){
|
|
12583
|
-
val = val[options.textNodeName];
|
|
12584
|
-
}else if(Object.keys(val).length === 0){
|
|
12585
|
-
if(options.alwaysCreateTextNode) val[options.textNodeName] = "";
|
|
12586
|
-
else val = "";
|
|
12587
|
-
}
|
|
12588
|
-
|
|
12589
|
-
if(compressedObj[property] !== undefined && compressedObj.hasOwnProperty(property)) {
|
|
12590
|
-
if(!Array.isArray(compressedObj[property])) {
|
|
12591
|
-
compressedObj[property] = [ compressedObj[property] ];
|
|
12592
|
-
}
|
|
12593
|
-
compressedObj[property].push(val);
|
|
12594
|
-
}else {
|
|
12595
|
-
//TODO: if a node is not an array, then check if it should be an array
|
|
12596
|
-
//also determine if it is a leaf node
|
|
12597
|
-
if (options.isArray(property, newJpath, isLeaf )) {
|
|
12598
|
-
compressedObj[property] = [val];
|
|
12599
|
-
}else {
|
|
12600
|
-
compressedObj[property] = val;
|
|
12601
|
-
}
|
|
12602
|
-
}
|
|
12603
|
-
}
|
|
12604
|
-
|
|
12605
|
-
}
|
|
12606
|
-
// if(text && text.length > 0) compressedObj[options.textNodeName] = text;
|
|
12607
|
-
if(typeof text === "string"){
|
|
12608
|
-
if(text.length > 0) compressedObj[options.textNodeName] = text;
|
|
12609
|
-
}else if(text !== undefined) compressedObj[options.textNodeName] = text;
|
|
12610
|
-
return compressedObj;
|
|
12611
|
-
}
|
|
12612
|
-
|
|
12613
|
-
function propName$1(obj){
|
|
12614
|
-
const keys = Object.keys(obj);
|
|
12615
|
-
for (let i = 0; i < keys.length; i++) {
|
|
12616
|
-
const key = keys[i];
|
|
12617
|
-
if(key !== ":@") return key;
|
|
12618
|
-
}
|
|
12619
|
-
}
|
|
12620
|
-
|
|
12621
|
-
function assignAttributes(obj, attrMap, jpath, options){
|
|
12622
|
-
if (attrMap) {
|
|
12623
|
-
const keys = Object.keys(attrMap);
|
|
12624
|
-
const len = keys.length; //don't make it inline
|
|
12625
|
-
for (let i = 0; i < len; i++) {
|
|
12626
|
-
const atrrName = keys[i];
|
|
12627
|
-
if (options.isArray(atrrName, jpath + "." + atrrName, true, true)) {
|
|
12628
|
-
obj[atrrName] = [ attrMap[atrrName] ];
|
|
12629
|
-
} else {
|
|
12630
|
-
obj[atrrName] = attrMap[atrrName];
|
|
12631
|
-
}
|
|
12632
|
-
}
|
|
12633
|
-
}
|
|
12634
|
-
}
|
|
12635
|
-
|
|
12636
|
-
function isLeafTag(obj, options){
|
|
12637
|
-
const { textNodeName } = options;
|
|
12638
|
-
const propCount = Object.keys(obj).length;
|
|
12639
|
-
|
|
12640
|
-
if (propCount === 0) {
|
|
12641
|
-
return true;
|
|
12642
|
-
}
|
|
12643
|
-
|
|
12644
|
-
if (
|
|
12645
|
-
propCount === 1 &&
|
|
12646
|
-
(obj[textNodeName] || typeof obj[textNodeName] === "boolean" || obj[textNodeName] === 0)
|
|
12647
|
-
) {
|
|
12648
|
-
return true;
|
|
12649
|
-
}
|
|
12650
|
-
|
|
12651
|
-
return false;
|
|
12652
|
-
}
|
|
12653
|
-
node2json.prettify = prettify$1;
|
|
12654
|
-
|
|
12655
|
-
const { buildOptions} = OptionsBuilder;
|
|
12656
|
-
const OrderedObjParser = OrderedObjParser_1;
|
|
12657
|
-
const { prettify} = node2json;
|
|
12658
|
-
const validator$1 = validator$2;
|
|
12659
|
-
|
|
12660
|
-
let XMLParser$1 = class XMLParser{
|
|
12661
|
-
|
|
12662
|
-
constructor(options){
|
|
12663
|
-
this.externalEntities = {};
|
|
12664
|
-
this.options = buildOptions(options);
|
|
12665
|
-
|
|
12666
|
-
}
|
|
12667
|
-
/**
|
|
12668
|
-
* Parse XML dats to JS object
|
|
12669
|
-
* @param {string|Buffer} xmlData
|
|
12670
|
-
* @param {boolean|Object} validationOption
|
|
12671
|
-
*/
|
|
12672
|
-
parse(xmlData,validationOption){
|
|
12673
|
-
if(typeof xmlData === "string");else if( xmlData.toString){
|
|
12674
|
-
xmlData = xmlData.toString();
|
|
12675
|
-
}else {
|
|
12676
|
-
throw new Error("XML data is accepted in String or Bytes[] form.")
|
|
12677
|
-
}
|
|
12678
|
-
if( validationOption){
|
|
12679
|
-
if(validationOption === true) validationOption = {}; //validate with default options
|
|
12680
|
-
|
|
12681
|
-
const result = validator$1.validate(xmlData, validationOption);
|
|
12682
|
-
if (result !== true) {
|
|
12683
|
-
throw Error( `${result.err.msg}:${result.err.line}:${result.err.col}` )
|
|
12684
|
-
}
|
|
12685
|
-
}
|
|
12686
|
-
const orderedObjParser = new OrderedObjParser(this.options);
|
|
12687
|
-
orderedObjParser.addExternalEntities(this.externalEntities);
|
|
12688
|
-
const orderedResult = orderedObjParser.parseXml(xmlData);
|
|
12689
|
-
if(this.options.preserveOrder || orderedResult === undefined) return orderedResult;
|
|
12690
|
-
else return prettify(orderedResult, this.options);
|
|
12691
|
-
}
|
|
12692
|
-
|
|
12693
|
-
/**
|
|
12694
|
-
* Add Entity which is not by default supported by this library
|
|
12695
|
-
* @param {string} key
|
|
12696
|
-
* @param {string} value
|
|
12697
|
-
*/
|
|
12698
|
-
addEntity(key, value){
|
|
12699
|
-
if(value.indexOf("&") !== -1){
|
|
12700
|
-
throw new Error("Entity value can't have '&'")
|
|
12701
|
-
}else if(key.indexOf("&") !== -1 || key.indexOf(";") !== -1){
|
|
12702
|
-
throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'")
|
|
12703
|
-
}else if(value === "&"){
|
|
12704
|
-
throw new Error("An entity with value '&' is not permitted");
|
|
12705
|
-
}else {
|
|
12706
|
-
this.externalEntities[key] = value;
|
|
12707
|
-
}
|
|
12708
|
-
}
|
|
12709
|
-
};
|
|
12710
|
-
|
|
12711
|
-
var XMLParser_1 = XMLParser$1;
|
|
12712
|
-
|
|
12713
|
-
const EOL = "\n";
|
|
12714
|
-
|
|
12715
|
-
/**
|
|
12716
|
-
*
|
|
12717
|
-
* @param {array} jArray
|
|
12718
|
-
* @param {any} options
|
|
12719
|
-
* @returns
|
|
12720
|
-
*/
|
|
12721
|
-
function toXml(jArray, options) {
|
|
12722
|
-
let indentation = "";
|
|
12723
|
-
if (options.format && options.indentBy.length > 0) {
|
|
12724
|
-
indentation = EOL;
|
|
12725
|
-
}
|
|
12726
|
-
return arrToStr(jArray, options, "", indentation);
|
|
12727
|
-
}
|
|
12728
|
-
|
|
12729
|
-
function arrToStr(arr, options, jPath, indentation) {
|
|
12730
|
-
let xmlStr = "";
|
|
12731
|
-
let isPreviousElementTag = false;
|
|
12732
|
-
|
|
12733
|
-
for (let i = 0; i < arr.length; i++) {
|
|
12734
|
-
const tagObj = arr[i];
|
|
12735
|
-
const tagName = propName(tagObj);
|
|
12736
|
-
if(tagName === undefined) continue;
|
|
12737
|
-
|
|
12738
|
-
let newJPath = "";
|
|
12739
|
-
if (jPath.length === 0) newJPath = tagName;
|
|
12740
|
-
else newJPath = `${jPath}.${tagName}`;
|
|
12741
|
-
|
|
12742
|
-
if (tagName === options.textNodeName) {
|
|
12743
|
-
let tagText = tagObj[tagName];
|
|
12744
|
-
if (!isStopNode(newJPath, options)) {
|
|
12745
|
-
tagText = options.tagValueProcessor(tagName, tagText);
|
|
12746
|
-
tagText = replaceEntitiesValue(tagText, options);
|
|
12747
|
-
}
|
|
12748
|
-
if (isPreviousElementTag) {
|
|
12749
|
-
xmlStr += indentation;
|
|
12750
|
-
}
|
|
12751
|
-
xmlStr += tagText;
|
|
12752
|
-
isPreviousElementTag = false;
|
|
12753
|
-
continue;
|
|
12754
|
-
} else if (tagName === options.cdataPropName) {
|
|
12755
|
-
if (isPreviousElementTag) {
|
|
12756
|
-
xmlStr += indentation;
|
|
12757
|
-
}
|
|
12758
|
-
xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
|
|
12759
|
-
isPreviousElementTag = false;
|
|
12760
|
-
continue;
|
|
12761
|
-
} else if (tagName === options.commentPropName) {
|
|
12762
|
-
xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
|
|
12763
|
-
isPreviousElementTag = true;
|
|
12764
|
-
continue;
|
|
12765
|
-
} else if (tagName[0] === "?") {
|
|
12766
|
-
const attStr = attr_to_str(tagObj[":@"], options);
|
|
12767
|
-
const tempInd = tagName === "?xml" ? "" : indentation;
|
|
12768
|
-
let piTextNodeName = tagObj[tagName][0][options.textNodeName];
|
|
12769
|
-
piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : ""; //remove extra spacing
|
|
12770
|
-
xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr}?>`;
|
|
12771
|
-
isPreviousElementTag = true;
|
|
12772
|
-
continue;
|
|
12773
|
-
}
|
|
12774
|
-
let newIdentation = indentation;
|
|
12775
|
-
if (newIdentation !== "") {
|
|
12776
|
-
newIdentation += options.indentBy;
|
|
12777
|
-
}
|
|
12778
|
-
const attStr = attr_to_str(tagObj[":@"], options);
|
|
12779
|
-
const tagStart = indentation + `<${tagName}${attStr}`;
|
|
12780
|
-
const tagValue = arrToStr(tagObj[tagName], options, newJPath, newIdentation);
|
|
12781
|
-
if (options.unpairedTags.indexOf(tagName) !== -1) {
|
|
12782
|
-
if (options.suppressUnpairedNode) xmlStr += tagStart + ">";
|
|
12783
|
-
else xmlStr += tagStart + "/>";
|
|
12784
|
-
} else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) {
|
|
12785
|
-
xmlStr += tagStart + "/>";
|
|
12786
|
-
} else if (tagValue && tagValue.endsWith(">")) {
|
|
12787
|
-
xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;
|
|
12788
|
-
} else {
|
|
12789
|
-
xmlStr += tagStart + ">";
|
|
12790
|
-
if (tagValue && indentation !== "" && (tagValue.includes("/>") || tagValue.includes("</"))) {
|
|
12791
|
-
xmlStr += indentation + options.indentBy + tagValue + indentation;
|
|
12792
|
-
} else {
|
|
12793
|
-
xmlStr += tagValue;
|
|
12794
|
-
}
|
|
12795
|
-
xmlStr += `</${tagName}>`;
|
|
12796
|
-
}
|
|
12797
|
-
isPreviousElementTag = true;
|
|
12798
|
-
}
|
|
12799
|
-
|
|
12800
|
-
return xmlStr;
|
|
12801
|
-
}
|
|
12802
|
-
|
|
12803
|
-
function propName(obj) {
|
|
12804
|
-
const keys = Object.keys(obj);
|
|
12805
|
-
for (let i = 0; i < keys.length; i++) {
|
|
12806
|
-
const key = keys[i];
|
|
12807
|
-
if(!obj.hasOwnProperty(key)) continue;
|
|
12808
|
-
if (key !== ":@") return key;
|
|
12809
|
-
}
|
|
12810
|
-
}
|
|
12811
|
-
|
|
12812
|
-
function attr_to_str(attrMap, options) {
|
|
12813
|
-
let attrStr = "";
|
|
12814
|
-
if (attrMap && !options.ignoreAttributes) {
|
|
12815
|
-
for (let attr in attrMap) {
|
|
12816
|
-
if(!attrMap.hasOwnProperty(attr)) continue;
|
|
12817
|
-
let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
|
|
12818
|
-
attrVal = replaceEntitiesValue(attrVal, options);
|
|
12819
|
-
if (attrVal === true && options.suppressBooleanAttributes) {
|
|
12820
|
-
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
|
|
12821
|
-
} else {
|
|
12822
|
-
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
|
|
12823
|
-
}
|
|
12824
|
-
}
|
|
12825
|
-
}
|
|
12826
|
-
return attrStr;
|
|
12827
|
-
}
|
|
12828
|
-
|
|
12829
|
-
function isStopNode(jPath, options) {
|
|
12830
|
-
jPath = jPath.substr(0, jPath.length - options.textNodeName.length - 1);
|
|
12831
|
-
let tagName = jPath.substr(jPath.lastIndexOf(".") + 1);
|
|
12832
|
-
for (let index in options.stopNodes) {
|
|
12833
|
-
if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName) return true;
|
|
12834
|
-
}
|
|
12835
|
-
return false;
|
|
12836
|
-
}
|
|
12837
|
-
|
|
12838
|
-
function replaceEntitiesValue(textValue, options) {
|
|
12839
|
-
if (textValue && textValue.length > 0 && options.processEntities) {
|
|
12840
|
-
for (let i = 0; i < options.entities.length; i++) {
|
|
12841
|
-
const entity = options.entities[i];
|
|
12842
|
-
textValue = textValue.replace(entity.regex, entity.val);
|
|
12843
|
-
}
|
|
12844
|
-
}
|
|
12845
|
-
return textValue;
|
|
12846
|
-
}
|
|
12847
|
-
var orderedJs2Xml = toXml;
|
|
12848
|
-
|
|
12849
|
-
//parse Empty Node as self closing node
|
|
12850
|
-
const buildFromOrderedJs = orderedJs2Xml;
|
|
12851
|
-
const getIgnoreAttributesFn = ignoreAttributes;
|
|
12852
|
-
|
|
12853
|
-
const defaultOptions = {
|
|
12854
|
-
attributeNamePrefix: '@_',
|
|
12855
|
-
attributesGroupName: false,
|
|
12856
|
-
textNodeName: '#text',
|
|
12857
|
-
ignoreAttributes: true,
|
|
12858
|
-
cdataPropName: false,
|
|
12859
|
-
format: false,
|
|
12860
|
-
indentBy: ' ',
|
|
12861
|
-
suppressEmptyNode: false,
|
|
12862
|
-
suppressUnpairedNode: true,
|
|
12863
|
-
suppressBooleanAttributes: true,
|
|
12864
|
-
tagValueProcessor: function(key, a) {
|
|
12865
|
-
return a;
|
|
12866
|
-
},
|
|
12867
|
-
attributeValueProcessor: function(attrName, a) {
|
|
12868
|
-
return a;
|
|
12869
|
-
},
|
|
12870
|
-
preserveOrder: false,
|
|
12871
|
-
commentPropName: false,
|
|
12872
|
-
unpairedTags: [],
|
|
12873
|
-
entities: [
|
|
12874
|
-
{ regex: new RegExp("&", "g"), val: "&" },//it must be on top
|
|
12875
|
-
{ regex: new RegExp(">", "g"), val: ">" },
|
|
12876
|
-
{ regex: new RegExp("<", "g"), val: "<" },
|
|
12877
|
-
{ regex: new RegExp("\'", "g"), val: "'" },
|
|
12878
|
-
{ regex: new RegExp("\"", "g"), val: """ }
|
|
12879
|
-
],
|
|
12880
|
-
processEntities: true,
|
|
12881
|
-
stopNodes: [],
|
|
12882
|
-
// transformTagName: false,
|
|
12883
|
-
// transformAttributeName: false,
|
|
12884
|
-
oneListGroup: false
|
|
12885
|
-
};
|
|
12886
|
-
|
|
12887
|
-
function Builder(options) {
|
|
12888
|
-
this.options = Object.assign({}, defaultOptions, options);
|
|
12889
|
-
if (this.options.ignoreAttributes === true || this.options.attributesGroupName) {
|
|
12890
|
-
this.isAttribute = function(/*a*/) {
|
|
12891
|
-
return false;
|
|
12892
|
-
};
|
|
12893
|
-
} else {
|
|
12894
|
-
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes);
|
|
12895
|
-
this.attrPrefixLen = this.options.attributeNamePrefix.length;
|
|
12896
|
-
this.isAttribute = isAttribute;
|
|
12897
|
-
}
|
|
12898
|
-
|
|
12899
|
-
this.processTextOrObjNode = processTextOrObjNode;
|
|
12900
|
-
|
|
12901
|
-
if (this.options.format) {
|
|
12902
|
-
this.indentate = indentate;
|
|
12903
|
-
this.tagEndChar = '>\n';
|
|
12904
|
-
this.newLine = '\n';
|
|
12905
|
-
} else {
|
|
12906
|
-
this.indentate = function() {
|
|
12907
|
-
return '';
|
|
12908
|
-
};
|
|
12909
|
-
this.tagEndChar = '>';
|
|
12910
|
-
this.newLine = '';
|
|
12911
|
-
}
|
|
12912
|
-
}
|
|
12913
|
-
|
|
12914
|
-
Builder.prototype.build = function(jObj) {
|
|
12915
|
-
if(this.options.preserveOrder){
|
|
12916
|
-
return buildFromOrderedJs(jObj, this.options);
|
|
12917
|
-
}else {
|
|
12918
|
-
if(Array.isArray(jObj) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1){
|
|
12919
|
-
jObj = {
|
|
12920
|
-
[this.options.arrayNodeName] : jObj
|
|
12921
|
-
};
|
|
12922
|
-
}
|
|
12923
|
-
return this.j2x(jObj, 0, []).val;
|
|
12924
|
-
}
|
|
12925
|
-
};
|
|
12926
|
-
|
|
12927
|
-
Builder.prototype.j2x = function(jObj, level, ajPath) {
|
|
12928
|
-
let attrStr = '';
|
|
12929
|
-
let val = '';
|
|
12930
|
-
const jPath = ajPath.join('.');
|
|
12931
|
-
for (let key in jObj) {
|
|
12932
|
-
if(!Object.prototype.hasOwnProperty.call(jObj, key)) continue;
|
|
12933
|
-
if (typeof jObj[key] === 'undefined') {
|
|
12934
|
-
// supress undefined node only if it is not an attribute
|
|
12935
|
-
if (this.isAttribute(key)) {
|
|
12936
|
-
val += '';
|
|
12937
|
-
}
|
|
12938
|
-
} else if (jObj[key] === null) {
|
|
12939
|
-
// null attribute should be ignored by the attribute list, but should not cause the tag closing
|
|
12940
|
-
if (this.isAttribute(key)) {
|
|
12941
|
-
val += '';
|
|
12942
|
-
} else if (key === this.options.cdataPropName) {
|
|
12943
|
-
val += '';
|
|
12944
|
-
} else if (key[0] === '?') {
|
|
12945
|
-
val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;
|
|
12946
|
-
} else {
|
|
12947
|
-
val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
12948
|
-
}
|
|
12949
|
-
// val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
12950
|
-
} else if (jObj[key] instanceof Date) {
|
|
12951
|
-
val += this.buildTextValNode(jObj[key], key, '', level);
|
|
12952
|
-
} else if (typeof jObj[key] !== 'object') {
|
|
12953
|
-
//premitive type
|
|
12954
|
-
const attr = this.isAttribute(key);
|
|
12955
|
-
if (attr && !this.ignoreAttributesFn(attr, jPath)) {
|
|
12956
|
-
attrStr += this.buildAttrPairStr(attr, '' + jObj[key]);
|
|
12957
|
-
} else if (!attr) {
|
|
12958
|
-
//tag value
|
|
12959
|
-
if (key === this.options.textNodeName) {
|
|
12960
|
-
let newval = this.options.tagValueProcessor(key, '' + jObj[key]);
|
|
12961
|
-
val += this.replaceEntitiesValue(newval);
|
|
12962
|
-
} else {
|
|
12963
|
-
val += this.buildTextValNode(jObj[key], key, '', level);
|
|
12964
|
-
}
|
|
12965
|
-
}
|
|
12966
|
-
} else if (Array.isArray(jObj[key])) {
|
|
12967
|
-
//repeated nodes
|
|
12968
|
-
const arrLen = jObj[key].length;
|
|
12969
|
-
let listTagVal = "";
|
|
12970
|
-
let listTagAttr = "";
|
|
12971
|
-
for (let j = 0; j < arrLen; j++) {
|
|
12972
|
-
const item = jObj[key][j];
|
|
12973
|
-
if (typeof item === 'undefined') ; else if (item === null) {
|
|
12974
|
-
if(key[0] === "?") val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;
|
|
12975
|
-
else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
12976
|
-
// val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
12977
|
-
} else if (typeof item === 'object') {
|
|
12978
|
-
if(this.options.oneListGroup){
|
|
12979
|
-
const result = this.j2x(item, level + 1, ajPath.concat(key));
|
|
12980
|
-
listTagVal += result.val;
|
|
12981
|
-
if (this.options.attributesGroupName && item.hasOwnProperty(this.options.attributesGroupName)) {
|
|
12982
|
-
listTagAttr += result.attrStr;
|
|
12983
|
-
}
|
|
12984
|
-
}else {
|
|
12985
|
-
listTagVal += this.processTextOrObjNode(item, key, level, ajPath);
|
|
12986
|
-
}
|
|
12987
|
-
} else {
|
|
12988
|
-
if (this.options.oneListGroup) {
|
|
12989
|
-
let textValue = this.options.tagValueProcessor(key, item);
|
|
12990
|
-
textValue = this.replaceEntitiesValue(textValue);
|
|
12991
|
-
listTagVal += textValue;
|
|
12992
|
-
} else {
|
|
12993
|
-
listTagVal += this.buildTextValNode(item, key, '', level);
|
|
12994
|
-
}
|
|
12995
|
-
}
|
|
12996
|
-
}
|
|
12997
|
-
if(this.options.oneListGroup){
|
|
12998
|
-
listTagVal = this.buildObjectNode(listTagVal, key, listTagAttr, level);
|
|
12999
|
-
}
|
|
13000
|
-
val += listTagVal;
|
|
13001
|
-
} else {
|
|
13002
|
-
//nested node
|
|
13003
|
-
if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
|
|
13004
|
-
const Ks = Object.keys(jObj[key]);
|
|
13005
|
-
const L = Ks.length;
|
|
13006
|
-
for (let j = 0; j < L; j++) {
|
|
13007
|
-
attrStr += this.buildAttrPairStr(Ks[j], '' + jObj[key][Ks[j]]);
|
|
13008
|
-
}
|
|
13009
|
-
} else {
|
|
13010
|
-
val += this.processTextOrObjNode(jObj[key], key, level, ajPath);
|
|
13011
|
-
}
|
|
13012
|
-
}
|
|
13013
|
-
}
|
|
13014
|
-
return {attrStr: attrStr, val: val};
|
|
13015
|
-
};
|
|
13016
|
-
|
|
13017
|
-
Builder.prototype.buildAttrPairStr = function(attrName, val){
|
|
13018
|
-
val = this.options.attributeValueProcessor(attrName, '' + val);
|
|
13019
|
-
val = this.replaceEntitiesValue(val);
|
|
13020
|
-
if (this.options.suppressBooleanAttributes && val === "true") {
|
|
13021
|
-
return ' ' + attrName;
|
|
13022
|
-
} else return ' ' + attrName + '="' + val + '"';
|
|
13023
|
-
};
|
|
13024
|
-
|
|
13025
|
-
function processTextOrObjNode (object, key, level, ajPath) {
|
|
13026
|
-
const result = this.j2x(object, level + 1, ajPath.concat(key));
|
|
13027
|
-
if (object[this.options.textNodeName] !== undefined && Object.keys(object).length === 1) {
|
|
13028
|
-
return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);
|
|
13029
|
-
} else {
|
|
13030
|
-
return this.buildObjectNode(result.val, key, result.attrStr, level);
|
|
13031
|
-
}
|
|
13032
|
-
}
|
|
13033
|
-
|
|
13034
|
-
Builder.prototype.buildObjectNode = function(val, key, attrStr, level) {
|
|
13035
|
-
if(val === ""){
|
|
13036
|
-
if(key[0] === "?") return this.indentate(level) + '<' + key + attrStr+ '?' + this.tagEndChar;
|
|
13037
|
-
else {
|
|
13038
|
-
return this.indentate(level) + '<' + key + attrStr + this.closeTag(key) + this.tagEndChar;
|
|
13039
|
-
}
|
|
13040
|
-
}else {
|
|
13041
|
-
|
|
13042
|
-
let tagEndExp = '</' + key + this.tagEndChar;
|
|
13043
|
-
let piClosingChar = "";
|
|
13044
|
-
|
|
13045
|
-
if(key[0] === "?") {
|
|
13046
|
-
piClosingChar = "?";
|
|
13047
|
-
tagEndExp = "";
|
|
13048
|
-
}
|
|
13049
|
-
|
|
13050
|
-
// attrStr is an empty string in case the attribute came as undefined or null
|
|
13051
|
-
if ((attrStr || attrStr === '') && val.indexOf('<') === -1) {
|
|
13052
|
-
return ( this.indentate(level) + '<' + key + attrStr + piClosingChar + '>' + val + tagEndExp );
|
|
13053
|
-
} else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
|
|
13054
|
-
return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
13055
|
-
}else {
|
|
13056
|
-
return (
|
|
13057
|
-
this.indentate(level) + '<' + key + attrStr + piClosingChar + this.tagEndChar +
|
|
13058
|
-
val +
|
|
13059
|
-
this.indentate(level) + tagEndExp );
|
|
13060
|
-
}
|
|
13061
|
-
}
|
|
13062
|
-
};
|
|
13063
|
-
|
|
13064
|
-
Builder.prototype.closeTag = function(key){
|
|
13065
|
-
let closeTag = "";
|
|
13066
|
-
if(this.options.unpairedTags.indexOf(key) !== -1){ //unpaired
|
|
13067
|
-
if(!this.options.suppressUnpairedNode) closeTag = "/";
|
|
13068
|
-
}else if(this.options.suppressEmptyNode){ //empty
|
|
13069
|
-
closeTag = "/";
|
|
13070
|
-
}else {
|
|
13071
|
-
closeTag = `></${key}`;
|
|
13072
|
-
}
|
|
13073
|
-
return closeTag;
|
|
13074
|
-
};
|
|
13075
|
-
|
|
13076
|
-
Builder.prototype.buildTextValNode = function(val, key, attrStr, level) {
|
|
13077
|
-
if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
|
|
13078
|
-
return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;
|
|
13079
|
-
}else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
|
|
13080
|
-
return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
13081
|
-
}else if(key[0] === "?") {//PI tag
|
|
13082
|
-
return this.indentate(level) + '<' + key + attrStr+ '?' + this.tagEndChar;
|
|
13083
|
-
}else {
|
|
13084
|
-
let textValue = this.options.tagValueProcessor(key, val);
|
|
13085
|
-
textValue = this.replaceEntitiesValue(textValue);
|
|
13086
|
-
|
|
13087
|
-
if( textValue === ''){
|
|
13088
|
-
return this.indentate(level) + '<' + key + attrStr + this.closeTag(key) + this.tagEndChar;
|
|
13089
|
-
}else {
|
|
13090
|
-
return this.indentate(level) + '<' + key + attrStr + '>' +
|
|
13091
|
-
textValue +
|
|
13092
|
-
'</' + key + this.tagEndChar;
|
|
13093
|
-
}
|
|
13094
|
-
}
|
|
13095
|
-
};
|
|
13096
|
-
|
|
13097
|
-
Builder.prototype.replaceEntitiesValue = function(textValue){
|
|
13098
|
-
if(textValue && textValue.length > 0 && this.options.processEntities){
|
|
13099
|
-
for (let i=0; i<this.options.entities.length; i++) {
|
|
13100
|
-
const entity = this.options.entities[i];
|
|
13101
|
-
textValue = textValue.replace(entity.regex, entity.val);
|
|
13102
|
-
}
|
|
13103
|
-
}
|
|
13104
|
-
return textValue;
|
|
13105
|
-
};
|
|
13106
|
-
|
|
13107
|
-
function indentate(level) {
|
|
13108
|
-
return this.options.indentBy.repeat(level);
|
|
13109
|
-
}
|
|
13110
|
-
|
|
13111
|
-
function isAttribute(name /*, options*/) {
|
|
13112
|
-
if (name.startsWith(this.options.attributeNamePrefix) && name !== this.options.textNodeName) {
|
|
13113
|
-
return name.substr(this.attrPrefixLen);
|
|
13114
|
-
} else {
|
|
13115
|
-
return false;
|
|
13116
|
-
}
|
|
13117
|
-
}
|
|
13118
|
-
|
|
13119
|
-
var json2xml = Builder;
|
|
13120
|
-
|
|
13121
|
-
const validator = validator$2;
|
|
13122
|
-
const XMLParser = XMLParser_1;
|
|
13123
|
-
const XMLBuilder = json2xml;
|
|
13124
|
-
|
|
13125
|
-
var fxp = {
|
|
13126
|
-
XMLParser: XMLParser,
|
|
13127
|
-
XMLValidator: validator,
|
|
13128
|
-
XMLBuilder: XMLBuilder
|
|
13129
|
-
};
|
|
13130
|
-
|
|
13131
|
-
var prompts$3 = {};
|
|
13132
|
-
|
|
13133
|
-
var kleur;
|
|
13134
|
-
var hasRequiredKleur;
|
|
13135
|
-
|
|
13136
|
-
function requireKleur () {
|
|
13137
|
-
if (hasRequiredKleur) return kleur;
|
|
13138
|
-
hasRequiredKleur = 1;
|
|
13139
|
-
|
|
13140
|
-
const { FORCE_COLOR, NODE_DISABLE_COLORS, TERM } = process.env;
|
|
13141
|
-
|
|
13142
|
-
const $ = {
|
|
13143
|
-
enabled: !NODE_DISABLE_COLORS && TERM !== 'dumb' && FORCE_COLOR !== '0',
|
|
11570
|
+
const $ = {
|
|
11571
|
+
enabled: !NODE_DISABLE_COLORS && TERM !== 'dumb' && FORCE_COLOR !== '0',
|
|
13144
11572
|
|
|
13145
11573
|
// modifiers
|
|
13146
11574
|
reset: init(0, 0),
|
|
@@ -13625,7 +12053,7 @@ function requirePrompt$1 () {
|
|
|
13625
12053
|
const _require = requireUtil$1(),
|
|
13626
12054
|
action = _require.action;
|
|
13627
12055
|
|
|
13628
|
-
const EventEmitter = require$$2
|
|
12056
|
+
const EventEmitter = require$$2;
|
|
13629
12057
|
|
|
13630
12058
|
const _require2 = requireSrc(),
|
|
13631
12059
|
beep = _require2.beep,
|
|
@@ -16096,9 +14524,9 @@ var hasRequiredPrompts$1;
|
|
|
16096
14524
|
function requirePrompts$1 () {
|
|
16097
14525
|
if (hasRequiredPrompts$1) return prompts$3;
|
|
16098
14526
|
hasRequiredPrompts$1 = 1;
|
|
16099
|
-
(function (exports
|
|
14527
|
+
(function (exports) {
|
|
16100
14528
|
|
|
16101
|
-
const $ = exports
|
|
14529
|
+
const $ = exports;
|
|
16102
14530
|
|
|
16103
14531
|
const el = requireElements$1();
|
|
16104
14532
|
|
|
@@ -16787,7 +15215,7 @@ function requirePrompt () {
|
|
|
16787
15215
|
|
|
16788
15216
|
const readline = require$$0$3;
|
|
16789
15217
|
const { action } = requireUtil();
|
|
16790
|
-
const EventEmitter = require$$2
|
|
15218
|
+
const EventEmitter = require$$2;
|
|
16791
15219
|
const { beep, cursor } = requireSrc();
|
|
16792
15220
|
const color = requireKleur();
|
|
16793
15221
|
|
|
@@ -19064,8 +17492,8 @@ var hasRequiredPrompts;
|
|
|
19064
17492
|
function requirePrompts () {
|
|
19065
17493
|
if (hasRequiredPrompts) return prompts$2;
|
|
19066
17494
|
hasRequiredPrompts = 1;
|
|
19067
|
-
(function (exports
|
|
19068
|
-
const $ = exports
|
|
17495
|
+
(function (exports) {
|
|
17496
|
+
const $ = exports;
|
|
19069
17497
|
const el = requireElements();
|
|
19070
17498
|
const noop = v => v;
|
|
19071
17499
|
|
|
@@ -19403,1015 +17831,292 @@ var prompts$1 = /*@__PURE__*/getDefaultExportFromCjs(prompts);
|
|
|
19403
17831
|
* This source code is licensed under the MIT license found in the
|
|
19404
17832
|
* LICENSE file in the root directory of this source tree.
|
|
19405
17833
|
*/
|
|
19406
|
-
|
|
19407
|
-
|
|
19408
|
-
|
|
19409
|
-
|
|
19410
|
-
|
|
19411
|
-
|
|
19412
|
-
|
|
19413
|
-
|
|
19414
|
-
|
|
19415
|
-
|
|
19416
|
-
|
|
19417
|
-
}
|
|
19418
|
-
async function fetchAppcastRelease(platform) {
|
|
19419
|
-
try {
|
|
19420
|
-
const response = await fetch(getAppcastUrl(platform), {
|
|
19421
|
-
signal: AbortSignal.timeout(30000),
|
|
19422
|
-
});
|
|
19423
|
-
if (!response.ok) {
|
|
19424
|
-
console.warn(chalk.yellow(`Warning: Failed to fetch appcast: HTTP ${response.status}`));
|
|
19425
|
-
return null;
|
|
19426
|
-
}
|
|
19427
|
-
const xmlContent = await response.text();
|
|
19428
|
-
const parser = new fxp.XMLParser({
|
|
19429
|
-
ignoreAttributes: false,
|
|
19430
|
-
attributeNamePrefix: '@_',
|
|
19431
|
-
});
|
|
19432
|
-
const parsed = parser.parse(xmlContent);
|
|
19433
|
-
// Navigate to enclosure element: rss > channel > item > enclosure
|
|
19434
|
-
const channel = parsed?.rss?.channel;
|
|
19435
|
-
if (!channel) {
|
|
19436
|
-
console.warn(chalk.yellow('Warning: Invalid appcast format - missing channel'));
|
|
19437
|
-
return null;
|
|
19438
|
-
}
|
|
19439
|
-
// Handle both single item and array of items
|
|
19440
|
-
const items = Array.isArray(channel.item) ? channel.item : [channel.item];
|
|
19441
|
-
const item = items[0];
|
|
19442
|
-
if (!item?.enclosure) {
|
|
19443
|
-
console.warn(chalk.yellow('Warning: No enclosure element found in appcast'));
|
|
19444
|
-
return null;
|
|
19445
|
-
}
|
|
19446
|
-
const enclosure = item.enclosure;
|
|
19447
|
-
const url = enclosure['@_url'];
|
|
19448
|
-
if (!url || typeof url !== 'string') {
|
|
19449
|
-
console.warn(chalk.yellow('Warning: No URL found in appcast enclosure'));
|
|
19450
|
-
return null;
|
|
19451
|
-
}
|
|
19452
|
-
const version = enclosure['@_sparkle:shortVersionString'];
|
|
19453
|
-
const buildNumber = enclosure['@_sparkle:version'];
|
|
19454
|
-
return {
|
|
19455
|
-
downloadUrl: url,
|
|
19456
|
-
version: typeof version === 'string' ? version : null,
|
|
19457
|
-
buildNumber: typeof buildNumber === 'string' ? buildNumber : null,
|
|
19458
|
-
};
|
|
19459
|
-
}
|
|
19460
|
-
catch (error) {
|
|
19461
|
-
console.warn(chalk.yellow(`Warning: Failed to fetch appcast: ${error.message}`));
|
|
19462
|
-
return null;
|
|
19463
|
-
}
|
|
19464
|
-
}
|
|
19465
|
-
/** Get highest version directory (e.g., v20) from Windows install path */
|
|
19466
|
-
function getHighestVersion(directoryPath) {
|
|
19467
|
-
try {
|
|
19468
|
-
const entries = fs$2.readdirSync(directoryPath, { withFileTypes: true });
|
|
19469
|
-
const versions = entries
|
|
19470
|
-
.filter((e) => e.isDirectory() && /^v\d+$/.test(e.name))
|
|
19471
|
-
.map((e) => parseInt(e.name.slice(1), 10));
|
|
19472
|
-
return versions.length ? `v${Math.max(...versions)}` : null;
|
|
19473
|
-
}
|
|
19474
|
-
catch {
|
|
19475
|
-
return null;
|
|
19476
|
-
}
|
|
19477
|
-
}
|
|
19478
|
-
function getMacOSAppVersion(appPath) {
|
|
19479
|
-
const plistPath = path$4.join(appPath, 'Contents', 'Info.plist');
|
|
19480
|
-
try {
|
|
19481
|
-
const output = execSync(`plutil -extract CFBundleShortVersionString raw "${plistPath}"`, { encoding: 'utf-8', timeout: 5000 });
|
|
19482
|
-
return output.trim();
|
|
19483
|
-
}
|
|
19484
|
-
catch {
|
|
19485
|
-
return null;
|
|
19486
|
-
}
|
|
19487
|
-
}
|
|
19488
|
-
function getWindowsAppVersion(basePath) {
|
|
19489
|
-
const highestVersion = getHighestVersion(basePath);
|
|
19490
|
-
if (!highestVersion) {
|
|
19491
|
-
return null;
|
|
19492
|
-
}
|
|
19493
|
-
const vNum = parseInt(highestVersion.substring(1), 10);
|
|
19494
|
-
return `${vNum}.0.0`;
|
|
19495
|
-
}
|
|
19496
|
-
function parseVersionFromOutput(output) {
|
|
19497
|
-
const match = output.match(/v?(\d+\.\d+\.\d+)/);
|
|
19498
|
-
return match ? match[1] : null;
|
|
19499
|
-
}
|
|
19500
|
-
async function detectMSEVersion(platform) {
|
|
19501
|
-
if (platform === 'linux') {
|
|
19502
|
-
const cliPath = path$4.join(MSE_INSTALL_PATHS.linux, MSE_LINUX_CLI_NAME);
|
|
19503
|
-
if (fs$2.existsSync(cliPath)) {
|
|
19504
|
-
try {
|
|
19505
|
-
const output = execSync(`"${cliPath}" --version`, {
|
|
19506
|
-
encoding: 'utf-8',
|
|
19507
|
-
timeout: 5000,
|
|
19508
|
-
});
|
|
19509
|
-
return parseVersionFromOutput(output);
|
|
19510
|
-
}
|
|
19511
|
-
catch {
|
|
19512
|
-
return null;
|
|
19513
|
-
}
|
|
19514
|
-
}
|
|
19515
|
-
try {
|
|
19516
|
-
const output = execSync('MetaSpatialEditorCLI --version', {
|
|
19517
|
-
encoding: 'utf-8',
|
|
19518
|
-
timeout: 5000,
|
|
19519
|
-
});
|
|
19520
|
-
return parseVersionFromOutput(output);
|
|
19521
|
-
}
|
|
19522
|
-
catch {
|
|
19523
|
-
return null;
|
|
19524
|
-
}
|
|
19525
|
-
}
|
|
19526
|
-
const installPath = MSE_INSTALL_PATHS[platform];
|
|
19527
|
-
if (!installPath || !fs$2.existsSync(installPath)) {
|
|
19528
|
-
return null;
|
|
19529
|
-
}
|
|
19530
|
-
return platform === 'darwin'
|
|
19531
|
-
? getMacOSAppVersion(installPath)
|
|
19532
|
-
: getWindowsAppVersion(installPath);
|
|
19533
|
-
}
|
|
19534
|
-
function isVersionSufficient(installed, required = MSE_MIN_VERSION) {
|
|
19535
|
-
try {
|
|
19536
|
-
const coerced = semver$1.coerce(installed);
|
|
19537
|
-
if (!coerced) {
|
|
19538
|
-
return false;
|
|
19539
|
-
}
|
|
19540
|
-
return semver$1.gte(coerced, required);
|
|
19541
|
-
}
|
|
19542
|
-
catch {
|
|
19543
|
-
return false;
|
|
19544
|
-
}
|
|
19545
|
-
}
|
|
19546
|
-
async function showAndAcceptTOS() {
|
|
19547
|
-
console.log('\n' + chalk.bold.underline('Meta Spatial Editor Terms and Privacy Policy'));
|
|
19548
|
-
console.log(chalk.gray('─'.repeat(60)));
|
|
19549
|
-
console.log(MSE_TOS_CONTENT);
|
|
19550
|
-
console.log(chalk.gray('─'.repeat(60)));
|
|
19551
|
-
const { accepted } = await prompts$1({
|
|
19552
|
-
type: 'select',
|
|
19553
|
-
name: 'accepted',
|
|
19554
|
-
message: 'Do you accept the Terms and Privacy Policy?',
|
|
19555
|
-
choices: [
|
|
19556
|
-
{ title: 'Yes', value: true },
|
|
19557
|
-
{ title: 'No', value: false },
|
|
19558
|
-
],
|
|
19559
|
-
hint: 'Use arrow keys to select, Enter to confirm',
|
|
19560
|
-
});
|
|
19561
|
-
return !!accepted;
|
|
19562
|
-
}
|
|
19563
|
-
async function downloadInstaller(platform, spinner, release) {
|
|
19564
|
-
const ext = { darwin: '.dmg', win32: '.msi', linux: '.tar.gz' }[platform];
|
|
19565
|
-
const tempPath = path$4.join(os.tmpdir(), `MetaSpatialEditorInstaller${ext}`);
|
|
19566
|
-
let releaseInfo = release;
|
|
19567
|
-
if (!releaseInfo) {
|
|
19568
|
-
spinner.text = 'Fetching latest release information...';
|
|
19569
|
-
releaseInfo = await fetchAppcastRelease(platform);
|
|
19570
|
-
}
|
|
19571
|
-
if (!releaseInfo) {
|
|
19572
|
-
throw new Error('Could not fetch release information. Please try again or download manually.');
|
|
19573
|
-
}
|
|
19574
|
-
spinner.text = releaseInfo.version
|
|
19575
|
-
? `Downloading Meta Spatial Editor ${releaseInfo.version}...`
|
|
19576
|
-
: 'Downloading Meta Spatial Editor installer...';
|
|
19577
|
-
const downloadUrl = releaseInfo.downloadUrl.replace(/&/g, '&');
|
|
19578
|
-
const response = await fetch(downloadUrl, {
|
|
19579
|
-
signal: AbortSignal.timeout(300000),
|
|
19580
|
-
});
|
|
19581
|
-
if (!response.ok) {
|
|
19582
|
-
throw new Error(`Download failed: HTTP ${response.status}`);
|
|
19583
|
-
}
|
|
19584
|
-
const buffer = await response.arrayBuffer();
|
|
19585
|
-
fs$2.writeFileSync(tempPath, Buffer.from(buffer));
|
|
19586
|
-
return tempPath;
|
|
19587
|
-
}
|
|
19588
|
-
function silentInstallMacOS(dmgPath, spinner) {
|
|
19589
|
-
const mountPoint = path$4.join(os.tmpdir(), 'mse-installer-mount');
|
|
19590
|
-
const targetPath = '/Applications';
|
|
19591
|
-
try {
|
|
19592
|
-
if (!fs$2.existsSync(mountPoint)) {
|
|
19593
|
-
fs$2.mkdirSync(mountPoint, { recursive: true });
|
|
19594
|
-
}
|
|
19595
|
-
spinner.text = 'Mounting installer...';
|
|
19596
|
-
execSync(`hdiutil attach "${dmgPath}" -nobrowse -quiet -mountpoint "${mountPoint}"`, {
|
|
19597
|
-
timeout: 60000,
|
|
19598
|
-
});
|
|
19599
|
-
let appPath = path$4.join(mountPoint, 'Meta Spatial Editor.app');
|
|
19600
|
-
let appName = 'Meta Spatial Editor.app';
|
|
19601
|
-
if (!fs$2.existsSync(appPath)) {
|
|
19602
|
-
const files = fs$2.readdirSync(mountPoint);
|
|
19603
|
-
const appFile = files.find((f) => f.endsWith('.app'));
|
|
19604
|
-
if (!appFile) {
|
|
19605
|
-
throw new Error('Could not find application in mounted DMG');
|
|
19606
|
-
}
|
|
19607
|
-
appPath = path$4.join(mountPoint, appFile);
|
|
19608
|
-
appName = appFile;
|
|
19609
|
-
}
|
|
19610
|
-
spinner.text = `Installing ${appName}...`;
|
|
19611
|
-
execSync(`cp -R "${appPath}" "${targetPath}/"`, { timeout: 120000 });
|
|
19612
|
-
}
|
|
19613
|
-
finally {
|
|
19614
|
-
try {
|
|
19615
|
-
execSync(`hdiutil detach "${mountPoint}" -quiet`, { timeout: 30000 });
|
|
19616
|
-
}
|
|
19617
|
-
catch {
|
|
19618
|
-
// Ignore unmount errors
|
|
19619
|
-
}
|
|
19620
|
-
}
|
|
19621
|
-
}
|
|
19622
|
-
function silentInstallWindows(msiPath, spinner) {
|
|
19623
|
-
const logPath = path$4.join(os.tmpdir(), 'mse-install.log');
|
|
19624
|
-
spinner.info('Administrator privileges required - a UAC prompt will appear.');
|
|
19625
|
-
console.log(chalk.gray(' Please approve the prompt to continue installation.\n'));
|
|
19626
|
-
const psCommand = `Start-Process -FilePath 'msiexec' -ArgumentList '/i', '${msiPath.replace(/'/g, "''")}', '/quiet', '/norestart', '/log', '${logPath.replace(/'/g, "''")}' -Verb RunAs -Wait`;
|
|
19627
|
-
try {
|
|
19628
|
-
spinner.start('Waiting for administrator approval...');
|
|
19629
|
-
execSync(`powershell -Command "${psCommand}"`, { timeout: 600000 });
|
|
19630
|
-
spinner.text = 'Installation completed, verifying...';
|
|
19631
|
-
}
|
|
19632
|
-
catch (error) {
|
|
19633
|
-
const errorMsg = error.message || '';
|
|
19634
|
-
if (errorMsg.includes('canceled') || errorMsg.includes('cancelled')) {
|
|
19635
|
-
throw new Error('Installation cancelled - administrator privileges are required to install.');
|
|
19636
|
-
}
|
|
19637
|
-
try {
|
|
19638
|
-
const logContent = fs$2.readFileSync(logPath, 'utf16le');
|
|
19639
|
-
if (logContent.includes('1925')) {
|
|
19640
|
-
throw new Error('Installation requires administrator privileges. Please run the terminal as Administrator or install manually.');
|
|
19641
|
-
}
|
|
19642
|
-
}
|
|
19643
|
-
catch {
|
|
19644
|
-
// Log file not readable, continue with original error
|
|
19645
|
-
}
|
|
19646
|
-
throw error;
|
|
19647
|
-
}
|
|
19648
|
-
}
|
|
19649
|
-
function silentInstallLinux(archivePath, spinner) {
|
|
19650
|
-
const installPath = MSE_INSTALL_PATHS.linux;
|
|
19651
|
-
spinner.text = 'Extracting Meta Spatial Editor CLI...';
|
|
19652
|
-
if (!fs$2.existsSync(installPath)) {
|
|
19653
|
-
fs$2.mkdirSync(installPath, { recursive: true });
|
|
19654
|
-
}
|
|
19655
|
-
execSync(`tar -xzf "${archivePath}" -C "${installPath}" --strip-components=1`, { timeout: 120000 });
|
|
19656
|
-
const cliPath = path$4.join(installPath, MSE_LINUX_CLI_NAME);
|
|
19657
|
-
if (fs$2.existsSync(cliPath)) {
|
|
19658
|
-
execSync(`chmod +x "${cliPath}"`, { timeout: 5000 });
|
|
19659
|
-
}
|
|
19660
|
-
const wrapperPath = path$4.join(installPath, 'meta-spatial-editor-cli');
|
|
19661
|
-
if (fs$2.existsSync(wrapperPath)) {
|
|
19662
|
-
execSync(`chmod +x "${wrapperPath}"`, { timeout: 5000 });
|
|
19663
|
-
}
|
|
19664
|
-
}
|
|
19665
|
-
function silentInstall(installerPath, platform, spinner) {
|
|
19666
|
-
if (platform === 'darwin') {
|
|
19667
|
-
silentInstallMacOS(installerPath, spinner);
|
|
19668
|
-
}
|
|
19669
|
-
else if (platform === 'win32') {
|
|
19670
|
-
silentInstallWindows(installerPath, spinner);
|
|
19671
|
-
}
|
|
19672
|
-
else {
|
|
19673
|
-
silentInstallLinux(installerPath, spinner);
|
|
19674
|
-
}
|
|
19675
|
-
}
|
|
19676
|
-
async function installMSE() {
|
|
19677
|
-
const platform = detectPlatform();
|
|
19678
|
-
const downloadUrl = MSE_DOWNLOAD_URLS[platform] || MSE_DOWNLOAD_URLS.default;
|
|
19679
|
-
const productName = platform === 'linux' ? 'Meta Spatial Editor CLI' : 'Meta Spatial Editor';
|
|
19680
|
-
console.log(chalk.gray('\nChecking for latest version...'));
|
|
19681
|
-
const latestRelease = await fetchAppcastRelease(platform);
|
|
19682
|
-
const latestVersion = latestRelease?.version || null;
|
|
19683
|
-
const existingVersion = await detectMSEVersion(platform);
|
|
19684
|
-
if (existingVersion) {
|
|
19685
|
-
const installedNormalized = normalizeVersion(existingVersion);
|
|
19686
|
-
const latestNormalized = latestVersion
|
|
19687
|
-
? normalizeVersion(latestVersion)
|
|
19688
|
-
: null;
|
|
19689
|
-
const belowMinimum = !isVersionSufficient(installedNormalized);
|
|
19690
|
-
if (latestNormalized && installedNormalized === latestNormalized) {
|
|
19691
|
-
console.log(chalk.green(`\n✓ ${productName} ${existingVersion} is already installed (latest version).`));
|
|
19692
|
-
return { installed: true, version: existingVersion, manual: false };
|
|
19693
|
-
}
|
|
19694
|
-
if (latestNormalized) {
|
|
19695
|
-
try {
|
|
19696
|
-
if (semver$1.gte(installedNormalized, latestNormalized)) {
|
|
19697
|
-
console.log(chalk.green(`\n✓ ${productName} ${existingVersion} is already installed (up to date).`));
|
|
19698
|
-
return { installed: true, version: existingVersion, manual: false };
|
|
19699
|
-
}
|
|
19700
|
-
}
|
|
19701
|
-
catch { }
|
|
19702
|
-
const upgradeMessage = belowMinimum
|
|
19703
|
-
? `${productName} ${existingVersion} is installed. Upgrade to ${latestVersion}? (version ${MSE_MIN_VERSION}+ is required for compatibility. The build pipeline may not work correctly if not updated)`
|
|
19704
|
-
: `${productName} ${existingVersion} is installed. Upgrade to ${latestVersion}?`;
|
|
19705
|
-
const { shouldUpgrade } = await prompts$1({
|
|
19706
|
-
type: 'confirm',
|
|
19707
|
-
name: 'shouldUpgrade',
|
|
19708
|
-
message: upgradeMessage,
|
|
19709
|
-
initial: true,
|
|
19710
|
-
});
|
|
19711
|
-
if (!shouldUpgrade) {
|
|
19712
|
-
console.log(chalk.gray('Skipping upgrade.'));
|
|
19713
|
-
return {
|
|
19714
|
-
installed: true,
|
|
19715
|
-
version: existingVersion,
|
|
19716
|
-
manual: false,
|
|
19717
|
-
outdated: belowMinimum,
|
|
19718
|
-
};
|
|
19719
|
-
}
|
|
19720
|
-
}
|
|
19721
|
-
else if (isVersionSufficient(existingVersion)) {
|
|
19722
|
-
console.log(chalk.green(`\n✓ ${productName} ${existingVersion} is already installed.`));
|
|
19723
|
-
console.log(chalk.gray('(Could not check for updates - using installed version)'));
|
|
19724
|
-
return { installed: true, version: existingVersion, manual: false };
|
|
19725
|
-
}
|
|
19726
|
-
else {
|
|
19727
|
-
const { shouldUpgrade } = await prompts$1({
|
|
19728
|
-
type: 'confirm',
|
|
19729
|
-
name: 'shouldUpgrade',
|
|
19730
|
-
message: `${productName} ${existingVersion} is installed but version ${MSE_MIN_VERSION}+ is required. Try to upgrade?`,
|
|
19731
|
-
initial: true,
|
|
19732
|
-
});
|
|
19733
|
-
if (!shouldUpgrade) {
|
|
19734
|
-
return {
|
|
19735
|
-
installed: true,
|
|
19736
|
-
version: existingVersion,
|
|
19737
|
-
manual: false,
|
|
19738
|
-
outdated: true,
|
|
19739
|
-
};
|
|
19740
|
-
}
|
|
19741
|
-
}
|
|
19742
|
-
}
|
|
19743
|
-
else if (!latestRelease) {
|
|
19744
|
-
console.log(chalk.yellow(`\nCould not fetch ${productName} release information.`));
|
|
19745
|
-
console.log('Please install manually:');
|
|
19746
|
-
console.log(chalk.cyan(` ${downloadUrl}`));
|
|
19747
|
-
return { installed: false, version: null, manual: true };
|
|
19748
|
-
}
|
|
19749
|
-
const tosAccepted = await showAndAcceptTOS();
|
|
19750
|
-
if (!tosAccepted) {
|
|
19751
|
-
console.log(chalk.yellow('\nInstallation cancelled - Terms not accepted.'));
|
|
19752
|
-
console.log('You can install Meta Spatial Editor manually later:');
|
|
19753
|
-
console.log(chalk.cyan(` ${downloadUrl}`));
|
|
19754
|
-
return { installed: false, version: null, manual: true };
|
|
19755
|
-
}
|
|
19756
|
-
const spinner = ora({
|
|
19757
|
-
text: 'Preparing installation...',
|
|
19758
|
-
stream: process.stderr,
|
|
19759
|
-
}).start();
|
|
19760
|
-
try {
|
|
19761
|
-
const installerPath = await downloadInstaller(platform, spinner, latestRelease);
|
|
19762
|
-
silentInstall(installerPath, platform, spinner);
|
|
19763
|
-
try {
|
|
19764
|
-
fs$2.unlinkSync(installerPath);
|
|
19765
|
-
}
|
|
19766
|
-
catch {
|
|
19767
|
-
// Ignore cleanup errors
|
|
19768
|
-
}
|
|
19769
|
-
// Brief delay for macOS to register the app
|
|
19770
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
19771
|
-
spinner.text = 'Verifying installation...';
|
|
19772
|
-
const version = await detectMSEVersion(platform);
|
|
19773
|
-
if (version && isVersionSufficient(version)) {
|
|
19774
|
-
spinner.succeed(`${productName} ${version} installed successfully`);
|
|
19775
|
-
if (platform === 'linux') {
|
|
19776
|
-
const cliPath = path$4.join(MSE_INSTALL_PATHS.linux, MSE_LINUX_CLI_NAME);
|
|
19777
|
-
console.log(chalk.cyan(`\nCLI installed to: ${cliPath}`));
|
|
19778
|
-
console.log(chalk.gray(`Set environment variable: META_SPATIAL_EDITOR_CLI_PATH=${cliPath}`));
|
|
19779
|
-
}
|
|
19780
|
-
return { installed: true, version, manual: false };
|
|
19781
|
-
}
|
|
19782
|
-
else if (version) {
|
|
19783
|
-
spinner.succeed(`${productName} ${version} installed (version above ${MSE_MIN_VERSION} recommended)`);
|
|
19784
|
-
return { installed: true, version, manual: false, outdated: true };
|
|
19785
|
-
}
|
|
19786
|
-
else {
|
|
19787
|
-
spinner.warn('Installation completed but version verification failed');
|
|
19788
|
-
return { installed: false, version: null, manual: true };
|
|
19789
|
-
}
|
|
19790
|
-
}
|
|
19791
|
-
catch (error) {
|
|
19792
|
-
spinner.fail('Installation failed');
|
|
19793
|
-
console.error(chalk.red(`Error: ${error.message}`));
|
|
19794
|
-
console.log('\nYou can install Meta Spatial Editor manually:');
|
|
19795
|
-
console.log(chalk.cyan(` ${downloadUrl}`));
|
|
19796
|
-
return {
|
|
19797
|
-
installed: false,
|
|
19798
|
-
version: null,
|
|
19799
|
-
manual: true,
|
|
19800
|
-
error: error,
|
|
19801
|
-
};
|
|
17834
|
+
const ADVANCED_FEATURE_KEYS = [
|
|
17835
|
+
'locomotionEnabled',
|
|
17836
|
+
'grabbingEnabled',
|
|
17837
|
+
'physicsEnabled',
|
|
17838
|
+
'sceneUnderstandingEnabled',
|
|
17839
|
+
'environmentRaycastEnabled',
|
|
17840
|
+
];
|
|
17841
|
+
function validateProjectName(value) {
|
|
17842
|
+
const name = value.trim();
|
|
17843
|
+
if (isValidProjectTarget(name)) {
|
|
17844
|
+
return true;
|
|
19802
17845
|
}
|
|
19803
|
-
|
|
19804
|
-
|
|
19805
|
-
/**
|
|
19806
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
19807
|
-
*
|
|
19808
|
-
* This source code is licensed under the MIT license found in the
|
|
19809
|
-
* LICENSE file in the root directory of this source tree.
|
|
19810
|
-
*/
|
|
17846
|
+
return 'Use "." for the current directory, or a name containing only letters, numbers, hyphens, underscores, dots, and @';
|
|
17847
|
+
}
|
|
19811
17848
|
async function promptFlow(nameArg, defaults = {}) {
|
|
19812
17849
|
let cancelled = false;
|
|
19813
17850
|
const onCancel = () => {
|
|
19814
17851
|
cancelled = true;
|
|
19815
17852
|
return false;
|
|
19816
17853
|
};
|
|
19817
|
-
const
|
|
19818
|
-
|
|
17854
|
+
const assertNotCancelled = () => {
|
|
17855
|
+
if (cancelled) {
|
|
17856
|
+
throw new Error('Input cancelled');
|
|
17857
|
+
}
|
|
17858
|
+
};
|
|
19819
17859
|
const name = nameArg ||
|
|
19820
17860
|
(await prompts$1({
|
|
19821
17861
|
type: 'text',
|
|
19822
17862
|
name: 'name',
|
|
19823
17863
|
message: 'Project name',
|
|
19824
17864
|
initial: 'iwsdk-app',
|
|
19825
|
-
validate:
|
|
19826
|
-
? true
|
|
19827
|
-
: 'Project name must contain only letters, numbers, hyphens, underscores, dots, and @',
|
|
17865
|
+
validate: validateProjectName,
|
|
19828
17866
|
}, { onCancel })).name;
|
|
19829
|
-
|
|
19830
|
-
|
|
19831
|
-
|
|
19832
|
-
|
|
19833
|
-
|
|
19834
|
-
|
|
19835
|
-
|
|
19836
|
-
|
|
19837
|
-
|
|
19838
|
-
|
|
19839
|
-
|
|
19840
|
-
|
|
19841
|
-
|
|
19842
|
-
|
|
19843
|
-
hint: '- Space to select, Enter to confirm',
|
|
19844
|
-
}, { onCancel });
|
|
19845
|
-
if (cancelled) {
|
|
19846
|
-
throw new Error('Input cancelled');
|
|
19847
|
-
}
|
|
19848
|
-
// If "none" is selected, clear all other selections
|
|
19849
|
-
const resolvedAiTools = aiTools?.includes('none')
|
|
19850
|
-
? []
|
|
19851
|
-
: aiTools || [];
|
|
19852
|
-
const { language } = await prompts$1({
|
|
17867
|
+
assertNotCancelled();
|
|
17868
|
+
const target = defaults.target ??
|
|
17869
|
+
(await prompts$1({
|
|
17870
|
+
type: 'select',
|
|
17871
|
+
name: 'target',
|
|
17872
|
+
message: 'What should this project start as?',
|
|
17873
|
+
choices: Object.entries(EXPERIENCE_TARGETS).map(([value, definition]) => ({
|
|
17874
|
+
title: `${definition.label} - ${definition.description}`,
|
|
17875
|
+
value,
|
|
17876
|
+
})),
|
|
17877
|
+
initial: 0,
|
|
17878
|
+
}, { onCancel })).target;
|
|
17879
|
+
assertNotCancelled();
|
|
17880
|
+
const { setup = 'recommended' } = await prompts$1({
|
|
19853
17881
|
type: 'select',
|
|
19854
|
-
name: '
|
|
19855
|
-
message: '
|
|
17882
|
+
name: 'setup',
|
|
17883
|
+
message: 'Setup',
|
|
19856
17884
|
choices: [
|
|
19857
|
-
{
|
|
19858
|
-
|
|
17885
|
+
{
|
|
17886
|
+
title: 'Create with recommended settings',
|
|
17887
|
+
value: 'recommended',
|
|
17888
|
+
},
|
|
17889
|
+
{ title: 'Customize setup...', value: 'advanced' },
|
|
19859
17890
|
],
|
|
19860
17891
|
initial: 0,
|
|
19861
17892
|
}, { onCancel });
|
|
19862
|
-
|
|
19863
|
-
|
|
19864
|
-
|
|
19865
|
-
|
|
19866
|
-
|
|
19867
|
-
|
|
19868
|
-
|
|
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({
|
|
17893
|
+
assertNotCancelled();
|
|
17894
|
+
let language = 'ts';
|
|
17895
|
+
let gitInit = true;
|
|
17896
|
+
let installNow = true;
|
|
17897
|
+
let configuration = getRecommendedConfiguration(target);
|
|
17898
|
+
if (setup === 'advanced') {
|
|
17899
|
+
const languageAnswer = await prompts$1({
|
|
19879
17900
|
type: 'select',
|
|
19880
|
-
name: '
|
|
19881
|
-
message: '
|
|
17901
|
+
name: 'language',
|
|
17902
|
+
message: 'Language',
|
|
19882
17903
|
choices: [
|
|
19883
|
-
{ title: '
|
|
19884
|
-
{ title: '
|
|
17904
|
+
{ title: 'TypeScript (recommended)', value: 'ts' },
|
|
17905
|
+
{ title: 'JavaScript', value: 'js' },
|
|
19885
17906
|
],
|
|
19886
17907
|
initial: 0,
|
|
19887
|
-
}, { onCancel })
|
|
19888
|
-
: { mode: 'vr' };
|
|
19889
|
-
if (cancelled) {
|
|
19890
|
-
throw new Error('Input cancelled');
|
|
19891
|
-
}
|
|
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
|
-
];
|
|
19904
|
-
const xrFeatureStates = {};
|
|
19905
|
-
for (const key of xrFeatureKeys) {
|
|
19906
|
-
const initial = mode === 'ar' ? 1 : key === 'handTracking' || key === 'layers' ? 1 : 0;
|
|
19907
|
-
const label = key === 'handTracking'
|
|
19908
|
-
? 'Hand Tracking'
|
|
19909
|
-
: key === 'planeDetection'
|
|
19910
|
-
? 'Plane Detection'
|
|
19911
|
-
: key === 'meshDetection'
|
|
19912
|
-
? 'Mesh Detection'
|
|
19913
|
-
: key === 'hitTest'
|
|
19914
|
-
? 'Hit Test'
|
|
19915
|
-
: key === 'anchors'
|
|
19916
|
-
? 'Anchors'
|
|
19917
|
-
: key === 'layers'
|
|
19918
|
-
? 'WebXR Layers'
|
|
19919
|
-
: key;
|
|
19920
|
-
const { state } = await prompts$1({
|
|
19921
|
-
type: 'select',
|
|
19922
|
-
name: 'state',
|
|
19923
|
-
message: `Enable ${label}?`,
|
|
19924
|
-
choices: [
|
|
19925
|
-
{ title: 'No', value: 'no' },
|
|
19926
|
-
{ title: 'Optional', value: 'optional' },
|
|
19927
|
-
{ title: 'Required', value: 'required' },
|
|
19928
|
-
],
|
|
19929
|
-
initial,
|
|
19930
17908
|
}, { onCancel });
|
|
19931
|
-
|
|
19932
|
-
|
|
19933
|
-
}
|
|
19934
|
-
|
|
19935
|
-
|
|
19936
|
-
|
|
19937
|
-
|
|
19938
|
-
// - VR: Locomotion → Grabbing → Physics
|
|
19939
|
-
// - AR: Scene Understanding → Grabbing → Physics
|
|
19940
|
-
let locomotionEnabled = false;
|
|
19941
|
-
let locomotionUseWorker = undefined;
|
|
19942
|
-
let sceneUnderstandingEnabled = false;
|
|
19943
|
-
let environmentRaycastEnabled = false;
|
|
19944
|
-
if (xrEnabled && mode === 'vr') {
|
|
19945
|
-
// Locomotion (VR only)
|
|
19946
|
-
const ans = await prompts$1({
|
|
19947
|
-
type: 'toggle',
|
|
19948
|
-
name: 'locomotionEnabled',
|
|
19949
|
-
message: 'Enable locomotion?',
|
|
19950
|
-
initial: true,
|
|
19951
|
-
active: 'Yes',
|
|
19952
|
-
inactive: 'No',
|
|
19953
|
-
}, { onCancel });
|
|
19954
|
-
if (cancelled) {
|
|
19955
|
-
throw new Error('Input cancelled');
|
|
19956
|
-
}
|
|
19957
|
-
locomotionEnabled = !!ans.locomotionEnabled;
|
|
19958
|
-
if (locomotionEnabled) {
|
|
19959
|
-
const followUp = await prompts$1({
|
|
19960
|
-
type: 'select',
|
|
19961
|
-
name: 'useWorker',
|
|
19962
|
-
message: 'Deploy locomotion engine on a Worker? (recommended for performance)',
|
|
19963
|
-
choices: [
|
|
19964
|
-
{ title: 'Yes (recommended)', value: true },
|
|
19965
|
-
{ title: 'No', value: false },
|
|
19966
|
-
],
|
|
19967
|
-
initial: 0,
|
|
19968
|
-
}, { onCancel });
|
|
19969
|
-
if (cancelled) {
|
|
19970
|
-
throw new Error('Input cancelled');
|
|
17909
|
+
assertNotCancelled();
|
|
17910
|
+
language = languageAnswer.language || 'ts';
|
|
17911
|
+
const overrides = {};
|
|
17912
|
+
for (const key of ADVANCED_FEATURE_KEYS) {
|
|
17913
|
+
const definition = FEATURE_CATALOG[key];
|
|
17914
|
+
if (!definition.targets.includes(target)) {
|
|
17915
|
+
continue;
|
|
19971
17916
|
}
|
|
19972
|
-
|
|
19973
|
-
|
|
19974
|
-
|
|
19975
|
-
|
|
19976
|
-
|
|
19977
|
-
|
|
19978
|
-
|
|
19979
|
-
|
|
19980
|
-
|
|
19981
|
-
|
|
19982
|
-
active: 'Yes',
|
|
19983
|
-
inactive: 'No',
|
|
19984
|
-
}, { onCancel });
|
|
19985
|
-
if (cancelled) {
|
|
19986
|
-
throw new Error('Input cancelled');
|
|
19987
|
-
}
|
|
19988
|
-
sceneUnderstandingEnabled = !!sceneAns.sceneUnderstandingEnabled;
|
|
19989
|
-
// Environment Raycast (no room scanning required)
|
|
19990
|
-
const raycastAns = await prompts$1({
|
|
19991
|
-
type: 'toggle',
|
|
19992
|
-
name: 'environmentRaycastEnabled',
|
|
19993
|
-
message: 'Enable Environment Raycast (hit-test surfaces)? No room scanning required.',
|
|
19994
|
-
initial: true,
|
|
19995
|
-
active: 'Yes',
|
|
19996
|
-
inactive: 'No',
|
|
19997
|
-
}, { onCancel });
|
|
19998
|
-
if (cancelled) {
|
|
19999
|
-
throw new Error('Input cancelled');
|
|
20000
|
-
}
|
|
20001
|
-
environmentRaycastEnabled = !!raycastAns.environmentRaycastEnabled;
|
|
20002
|
-
}
|
|
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;
|
|
20017
|
-
}
|
|
20018
|
-
// Physics (default: disabled)
|
|
20019
|
-
const { physicsEnabled } = await prompts$1({
|
|
20020
|
-
type: 'toggle',
|
|
20021
|
-
name: 'physicsEnabled',
|
|
20022
|
-
message: 'Enable physics simulation (Havok)?',
|
|
20023
|
-
initial: false,
|
|
20024
|
-
active: 'Yes',
|
|
20025
|
-
inactive: 'No',
|
|
20026
|
-
}, { onCancel });
|
|
20027
|
-
if (cancelled) {
|
|
20028
|
-
throw new Error('Input cancelled');
|
|
20029
|
-
}
|
|
20030
|
-
// UI library selection removed (no-op currently)
|
|
20031
|
-
// Meta Spatial Editor is only available as a GUI app on macOS/Windows.
|
|
20032
|
-
// On Linux, skip the prompt and default to manual workflow.
|
|
20033
|
-
const isLinux = process.platform !== 'darwin' && process.platform !== 'win32';
|
|
20034
|
-
let metaspatial = false;
|
|
20035
|
-
if (!isLinux) {
|
|
20036
|
-
const metaAnswer = await prompts$1({
|
|
20037
|
-
type: 'select',
|
|
20038
|
-
name: 'metaspatialChoice',
|
|
20039
|
-
message: 'Enable Meta Spatial Editor integration?',
|
|
20040
|
-
choices: [
|
|
20041
|
-
{
|
|
20042
|
-
title: 'Yes (Install Meta Spatial Editor if needed)',
|
|
20043
|
-
value: true,
|
|
20044
|
-
},
|
|
20045
|
-
{ title: 'Skip for now (can change later)', value: false },
|
|
20046
|
-
],
|
|
20047
|
-
initial: 1,
|
|
20048
|
-
}, { onCancel });
|
|
20049
|
-
metaspatial = !!metaAnswer.metaspatialChoice;
|
|
20050
|
-
}
|
|
20051
|
-
let mseInstallResult;
|
|
20052
|
-
if (metaspatial) {
|
|
20053
|
-
mseInstallResult = await installMSE();
|
|
20054
|
-
if (mseInstallResult.manual || mseInstallResult.outdated) {
|
|
20055
|
-
prerequisites.push({
|
|
20056
|
-
level: 'important',
|
|
20057
|
-
message: `Required: Install Meta Spatial Editor (v${MSE_MIN_VERSION} or later). The build pipeline depends on its CLI tool; without it, build or dev WILL FAIL. Download: https://developers.meta.com/horizon/documentation/spatial-sdk/spatial-editor-overview`,
|
|
20058
|
-
});
|
|
17917
|
+
const answer = await prompts$1({
|
|
17918
|
+
type: 'toggle',
|
|
17919
|
+
name: 'enabled',
|
|
17920
|
+
message: `${definition.label}: ${definition.description}`,
|
|
17921
|
+
initial: !!configuration.featureFlags[key],
|
|
17922
|
+
active: 'Yes',
|
|
17923
|
+
inactive: 'No',
|
|
17924
|
+
}, { onCancel });
|
|
17925
|
+
assertNotCancelled();
|
|
17926
|
+
overrides[key] = !!answer.enabled;
|
|
20059
17927
|
}
|
|
17928
|
+
configuration = getRecommendedConfiguration(target, overrides);
|
|
17929
|
+
const operationalAnswers = await prompts$1([
|
|
17930
|
+
{
|
|
17931
|
+
type: 'toggle',
|
|
17932
|
+
name: 'gitInit',
|
|
17933
|
+
message: 'Set up a Git repository?',
|
|
17934
|
+
initial: true,
|
|
17935
|
+
active: 'Yes',
|
|
17936
|
+
inactive: 'No',
|
|
17937
|
+
},
|
|
17938
|
+
{
|
|
17939
|
+
type: 'toggle',
|
|
17940
|
+
name: 'installNow',
|
|
17941
|
+
message: 'Install dependencies now?',
|
|
17942
|
+
initial: true,
|
|
17943
|
+
active: 'Yes',
|
|
17944
|
+
inactive: 'No',
|
|
17945
|
+
},
|
|
17946
|
+
], { onCancel });
|
|
17947
|
+
assertNotCancelled();
|
|
17948
|
+
gitInit = !!operationalAnswers.gitInit;
|
|
17949
|
+
installNow = !!operationalAnswers.installNow;
|
|
20060
17950
|
}
|
|
20061
|
-
const { gitInit, installNow } = await prompts$1([
|
|
20062
|
-
{
|
|
20063
|
-
type: 'toggle',
|
|
20064
|
-
name: 'gitInit',
|
|
20065
|
-
message: 'Set up a Git repository?',
|
|
20066
|
-
initial: true,
|
|
20067
|
-
active: 'Yes',
|
|
20068
|
-
inactive: 'No',
|
|
20069
|
-
},
|
|
20070
|
-
{
|
|
20071
|
-
type: 'toggle',
|
|
20072
|
-
name: 'installNow',
|
|
20073
|
-
message: 'Install dependencies now? (We will print the command to start the dev server.)',
|
|
20074
|
-
initial: true,
|
|
20075
|
-
active: 'Yes',
|
|
20076
|
-
inactive: 'No',
|
|
20077
|
-
},
|
|
20078
|
-
], { onCancel });
|
|
20079
|
-
if (cancelled) {
|
|
20080
|
-
throw new Error('Input cancelled');
|
|
20081
|
-
}
|
|
20082
|
-
const kind = metaspatial ? 'metaspatial' : 'manual';
|
|
20083
|
-
const id = `${mode}-${kind}-${language}`;
|
|
20084
17951
|
return {
|
|
20085
17952
|
name,
|
|
20086
|
-
id,
|
|
20087
17953
|
installNow,
|
|
20088
|
-
|
|
20089
|
-
xrEnabled,
|
|
20090
|
-
mode,
|
|
17954
|
+
target,
|
|
17955
|
+
xrEnabled: configuration.xrEnabled,
|
|
17956
|
+
mode: configuration.mode,
|
|
20091
17957
|
language,
|
|
20092
|
-
|
|
20093
|
-
featureFlags: {
|
|
20094
|
-
locomotionEnabled: !!locomotionEnabled,
|
|
20095
|
-
locomotionUseWorker,
|
|
20096
|
-
grabbingEnabled: !!grabbingEnabled,
|
|
20097
|
-
physicsEnabled: !!physicsEnabled,
|
|
20098
|
-
sceneUnderstandingEnabled: !!sceneUnderstandingEnabled,
|
|
20099
|
-
environmentRaycastEnabled: !!environmentRaycastEnabled,
|
|
20100
|
-
},
|
|
17958
|
+
featureFlags: configuration.featureFlags,
|
|
20101
17959
|
gitInit,
|
|
20102
|
-
|
|
20103
|
-
|
|
20104
|
-
|
|
20105
|
-
prerequisites,
|
|
20106
|
-
mseInstallResult,
|
|
17960
|
+
xrFeatureStates: configuration.xrFeatureStates,
|
|
17961
|
+
actionItems: [],
|
|
17962
|
+
prerequisites: [],
|
|
20107
17963
|
};
|
|
20108
17964
|
}
|
|
20109
17965
|
|
|
20110
|
-
|
|
20111
|
-
|
|
20112
|
-
|
|
20113
|
-
|
|
17966
|
+
/**
|
|
17967
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
17968
|
+
*
|
|
17969
|
+
* This source code is licensed under the MIT license found in the
|
|
17970
|
+
* LICENSE file in the root directory of this source tree.
|
|
17971
|
+
*/
|
|
17972
|
+
async function getStat(targetPath) {
|
|
17973
|
+
try {
|
|
17974
|
+
return await fsp.lstat(targetPath);
|
|
20114
17975
|
}
|
|
20115
|
-
|
|
20116
|
-
|
|
20117
|
-
|
|
20118
|
-
const resolvedRecipes = [];
|
|
20119
|
-
const addRecipe = (recipe) => {
|
|
20120
|
-
const insertLocation = Math.max(-1, ...Object.entries(recipe.requirements ?? {}).map(([name, versionQuery]) => {
|
|
20121
|
-
const index = resolvedRecipes.findIndex((recipe) => recipe.name === name && semver.satisfies(recipe.version ?? '0.0.0', versionQuery));
|
|
20122
|
-
if (index != -1) {
|
|
20123
|
-
return index;
|
|
20124
|
-
}
|
|
20125
|
-
{
|
|
20126
|
-
throw new Error(`Recipe "${name}" requires a resolveRequirements function to resolve dependencies`);
|
|
20127
|
-
}
|
|
20128
|
-
})) + 1;
|
|
20129
|
-
resolvedRecipes.splice(insertLocation, 0, recipe);
|
|
20130
|
-
return insertLocation;
|
|
20131
|
-
};
|
|
20132
|
-
for (let i = recipes.length - 1; i >= 0; i--) {
|
|
20133
|
-
addRecipe(recipes[i]);
|
|
20134
|
-
}
|
|
20135
|
-
const files = {};
|
|
20136
|
-
const binaryFiles = {};
|
|
20137
|
-
const variables = {};
|
|
20138
|
-
for (const recipe of resolvedRecipes) {
|
|
20139
|
-
if (recipe.edits == null) {
|
|
20140
|
-
continue;
|
|
20141
|
-
}
|
|
20142
|
-
await applyRecipeEdits(files, variables, recipe.edits, binaryFiles);
|
|
20143
|
-
}
|
|
20144
|
-
const resolvedVariables = {};
|
|
20145
|
-
// Resolve all variables: replace variable references with their values
|
|
20146
|
-
const variableEntryQueue = Object.entries(variables);
|
|
20147
|
-
const resolvedVariableNames = new Set();
|
|
20148
|
-
while (variableEntryQueue.length > 0) {
|
|
20149
|
-
let madeProgress = false;
|
|
20150
|
-
for (let i = variableEntryQueue.length - 1; i >= 0; i--) {
|
|
20151
|
-
const [variableName, variableValue] = variableEntryQueue[i];
|
|
20152
|
-
try {
|
|
20153
|
-
const resolved = resolveVariableReferences(variableValue, variables, resolvedVariables);
|
|
20154
|
-
resolvedVariables[variableName] = resolved;
|
|
20155
|
-
resolvedVariableNames.add(variableName);
|
|
20156
|
-
variableEntryQueue.splice(i, 1);
|
|
20157
|
-
madeProgress = true;
|
|
20158
|
-
}
|
|
20159
|
-
catch (error) {
|
|
20160
|
-
if (error instanceof VariableResolutionError) ;
|
|
20161
|
-
else {
|
|
20162
|
-
throw error;
|
|
20163
|
-
}
|
|
20164
|
-
}
|
|
20165
|
-
}
|
|
20166
|
-
if (!madeProgress) {
|
|
20167
|
-
throw new Error(`Circular dependency detected for: ${variableEntryQueue.map(([key]) => key).join(', ')}`);
|
|
17976
|
+
catch (error) {
|
|
17977
|
+
if (error.code === 'ENOENT') {
|
|
17978
|
+
return undefined;
|
|
20168
17979
|
}
|
|
20169
|
-
|
|
20170
|
-
// Convert files from Record<string, Json> to Record<string, string> and return them
|
|
20171
|
-
const result = {
|
|
20172
|
-
...binaryFiles,
|
|
20173
|
-
};
|
|
20174
|
-
for (const [fileName, fileValue] of Object.entries(files)) {
|
|
20175
|
-
result[fileName] = encoder.encode(jsonToOutputString(resolveVariableReferences(fileValue, variables, resolvedVariables)));
|
|
20176
|
-
}
|
|
20177
|
-
return result;
|
|
20178
|
-
}
|
|
20179
|
-
async function applyRecipeEdits(files, variables, edits, binaryFiles, options) {
|
|
20180
|
-
if (edits == null) {
|
|
20181
|
-
return;
|
|
20182
|
-
}
|
|
20183
|
-
for (const [path, operation] of Object.entries(edits)) {
|
|
20184
|
-
await applyRecipeEditOperation(files, variables, path, operation, binaryFiles);
|
|
17980
|
+
throw error;
|
|
20185
17981
|
}
|
|
20186
17982
|
}
|
|
20187
|
-
|
|
20188
|
-
|
|
20189
|
-
|
|
20190
|
-
|
|
20191
|
-
|
|
20192
|
-
|
|
20193
|
-
|
|
20194
|
-
|
|
20195
|
-
|
|
20196
|
-
|
|
20197
|
-
|
|
20198
|
-
|
|
20199
|
-
|
|
20200
|
-
|
|
20201
|
-
|
|
20202
|
-
|
|
20203
|
-
|
|
20204
|
-
if (binaryFiles == null) {
|
|
20205
|
-
throw new Error(`binaryFiles parameter is required when fetching binary content from URL`);
|
|
20206
|
-
}
|
|
20207
|
-
const binaryContent = new Uint8Array(await response.arrayBuffer());
|
|
20208
|
-
const { name } = parsePath(path);
|
|
20209
|
-
binaryFiles[name] = binaryContent;
|
|
20210
|
-
}
|
|
20211
|
-
}
|
|
20212
|
-
if (operation.base64 != null) {
|
|
20213
|
-
const binaryData = Uint8Array.from(atob(operation.base64), (c) => c.charCodeAt(0));
|
|
20214
|
-
if (path.startsWith('@')) {
|
|
20215
|
-
throw new Error(`Cannot set base64 data on variable "${path}". Use file paths for binary data.`);
|
|
20216
|
-
}
|
|
20217
|
-
if (binaryFiles == null) {
|
|
20218
|
-
throw new Error(`binaryFiles parameter is required when using base64 operations`);
|
|
20219
|
-
}
|
|
20220
|
-
const { name } = parsePath(path);
|
|
20221
|
-
binaryFiles[name] = binaryData;
|
|
20222
|
-
}
|
|
20223
|
-
if (operation.lines != null) {
|
|
20224
|
-
setAtPath(files, variables, path, operation.lines.join('\n'));
|
|
20225
|
-
}
|
|
20226
|
-
if (operation.set != null) {
|
|
20227
|
-
setAtPath(files, variables, path, inputJsonToJson(operation.set));
|
|
20228
|
-
}
|
|
20229
|
-
let current = getAtPath(files, variables, path);
|
|
20230
|
-
if (operation.append != null) {
|
|
20231
|
-
if (typeof current != 'string') {
|
|
20232
|
-
current = jsonToOutputString(current ?? '');
|
|
20233
|
-
}
|
|
20234
|
-
setAtPath(files, variables, path, `${current}${operation.append}`);
|
|
20235
|
-
}
|
|
20236
|
-
if (operation.appendLines != null) {
|
|
20237
|
-
if (typeof current != 'string') {
|
|
20238
|
-
current = jsonToOutputString(current ?? '');
|
|
20239
|
-
}
|
|
20240
|
-
const appendText = operation.appendLines.join('\n');
|
|
20241
|
-
setAtPath(files, variables, path, current.length > 0 ? `${current}\n${appendText}` : appendText);
|
|
20242
|
-
}
|
|
20243
|
-
if (operation.prepend != null) {
|
|
20244
|
-
if (typeof current != 'string') {
|
|
20245
|
-
current = jsonToOutputString(current ?? '');
|
|
20246
|
-
}
|
|
20247
|
-
setAtPath(files, variables, path, `${operation.prepend}${current}`);
|
|
20248
|
-
}
|
|
20249
|
-
if (operation.prependLines != null) {
|
|
20250
|
-
if (typeof current != 'string') {
|
|
20251
|
-
current = jsonToOutputString(current ?? '');
|
|
20252
|
-
}
|
|
20253
|
-
const prependText = operation.prependLines.join('\n');
|
|
20254
|
-
setAtPath(files, variables, path, current.length > 0 ? `${prependText}\n${current}` : prependText);
|
|
20255
|
-
}
|
|
20256
|
-
if (operation.push != null) {
|
|
20257
|
-
current ??= [];
|
|
20258
|
-
if (!Array.isArray(current)) {
|
|
20259
|
-
throw new Error(`Cannot push to non-array value ${JSON.stringify(current)} at path "${path}"`);
|
|
20260
|
-
}
|
|
20261
|
-
setAtPath(files, variables, path, [...current, inputJsonToJson(operation.push)]);
|
|
20262
|
-
}
|
|
20263
|
-
if (operation.pushAll != null) {
|
|
20264
|
-
current ??= [];
|
|
20265
|
-
if (!Array.isArray(current)) {
|
|
20266
|
-
throw new Error(`Cannot pushAll to non-array value "${current}" at path "${path}"`);
|
|
20267
|
-
}
|
|
20268
|
-
setAtPath(files, variables, path, [...current, ...operation.pushAll.map(inputJsonToJson)]);
|
|
17983
|
+
function resolveOutputPath(outDir, sourcePath) {
|
|
17984
|
+
const invalidSegment = sourcePath
|
|
17985
|
+
.split('/')
|
|
17986
|
+
.some((segment) => segment === '' || segment === '.' || segment === '..');
|
|
17987
|
+
if (sourcePath.includes('\0') ||
|
|
17988
|
+
sourcePath.includes('\\') ||
|
|
17989
|
+
invalidSegment ||
|
|
17990
|
+
/^[a-zA-Z]:/.test(sourcePath)) {
|
|
17991
|
+
throw new Error(`Generated output path "${sourcePath}" is not safe.`);
|
|
17992
|
+
}
|
|
17993
|
+
const outPath = path$5.resolve(outDir, ...sourcePath.split('/'));
|
|
17994
|
+
const relativePath = path$5.relative(outDir, outPath);
|
|
17995
|
+
if (relativePath === '' ||
|
|
17996
|
+
relativePath === '..' ||
|
|
17997
|
+
relativePath.startsWith(`..${path$5.sep}`) ||
|
|
17998
|
+
path$5.isAbsolute(relativePath)) {
|
|
17999
|
+
throw new Error(`Generated output path "${sourcePath}" escapes the target.`);
|
|
20269
18000
|
}
|
|
18001
|
+
return {
|
|
18002
|
+
collisionKey: relativePath.normalize('NFC').toLowerCase(),
|
|
18003
|
+
outPath,
|
|
18004
|
+
relativePath,
|
|
18005
|
+
};
|
|
20270
18006
|
}
|
|
20271
|
-
function
|
|
20272
|
-
const
|
|
20273
|
-
|
|
20274
|
-
|
|
20275
|
-
|
|
20276
|
-
|
|
20277
|
-
|
|
18007
|
+
function buildProjectFiles(sources, outDir) {
|
|
18008
|
+
const files = [];
|
|
18009
|
+
const outputPaths = new Set();
|
|
18010
|
+
for (const source of sources) {
|
|
18011
|
+
const rel = source.path;
|
|
18012
|
+
const { collisionKey, outPath, relativePath } = resolveOutputPath(outDir, rel);
|
|
18013
|
+
if (outputPaths.has(collisionKey)) {
|
|
18014
|
+
throw new Error(`Generated output path "${rel}" resolves more than once.`);
|
|
20278
18015
|
}
|
|
20279
|
-
|
|
20280
|
-
|
|
20281
|
-
|
|
18016
|
+
outputPaths.add(collisionKey);
|
|
18017
|
+
files.push({
|
|
18018
|
+
collisionKey,
|
|
18019
|
+
contents: typeof source.contents === 'string'
|
|
18020
|
+
? Buffer.from(source.contents, 'utf8')
|
|
18021
|
+
: Buffer.from(source.contents),
|
|
18022
|
+
outPath,
|
|
18023
|
+
relativePath,
|
|
18024
|
+
});
|
|
20282
18025
|
}
|
|
20283
|
-
|
|
18026
|
+
return files;
|
|
20284
18027
|
}
|
|
20285
|
-
function
|
|
20286
|
-
const
|
|
20287
|
-
|
|
20288
|
-
|
|
20289
|
-
|
|
20290
|
-
|
|
18028
|
+
function assertManifestPaths(files) {
|
|
18029
|
+
const outputPaths = new Set(files.map((file) => file.collisionKey));
|
|
18030
|
+
for (const file of files) {
|
|
18031
|
+
let ancestor = path$5.dirname(file.relativePath);
|
|
18032
|
+
while (ancestor !== '.') {
|
|
18033
|
+
if (outputPaths.has(ancestor.normalize('NFC').toLowerCase())) {
|
|
18034
|
+
throw new Error(`Generated output "${ancestor}" cannot be both a file and a directory.`);
|
|
18035
|
+
}
|
|
18036
|
+
ancestor = path$5.dirname(ancestor);
|
|
20291
18037
|
}
|
|
20292
|
-
assureAccessible(value, valuePathPart, path);
|
|
20293
|
-
value = value[valuePathPart];
|
|
20294
18038
|
}
|
|
20295
|
-
return value;
|
|
20296
18039
|
}
|
|
20297
|
-
function
|
|
20298
|
-
|
|
20299
|
-
|
|
18040
|
+
async function ensureTargetDirectory(outDir, force) {
|
|
18041
|
+
let targetStat = await getStat(outDir);
|
|
18042
|
+
if (targetStat == null) {
|
|
18043
|
+
await fsp.mkdir(outDir, { recursive: true });
|
|
18044
|
+
targetStat = await getStat(outDir);
|
|
20300
18045
|
}
|
|
20301
|
-
if (
|
|
20302
|
-
throw new Error(
|
|
18046
|
+
if (targetStat?.isSymbolicLink()) {
|
|
18047
|
+
throw new Error('Refusing to scaffold into a symbolic-link target.');
|
|
20303
18048
|
}
|
|
20304
|
-
|
|
20305
|
-
|
|
20306
|
-
const isFile = !path.startsWith('@');
|
|
20307
|
-
let searchStartIndex;
|
|
20308
|
-
if (isFile) {
|
|
20309
|
-
searchStartIndex = path.lastIndexOf('.');
|
|
20310
|
-
if (searchStartIndex === -1) {
|
|
20311
|
-
throw new Error(`files must include a "." for the file extension`);
|
|
20312
|
-
}
|
|
18049
|
+
if (!targetStat?.isDirectory()) {
|
|
18050
|
+
throw new Error('Scaffold target is not a directory.');
|
|
20313
18051
|
}
|
|
20314
|
-
|
|
20315
|
-
|
|
20316
|
-
endOfNameIndex = path.length;
|
|
18052
|
+
if (!force && (await fsp.readdir(outDir)).length > 0) {
|
|
18053
|
+
throw new Error('Target directory is not empty. Re-run with --force to overwrite conflicting generated files; unrelated files will be preserved.');
|
|
20317
18054
|
}
|
|
20318
|
-
return {
|
|
20319
|
-
isFile,
|
|
20320
|
-
name: path.slice(0, endOfNameIndex),
|
|
20321
|
-
valuePath: path
|
|
20322
|
-
.slice(endOfNameIndex + 1)
|
|
20323
|
-
.split(/(?<!\\)\//)
|
|
20324
|
-
.filter((part) => part.length > 0)
|
|
20325
|
-
.map((part) => part.replaceAll(/(?<!\\)\\\//g, '/')),
|
|
20326
|
-
};
|
|
20327
18055
|
}
|
|
20328
|
-
function
|
|
20329
|
-
|
|
20330
|
-
|
|
20331
|
-
|
|
20332
|
-
|
|
20333
|
-
|
|
20334
|
-
|
|
20335
|
-
|
|
18056
|
+
async function assertOutputPaths(files, outDir) {
|
|
18057
|
+
const targetStat = await getStat(outDir);
|
|
18058
|
+
if (targetStat?.isSymbolicLink()) {
|
|
18059
|
+
throw new Error('Refusing to scaffold into a symbolic-link target.');
|
|
18060
|
+
}
|
|
18061
|
+
if (!targetStat?.isDirectory()) {
|
|
18062
|
+
throw new Error('Scaffold target is not a directory.');
|
|
18063
|
+
}
|
|
18064
|
+
for (const file of files) {
|
|
18065
|
+
const pathParts = file.relativePath.split(path$5.sep);
|
|
18066
|
+
let currentPath = outDir;
|
|
18067
|
+
for (let index = 0; index < pathParts.length; index++) {
|
|
18068
|
+
currentPath = path$5.join(currentPath, pathParts[index]);
|
|
18069
|
+
const currentStat = await getStat(currentPath);
|
|
18070
|
+
if (currentStat == null) {
|
|
18071
|
+
break;
|
|
20336
18072
|
}
|
|
20337
|
-
|
|
20338
|
-
|
|
20339
|
-
|
|
20340
|
-
|
|
20341
|
-
|
|
20342
|
-
|
|
20343
|
-
|
|
20344
|
-
|
|
20345
|
-
|
|
20346
|
-
|
|
20347
|
-
|
|
20348
|
-
|
|
18073
|
+
const displayPath = path$5.relative(outDir, currentPath);
|
|
18074
|
+
if (currentStat.isSymbolicLink()) {
|
|
18075
|
+
throw new Error(`Refusing to scaffold through symbolic link "${displayPath}".`);
|
|
18076
|
+
}
|
|
18077
|
+
const isOutputFile = index === pathParts.length - 1;
|
|
18078
|
+
if (!isOutputFile && !currentStat.isDirectory()) {
|
|
18079
|
+
throw new Error(`Cannot create "${file.relativePath}": "${displayPath}" is not a directory.`);
|
|
18080
|
+
}
|
|
18081
|
+
if (isOutputFile && !currentStat.isFile()) {
|
|
18082
|
+
throw new Error(`Cannot overwrite "${file.relativePath}": the existing path is not a regular file.`);
|
|
18083
|
+
}
|
|
18084
|
+
}
|
|
20349
18085
|
}
|
|
20350
|
-
return resolved;
|
|
20351
18086
|
}
|
|
20352
|
-
function
|
|
20353
|
-
|
|
20354
|
-
|
|
18087
|
+
async function createOutputDirectories(files) {
|
|
18088
|
+
const directories = Array.from(new Set(files.map((file) => path$5.dirname(file.outPath)))).sort((left, right) => left.length - right.length);
|
|
18089
|
+
for (const directory of directories) {
|
|
18090
|
+
await fsp.mkdir(directory, { recursive: true });
|
|
20355
18091
|
}
|
|
18092
|
+
}
|
|
18093
|
+
async function stageProjectFiles(files) {
|
|
18094
|
+
const stagedFiles = [];
|
|
20356
18095
|
try {
|
|
20357
|
-
|
|
20358
|
-
|
|
20359
|
-
|
|
20360
|
-
|
|
18096
|
+
for (const file of files) {
|
|
18097
|
+
const stagedPath = path$5.join(path$5.dirname(file.outPath), `.${path$5.basename(file.outPath)}.iwsdk-${randomUUID()}.tmp`);
|
|
18098
|
+
await fsp.writeFile(stagedPath, file.contents, { flag: 'wx' });
|
|
18099
|
+
stagedFiles.push({ ...file, stagedPath });
|
|
18100
|
+
}
|
|
18101
|
+
return stagedFiles;
|
|
20361
18102
|
}
|
|
20362
|
-
|
|
20363
|
-
|
|
20364
|
-
|
|
20365
|
-
return 'null';
|
|
20366
|
-
}
|
|
20367
|
-
if (Array.isArray(json)) {
|
|
20368
|
-
return `[${json.map(jsonToOutputString).join(', ')}]`;
|
|
20369
|
-
}
|
|
20370
|
-
switch (typeof json) {
|
|
20371
|
-
case 'boolean':
|
|
20372
|
-
case 'number':
|
|
20373
|
-
case 'string':
|
|
20374
|
-
return json.toString();
|
|
20375
|
-
case 'object':
|
|
20376
|
-
return `{ ${Object.entries(json)
|
|
20377
|
-
.map(([key, value]) => `"${key}": ${jsonToOutputString(value)}`)
|
|
20378
|
-
.join(', ')} }`;
|
|
18103
|
+
catch (error) {
|
|
18104
|
+
await Promise.allSettled(stagedFiles.map((file) => fsp.rm(file.stagedPath, { force: true })));
|
|
18105
|
+
throw error;
|
|
20379
18106
|
}
|
|
20380
18107
|
}
|
|
20381
|
-
|
|
20382
|
-
|
|
20383
|
-
|
|
20384
|
-
|
|
20385
|
-
* This source code is licensed under the MIT license found in the
|
|
20386
|
-
* LICENSE file in the root directory of this source tree.
|
|
20387
|
-
*/
|
|
20388
|
-
async function applyRecipe(recipes, outDir) {
|
|
20389
|
-
const recipeArray = Array.isArray(recipes) ? recipes : [recipes];
|
|
20390
|
-
const result = await buildProject(recipeArray);
|
|
20391
|
-
const decoder = new TextDecoder('utf-8');
|
|
20392
|
-
for (const [rel, bytes] of Object.entries(result)) {
|
|
20393
|
-
const outPath = path$4.join(outDir, rel);
|
|
20394
|
-
await fsp.mkdir(path$4.dirname(outPath), { recursive: true });
|
|
20395
|
-
const ext = path$4.extname(rel).toLowerCase();
|
|
20396
|
-
const isTs = ext === '.ts' || ext === '.tsx' || ext === '.d.ts';
|
|
20397
|
-
if (!isTs) {
|
|
20398
|
-
await fsp.writeFile(outPath, Buffer.from(bytes));
|
|
20399
|
-
continue;
|
|
20400
|
-
}
|
|
20401
|
-
// Attempt to format TS content with Prettier; fall back on error
|
|
20402
|
-
try {
|
|
20403
|
-
const text = typeof bytes === 'string'
|
|
20404
|
-
? bytes
|
|
20405
|
-
: decoder.decode(bytes);
|
|
20406
|
-
const formatted = await prettier.format(text, { filepath: rel });
|
|
20407
|
-
await fsp.writeFile(outPath, formatted, 'utf8');
|
|
18108
|
+
async function commitProjectFiles(files, force) {
|
|
18109
|
+
for (const file of files) {
|
|
18110
|
+
if (force) {
|
|
18111
|
+
await fsp.rename(file.stagedPath, file.outPath);
|
|
20408
18112
|
}
|
|
20409
|
-
|
|
20410
|
-
await fsp.
|
|
18113
|
+
else {
|
|
18114
|
+
await fsp.copyFile(file.stagedPath, file.outPath, constants$2.COPYFILE_EXCL);
|
|
18115
|
+
await fsp.rm(file.stagedPath);
|
|
20411
18116
|
}
|
|
20412
18117
|
}
|
|
20413
18118
|
}
|
|
20414
|
-
async function scaffoldProject(
|
|
18119
|
+
async function scaffoldProject(sources, outDir, options = {}) {
|
|
20415
18120
|
const scaffoldSpinner = ora({
|
|
20416
18121
|
text: `Scaffolding in ${chalk.gray(outDir)} ...`,
|
|
20417
18122
|
stream: process.stderr,
|
|
@@ -20420,8 +18125,24 @@ async function scaffoldProject(recipes, outDir) {
|
|
|
20420
18125
|
isEnabled: process.stderr.isTTY,
|
|
20421
18126
|
}).start();
|
|
20422
18127
|
try {
|
|
20423
|
-
|
|
20424
|
-
|
|
18128
|
+
const resolvedOutDir = path$5.resolve(outDir);
|
|
18129
|
+
const force = options.force === true;
|
|
18130
|
+
const files = buildProjectFiles(sources, resolvedOutDir);
|
|
18131
|
+
assertManifestPaths(files);
|
|
18132
|
+
await ensureTargetDirectory(resolvedOutDir, force);
|
|
18133
|
+
await assertOutputPaths(files, resolvedOutDir);
|
|
18134
|
+
await createOutputDirectories(files);
|
|
18135
|
+
// Recheck after directory creation so no file is changed when a generated
|
|
18136
|
+
// path has an incompatible shape or resolves through a symlink.
|
|
18137
|
+
await assertOutputPaths(files, resolvedOutDir);
|
|
18138
|
+
const stagedFiles = await stageProjectFiles(files);
|
|
18139
|
+
try {
|
|
18140
|
+
await assertOutputPaths(files, resolvedOutDir);
|
|
18141
|
+
await commitProjectFiles(stagedFiles, force);
|
|
18142
|
+
}
|
|
18143
|
+
finally {
|
|
18144
|
+
await Promise.allSettled(stagedFiles.map((file) => fsp.rm(file.stagedPath, { force: true })));
|
|
18145
|
+
}
|
|
20425
18146
|
scaffoldSpinner.stopAndPersist({
|
|
20426
18147
|
symbol: chalk.green('✔'),
|
|
20427
18148
|
text: 'Project files created',
|
|
@@ -20436,45 +18157,6 @@ async function scaffoldProject(recipes, outDir) {
|
|
|
20436
18157
|
}
|
|
20437
18158
|
}
|
|
20438
18159
|
|
|
20439
|
-
const VERSION = "0.4.2";
|
|
20440
|
-
const NODE_ENGINE = ">=20.19.0 <21.0.0-0 || >=22.12.0 <23.0.0-0 || >=24.0.0";
|
|
20441
|
-
|
|
20442
|
-
/**
|
|
20443
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
20444
|
-
*
|
|
20445
|
-
* This source code is licensed under the MIT license found in the
|
|
20446
|
-
* LICENSE file in the root directory of this source tree.
|
|
20447
|
-
*/
|
|
20448
|
-
const DEFAULT_ASSETS_BASE = process.env.IWSDK_ASSET_BASE ||
|
|
20449
|
-
`https://cdn.jsdelivr.net/npm/@iwsdk/starter-assets@${VERSION}/dist`;
|
|
20450
|
-
async function fetchJSON(url, fallbackUrl) {
|
|
20451
|
-
let res = await fetch(url);
|
|
20452
|
-
// Fallback to @latest if pinned version not found (e.g., jsDelivr indexing delay)
|
|
20453
|
-
if (!res.ok && res.status === 404 && fallbackUrl) {
|
|
20454
|
-
res = await fetch(fallbackUrl);
|
|
20455
|
-
}
|
|
20456
|
-
if (!res.ok) {
|
|
20457
|
-
throw new Error(`HTTP ${res.status} for ${url}`);
|
|
20458
|
-
}
|
|
20459
|
-
return (await res.json());
|
|
20460
|
-
}
|
|
20461
|
-
async function fetchRecipesIndex(base = DEFAULT_ASSETS_BASE) {
|
|
20462
|
-
const url = new URL('recipes/index.json', base.endsWith('/') ? base : base + '/').toString();
|
|
20463
|
-
// If using versioned base, create fallback to @latest
|
|
20464
|
-
const fallbackUrl = base === DEFAULT_ASSETS_BASE
|
|
20465
|
-
? url.replace(`@${VERSION}/`, '@latest/')
|
|
20466
|
-
: undefined;
|
|
20467
|
-
return fetchJSON(url, fallbackUrl);
|
|
20468
|
-
}
|
|
20469
|
-
async function fetchRecipeByFileName(fileName, base = DEFAULT_ASSETS_BASE) {
|
|
20470
|
-
const url = new URL(`recipes/${fileName}`, base.endsWith('/') ? base : base + '/').toString();
|
|
20471
|
-
// If using versioned base, create fallback to @latest
|
|
20472
|
-
const fallbackUrl = base === DEFAULT_ASSETS_BASE
|
|
20473
|
-
? url.replace(`@${VERSION}/`, '@latest/')
|
|
20474
|
-
: undefined;
|
|
20475
|
-
return fetchJSON(url, fallbackUrl);
|
|
20476
|
-
}
|
|
20477
|
-
|
|
20478
18160
|
/**
|
|
20479
18161
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
20480
18162
|
*
|
|
@@ -20484,7 +18166,7 @@ async function fetchRecipeByFileName(fileName, base = DEFAULT_ASSETS_BASE) {
|
|
|
20484
18166
|
/**
|
|
20485
18167
|
* Directory inside scaffolded projects where SDK package tarballs are stored.
|
|
20486
18168
|
* Preserves the monorepo's subdirectory hierarchy so that internal `file:`
|
|
20487
|
-
* references between packages (e.g., core →
|
|
18169
|
+
* references between packages (e.g., core → scene-composition) resolve correctly.
|
|
20488
18170
|
*/
|
|
20489
18171
|
const SDK_PACKAGES_DIR = '.sdk-packages';
|
|
20490
18172
|
/**
|
|
@@ -20492,44 +18174,7 @@ const SDK_PACKAGES_DIR = '.sdk-packages';
|
|
|
20492
18174
|
*/
|
|
20493
18175
|
const DEFAULT_BUNDLE_URL = 'https://d1erq8v22udnml.cloudfront.net/sdk-bundle';
|
|
20494
18176
|
/**
|
|
20495
|
-
*
|
|
20496
|
-
* Absolute URLs pass through unchanged (backwards compatible).
|
|
20497
|
-
* Returns a new recipe object (no mutation).
|
|
20498
|
-
*/
|
|
20499
|
-
function prependBaseUrl(recipe, base) {
|
|
20500
|
-
const edits = recipe.edits;
|
|
20501
|
-
if (!edits) {
|
|
20502
|
-
return recipe;
|
|
20503
|
-
}
|
|
20504
|
-
const baseWithSlash = base.endsWith('/') ? base : base + '/';
|
|
20505
|
-
const newEdits = {};
|
|
20506
|
-
let changed = false;
|
|
20507
|
-
for (const [key, value] of Object.entries(edits)) {
|
|
20508
|
-
if (value &&
|
|
20509
|
-
typeof value === 'object' &&
|
|
20510
|
-
'url' in value &&
|
|
20511
|
-
typeof value.url === 'string') {
|
|
20512
|
-
const url = value.url;
|
|
20513
|
-
if (!URL.canParse(url)) {
|
|
20514
|
-
// Relative URL — prepend base
|
|
20515
|
-
newEdits[key] = { ...value, url: new URL(url, baseWithSlash).href };
|
|
20516
|
-
changed = true;
|
|
20517
|
-
}
|
|
20518
|
-
else {
|
|
20519
|
-
newEdits[key] = value;
|
|
20520
|
-
}
|
|
20521
|
-
}
|
|
20522
|
-
else {
|
|
20523
|
-
newEdits[key] = value;
|
|
20524
|
-
}
|
|
20525
|
-
}
|
|
20526
|
-
if (!changed) {
|
|
20527
|
-
return recipe;
|
|
20528
|
-
}
|
|
20529
|
-
return { ...recipe, edits: newEdits };
|
|
20530
|
-
}
|
|
20531
|
-
/**
|
|
20532
|
-
* Default source: fetches recipes and packages from jsDelivr CDN / npm registry.
|
|
18177
|
+
* Default source: package dependencies resolve from the npm registry.
|
|
20533
18178
|
*/
|
|
20534
18179
|
class NpmSource {
|
|
20535
18180
|
constructor() {
|
|
@@ -20538,30 +18183,21 @@ class NpmSource {
|
|
|
20538
18183
|
async prepare() {
|
|
20539
18184
|
// no-op
|
|
20540
18185
|
}
|
|
20541
|
-
async fetchIndex() {
|
|
20542
|
-
return fetchRecipesIndex();
|
|
20543
|
-
}
|
|
20544
|
-
async fetchRecipe(fileName) {
|
|
20545
|
-
return fetchRecipeByFileName(fileName);
|
|
20546
|
-
}
|
|
20547
18186
|
getPackageInstallSpec(_name) {
|
|
20548
|
-
return undefined; //
|
|
18187
|
+
return undefined; // generated package.json uses the matching SDK version
|
|
18188
|
+
}
|
|
18189
|
+
getPackageInstallSpecs() {
|
|
18190
|
+
return {};
|
|
20549
18191
|
}
|
|
20550
18192
|
async downloadPackages(_destDir) {
|
|
20551
18193
|
// no-op — npm resolves packages from the registry
|
|
20552
18194
|
}
|
|
20553
|
-
resolveRecipeUrls(recipe) {
|
|
20554
|
-
const base = DEFAULT_ASSETS_BASE.endsWith('/')
|
|
20555
|
-
? DEFAULT_ASSETS_BASE
|
|
20556
|
-
: DEFAULT_ASSETS_BASE + '/';
|
|
20557
|
-
return prependBaseUrl(recipe, base);
|
|
20558
|
-
}
|
|
20559
18195
|
async cleanup() {
|
|
20560
18196
|
// no-op
|
|
20561
18197
|
}
|
|
20562
18198
|
}
|
|
20563
18199
|
/**
|
|
20564
|
-
* Bundle source: fetches
|
|
18200
|
+
* Bundle source: fetches packages from a remote HTTP(S) bundle URL.
|
|
20565
18201
|
* Resolves @iwsdk/* packages to local file: paths after downloading tarballs.
|
|
20566
18202
|
*/
|
|
20567
18203
|
class BundleSource {
|
|
@@ -20580,14 +18216,12 @@ class BundleSource {
|
|
|
20580
18216
|
throw new Error(`Unsupported bundle schema version: ${this.manifest.schemaVersion}. ` +
|
|
20581
18217
|
'Please update your CLI or use a compatible bundle.');
|
|
20582
18218
|
}
|
|
20583
|
-
|
|
20584
|
-
|
|
20585
|
-
|
|
20586
|
-
|
|
20587
|
-
|
|
20588
|
-
|
|
20589
|
-
const content = await this.readContent(`recipes/${fileName}`);
|
|
20590
|
-
return JSON.parse(content);
|
|
18219
|
+
if (this.manifest.sdkVersion !== VERSION) {
|
|
18220
|
+
throw new Error(`SDK bundle version ${JSON.stringify(this.manifest.sdkVersion)} does not match @iwsdk/create ${JSON.stringify(VERSION)}. Use a Create package from the same SDK build.`);
|
|
18221
|
+
}
|
|
18222
|
+
for (const packagePath of Object.values(this.manifest.packages)) {
|
|
18223
|
+
this.manifestSubPath(packagePath);
|
|
18224
|
+
}
|
|
20591
18225
|
}
|
|
20592
18226
|
getPackageInstallSpec(name) {
|
|
20593
18227
|
if (!this.manifest) {
|
|
@@ -20599,6 +18233,15 @@ class BundleSource {
|
|
|
20599
18233
|
}
|
|
20600
18234
|
return `file:${SDK_PACKAGES_DIR}/${this.manifestSubPath(tgzRelPath)}`;
|
|
20601
18235
|
}
|
|
18236
|
+
getPackageInstallSpecs() {
|
|
18237
|
+
if (!this.manifest) {
|
|
18238
|
+
return {};
|
|
18239
|
+
}
|
|
18240
|
+
return Object.fromEntries(Object.entries(this.manifest.packages).map(([name, tgzRelPath]) => [
|
|
18241
|
+
name,
|
|
18242
|
+
`file:${SDK_PACKAGES_DIR}/${this.manifestSubPath(tgzRelPath)}`,
|
|
18243
|
+
]));
|
|
18244
|
+
}
|
|
20602
18245
|
async downloadPackages(destDir) {
|
|
20603
18246
|
if (!this.manifest) {
|
|
20604
18247
|
throw new Error('BundleSource.prepare() must be called before downloadPackages()');
|
|
@@ -20618,9 +18261,6 @@ class BundleSource {
|
|
|
20618
18261
|
await writeFile(destFile, buffer);
|
|
20619
18262
|
}
|
|
20620
18263
|
}
|
|
20621
|
-
resolveRecipeUrls(recipe) {
|
|
20622
|
-
return prependBaseUrl(recipe, this.baseUrl);
|
|
20623
|
-
}
|
|
20624
18264
|
async cleanup() {
|
|
20625
18265
|
// no-op (no temp dir)
|
|
20626
18266
|
}
|
|
@@ -20643,11 +18283,28 @@ class BundleSource {
|
|
|
20643
18283
|
return new URL(relativePath, base).toString();
|
|
20644
18284
|
}
|
|
20645
18285
|
/**
|
|
20646
|
-
*
|
|
18286
|
+
* Validate a manifest path and strip its leading `packages/` prefix.
|
|
20647
18287
|
* e.g. `packages/core/iwsdk-core.tgz` → `core/iwsdk-core.tgz`
|
|
20648
18288
|
*/
|
|
20649
18289
|
manifestSubPath(relPath) {
|
|
20650
|
-
|
|
18290
|
+
if (typeof relPath !== 'string') {
|
|
18291
|
+
throw new Error(`Invalid bundle package path: "${String(relPath)}".`);
|
|
18292
|
+
}
|
|
18293
|
+
const prefix = 'packages/';
|
|
18294
|
+
const subPath = relPath.startsWith(prefix)
|
|
18295
|
+
? relPath.slice(prefix.length)
|
|
18296
|
+
: '';
|
|
18297
|
+
const hasUnsafeSegment = subPath
|
|
18298
|
+
.split('/')
|
|
18299
|
+
.some((segment) => segment === '' || segment === '.' || segment === '..');
|
|
18300
|
+
if (subPath === '' ||
|
|
18301
|
+
subPath.includes('\0') ||
|
|
18302
|
+
subPath.includes('\\') ||
|
|
18303
|
+
hasUnsafeSegment ||
|
|
18304
|
+
/^[a-zA-Z]:/.test(subPath)) {
|
|
18305
|
+
throw new Error(`Invalid bundle package path: "${relPath}".`);
|
|
18306
|
+
}
|
|
18307
|
+
return subPath;
|
|
20651
18308
|
}
|
|
20652
18309
|
}
|
|
20653
18310
|
/**
|
|
@@ -20671,6 +18328,94 @@ function resolveSource(canaryFlag) {
|
|
|
20671
18328
|
* This source code is licensed under the MIT license found in the
|
|
20672
18329
|
* LICENSE file in the root directory of this source tree.
|
|
20673
18330
|
*/
|
|
18331
|
+
function hasFlag(args, flag) {
|
|
18332
|
+
return args.includes(flag);
|
|
18333
|
+
}
|
|
18334
|
+
function resolveBooleanFlag(args, enabledFlag, disabledFlag) {
|
|
18335
|
+
const enabled = hasFlag(args, enabledFlag);
|
|
18336
|
+
const disabled = hasFlag(args, disabledFlag);
|
|
18337
|
+
if (enabled && disabled) {
|
|
18338
|
+
throw new Error(`Use either ${enabledFlag} or ${disabledFlag}, not both.`);
|
|
18339
|
+
}
|
|
18340
|
+
if (disabled) {
|
|
18341
|
+
return false;
|
|
18342
|
+
}
|
|
18343
|
+
if (enabled) {
|
|
18344
|
+
return true;
|
|
18345
|
+
}
|
|
18346
|
+
return undefined;
|
|
18347
|
+
}
|
|
18348
|
+
function resolveExplicitTarget(options, args) {
|
|
18349
|
+
const target = options.target;
|
|
18350
|
+
const mode = options.mode;
|
|
18351
|
+
const xrFlag = hasFlag(args, '--xr');
|
|
18352
|
+
const noXrFlag = hasFlag(args, '--no-xr');
|
|
18353
|
+
if (target && target !== 'vr' && target !== 'ar' && target !== 'browser') {
|
|
18354
|
+
throw new Error(`Invalid --target "${target}". Must be "vr", "ar", or "browser".`);
|
|
18355
|
+
}
|
|
18356
|
+
if (mode && mode !== 'vr' && mode !== 'ar') {
|
|
18357
|
+
throw new Error(`Invalid --mode "${mode}". Must be "vr" or "ar".`);
|
|
18358
|
+
}
|
|
18359
|
+
if (xrFlag && noXrFlag) {
|
|
18360
|
+
throw new Error('Use either --xr or --no-xr, not both.');
|
|
18361
|
+
}
|
|
18362
|
+
if (target === 'browser' && (mode || xrFlag)) {
|
|
18363
|
+
throw new Error('--target browser cannot be combined with --mode or --xr.');
|
|
18364
|
+
}
|
|
18365
|
+
if (target && target !== 'browser' && noXrFlag) {
|
|
18366
|
+
throw new Error(`--target ${target} cannot be combined with --no-xr.`);
|
|
18367
|
+
}
|
|
18368
|
+
if (target && mode && target !== mode) {
|
|
18369
|
+
throw new Error(`--target ${target} conflicts with --mode ${mode}.`);
|
|
18370
|
+
}
|
|
18371
|
+
if (mode && noXrFlag) {
|
|
18372
|
+
throw new Error('--mode cannot be combined with --no-xr.');
|
|
18373
|
+
}
|
|
18374
|
+
if (target) {
|
|
18375
|
+
return target;
|
|
18376
|
+
}
|
|
18377
|
+
if (noXrFlag) {
|
|
18378
|
+
return 'browser';
|
|
18379
|
+
}
|
|
18380
|
+
if (mode) {
|
|
18381
|
+
return mode;
|
|
18382
|
+
}
|
|
18383
|
+
if (xrFlag) {
|
|
18384
|
+
return 'vr';
|
|
18385
|
+
}
|
|
18386
|
+
return undefined;
|
|
18387
|
+
}
|
|
18388
|
+
function isInsideGitWorkTree(directory) {
|
|
18389
|
+
try {
|
|
18390
|
+
return (execFileSync('git', ['rev-parse', '--is-inside-work-tree'], {
|
|
18391
|
+
cwd: directory,
|
|
18392
|
+
encoding: 'utf8',
|
|
18393
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
18394
|
+
}).trim() === 'true');
|
|
18395
|
+
}
|
|
18396
|
+
catch {
|
|
18397
|
+
return false;
|
|
18398
|
+
}
|
|
18399
|
+
}
|
|
18400
|
+
function printConfigurationSummary(result) {
|
|
18401
|
+
const config = {
|
|
18402
|
+
target: result.target,
|
|
18403
|
+
xrEnabled: result.xrEnabled,
|
|
18404
|
+
mode: result.mode,
|
|
18405
|
+
featureFlags: result.featureFlags,
|
|
18406
|
+
xrFeatureStates: result.xrFeatureStates,
|
|
18407
|
+
};
|
|
18408
|
+
const enabledFeatures = Object.entries(result.featureFlags)
|
|
18409
|
+
.filter(([key, enabled]) => key !== 'locomotionUseWorker' && enabled)
|
|
18410
|
+
.map(([key]) => FEATURE_CATALOG[key].label);
|
|
18411
|
+
console.log(chalk.bold('\nProject configuration'));
|
|
18412
|
+
console.log(` Starting point: ${EXPERIENCE_TARGETS[result.target].label}`);
|
|
18413
|
+
console.log(` Language: ${result.language === 'ts' ? 'TypeScript' : 'JavaScript'}`);
|
|
18414
|
+
console.log(` SDK features: ${enabledFeatures.length > 0 ? enabledFeatures.join(', ') : 'none'}`);
|
|
18415
|
+
const manifest = createProjectManifest(config);
|
|
18416
|
+
console.log(` Runtime: ${manifest.world.xr === false ? 'Desktop 3D' : manifest.world.xr.mode.toUpperCase()}`);
|
|
18417
|
+
console.log(chalk.dim(' Change declarative settings later in iwsdk.config.json; keep systems in src/index.ts.\n'));
|
|
18418
|
+
}
|
|
20674
18419
|
async function main() {
|
|
20675
18420
|
// Enforce Node engines range from generated version.ts
|
|
20676
18421
|
const nodeVer = process.versions.node;
|
|
@@ -20679,7 +18424,7 @@ async function main() {
|
|
|
20679
18424
|
console.error(chalk.red(`Unsupported Node.js version: ${nodeVer}.\nRequires Node ${requiredRange}. Please upgrade (e.g., via nvm or Volta) and try again.`));
|
|
20680
18425
|
process.exit(1);
|
|
20681
18426
|
}
|
|
20682
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
18427
|
+
const __filename = fileURLToPath$1(import.meta.url);
|
|
20683
18428
|
const __dirname = dirname(__filename);
|
|
20684
18429
|
const pkgPath = join(__dirname, '../package.json');
|
|
20685
18430
|
let version = '0.0.0';
|
|
@@ -20707,43 +18452,37 @@ IWSDK Create CLI v${VERSION}\nNode ${process.version}`;
|
|
|
20707
18452
|
.name('Create IWSDK')
|
|
20708
18453
|
.description('Official CLI for creating Immersive Web SDK projects')
|
|
20709
18454
|
.version(version)
|
|
20710
|
-
.argument('[name]', 'Project
|
|
18455
|
+
.argument('[name]', 'Project directory (use "." for the current directory)')
|
|
20711
18456
|
.option('--canary [url]', 'Use canary SDK bundle (optionally from a custom URL)')
|
|
20712
18457
|
.option('-y, --yes', 'Use defaults and skip prompts')
|
|
20713
|
-
.option('--
|
|
20714
|
-
.option('--
|
|
20715
|
-
.option('--
|
|
20716
|
-
.option('--
|
|
20717
|
-
.option('--
|
|
20718
|
-
.option('--no-
|
|
20719
|
-
.option('--install', 'Install dependencies after scaffolding'
|
|
18458
|
+
.option('--force', 'Overwrite conflicting generated files in a non-empty target directory')
|
|
18459
|
+
.option('--target <target>', 'Starting point: vr, ar, or browser')
|
|
18460
|
+
.option('--mode <mode>', 'XR mode alias: vr or ar')
|
|
18461
|
+
.option('--language <lang>', 'Language: ts or js')
|
|
18462
|
+
.option('--xr', 'Use an XR starting point (VR unless --mode is provided)')
|
|
18463
|
+
.option('--no-xr', 'Use the desktop 3D starting point')
|
|
18464
|
+
.option('--install', 'Install dependencies after scaffolding')
|
|
20720
18465
|
.option('--no-install', 'Skip dependency installation')
|
|
20721
|
-
.option('--git', 'Initialize git repository'
|
|
18466
|
+
.option('--git', 'Initialize git repository')
|
|
20722
18467
|
.option('--no-git', 'Skip git initialization')
|
|
20723
|
-
.option('--locomotion', 'Enable locomotion feature'
|
|
18468
|
+
.option('--locomotion', 'Enable locomotion feature')
|
|
20724
18469
|
.option('--no-locomotion', 'Disable locomotion feature')
|
|
20725
|
-
.option('--grabbing', 'Enable grabbing feature'
|
|
18470
|
+
.option('--grabbing', 'Enable grabbing feature')
|
|
20726
18471
|
.option('--no-grabbing', 'Disable grabbing feature')
|
|
20727
|
-
.option('--physics', 'Enable physics feature'
|
|
20728
|
-
.option('--no-physics', 'Disable physics feature
|
|
20729
|
-
.option('--scene-understanding', 'Enable scene understanding (AR mode)'
|
|
18472
|
+
.option('--physics', 'Enable physics feature')
|
|
18473
|
+
.option('--no-physics', 'Disable physics feature')
|
|
18474
|
+
.option('--scene-understanding', 'Enable scene understanding (AR mode)')
|
|
20730
18475
|
.option('--no-scene-understanding', 'Disable scene understanding')
|
|
20731
|
-
.option('--environment-raycast', 'Enable environment raycast (AR mode)'
|
|
18476
|
+
.option('--environment-raycast', 'Enable environment raycast (AR mode)')
|
|
20732
18477
|
.option('--no-environment-raycast', 'Disable environment raycast')
|
|
20733
|
-
.option('--ai-tools <tools>', 'AI tools to configure (comma-separated: claude,cursor,copilot,codex; or "none")', 'claude,cursor,copilot,codex')
|
|
20734
18478
|
.action((n, opts) => {
|
|
20735
18479
|
nameArg = n;
|
|
20736
18480
|
cliOpts = opts;
|
|
20737
18481
|
});
|
|
20738
18482
|
program.parse(process.argv);
|
|
20739
18483
|
try {
|
|
20740
|
-
//
|
|
20741
|
-
|
|
20742
|
-
cliOpts.mode !== 'vr' &&
|
|
20743
|
-
cliOpts.mode !== 'ar') {
|
|
20744
|
-
console.error(chalk.red(`Invalid --mode "${cliOpts.mode}". Must be "vr" or "ar".`));
|
|
20745
|
-
process.exit(1);
|
|
20746
|
-
}
|
|
18484
|
+
// Collapse the target selector and legacy XR flags into one starting point.
|
|
18485
|
+
const explicitTarget = resolveExplicitTarget(cliOpts, process.argv.slice(2));
|
|
20747
18486
|
if (cliOpts.language !== undefined &&
|
|
20748
18487
|
cliOpts.language !== 'ts' &&
|
|
20749
18488
|
cliOpts.language !== 'js') {
|
|
@@ -20760,10 +18499,7 @@ IWSDK Create CLI v${VERSION}\nNode ${process.version}`;
|
|
|
20760
18499
|
}
|
|
20761
18500
|
// Warn if flags are provided without --yes (they only take effect in non-interactive mode)
|
|
20762
18501
|
const explicitFlags = [
|
|
20763
|
-
'--mode',
|
|
20764
18502
|
'--language',
|
|
20765
|
-
'--metaspatial',
|
|
20766
|
-
'--no-metaspatial',
|
|
20767
18503
|
'--install',
|
|
20768
18504
|
'--no-install',
|
|
20769
18505
|
'--git',
|
|
@@ -20778,108 +18514,71 @@ IWSDK Create CLI v${VERSION}\nNode ${process.version}`;
|
|
|
20778
18514
|
'--no-scene-understanding',
|
|
20779
18515
|
'--environment-raycast',
|
|
20780
18516
|
'--no-environment-raycast',
|
|
20781
|
-
'--ai-tools',
|
|
20782
18517
|
];
|
|
20783
|
-
const hasExplicitFlags =
|
|
18518
|
+
const hasExplicitFlags = explicitFlags.some((flag) => hasCliOption(process.argv, flag));
|
|
20784
18519
|
if (hasExplicitFlags && !cliOpts.yes) {
|
|
20785
|
-
console.warn(chalk.yellow('Warning: CLI flags (--
|
|
18520
|
+
console.warn(chalk.yellow('Warning: advanced CLI flags (--language, --physics, etc.) only take effect with -y/--yes.\n' +
|
|
20786
18521
|
'Add -y to use non-interactive mode, or remove flags for interactive prompts.'));
|
|
20787
18522
|
}
|
|
20788
18523
|
// Build PromptResult from CLI flags or interactive prompts
|
|
20789
18524
|
let res;
|
|
20790
18525
|
if (cliOpts.yes) {
|
|
20791
|
-
const
|
|
20792
|
-
|
|
20793
|
-
const
|
|
20794
|
-
const
|
|
20795
|
-
|
|
20796
|
-
|
|
20797
|
-
|
|
20798
|
-
|
|
20799
|
-
|
|
20800
|
-
|
|
18526
|
+
const target = explicitTarget ?? 'vr';
|
|
18527
|
+
validateFeatureOptionsForTarget(target, process.argv);
|
|
18528
|
+
const language = cliOpts.language ?? 'ts';
|
|
18529
|
+
const overrides = {};
|
|
18530
|
+
const locomotion = resolveBooleanFlag(process.argv, '--locomotion', '--no-locomotion');
|
|
18531
|
+
const grabbing = resolveBooleanFlag(process.argv, '--grabbing', '--no-grabbing');
|
|
18532
|
+
const physics = resolveBooleanFlag(process.argv, '--physics', '--no-physics');
|
|
18533
|
+
const sceneUnderstanding = resolveBooleanFlag(process.argv, '--scene-understanding', '--no-scene-understanding');
|
|
18534
|
+
const environmentRaycast = resolveBooleanFlag(process.argv, '--environment-raycast', '--no-environment-raycast');
|
|
18535
|
+
if (locomotion !== undefined) {
|
|
18536
|
+
overrides.locomotionEnabled = locomotion;
|
|
20801
18537
|
}
|
|
20802
|
-
|
|
20803
|
-
|
|
20804
|
-
|
|
20805
|
-
|
|
20806
|
-
.
|
|
20807
|
-
|
|
20808
|
-
|
|
20809
|
-
|
|
20810
|
-
: rawAiTools.filter((t) => validAiTools.includes(t));
|
|
20811
|
-
const locomotionEnabled = xrEnabled && mode === 'vr' ? (cliOpts.locomotion ?? true) : false;
|
|
20812
|
-
// MSE detection for scripted mode (no auto-install — requires TOS consent)
|
|
20813
|
-
let mseInstallResult;
|
|
20814
|
-
if (metaspatial) {
|
|
20815
|
-
const platform = detectPlatform();
|
|
20816
|
-
const existingVersion = await detectMSEVersion(platform);
|
|
20817
|
-
if (existingVersion && isVersionSufficient(existingVersion)) {
|
|
20818
|
-
mseInstallResult = {
|
|
20819
|
-
installed: true,
|
|
20820
|
-
version: existingVersion,
|
|
20821
|
-
manual: false,
|
|
20822
|
-
};
|
|
20823
|
-
}
|
|
20824
|
-
else if (existingVersion) {
|
|
20825
|
-
throw new Error(`Meta Spatial Editor ${existingVersion} is installed but version ${MSE_MIN_VERSION}+ is required.\n` +
|
|
20826
|
-
'Please upgrade manually, or run without --yes to upgrade interactively.\n' +
|
|
20827
|
-
'Download: https://developers.meta.com/horizon/documentation/spatial-sdk/spatial-editor-overview');
|
|
20828
|
-
}
|
|
20829
|
-
else {
|
|
20830
|
-
throw new Error('Meta Spatial Editor is required for --metaspatial but is not installed.\n' +
|
|
20831
|
-
'Installation requires accepting the Terms of Service and cannot be automated with --yes.\n' +
|
|
20832
|
-
'Run without --yes to install interactively, or install manually:\n' +
|
|
20833
|
-
'https://developers.meta.com/horizon/documentation/spatial-sdk/spatial-editor-overview');
|
|
20834
|
-
}
|
|
18538
|
+
if (grabbing !== undefined) {
|
|
18539
|
+
overrides.grabbingEnabled = grabbing;
|
|
18540
|
+
}
|
|
18541
|
+
if (physics !== undefined) {
|
|
18542
|
+
overrides.physicsEnabled = physics;
|
|
18543
|
+
}
|
|
18544
|
+
if (sceneUnderstanding !== undefined) {
|
|
18545
|
+
overrides.sceneUnderstandingEnabled = sceneUnderstanding;
|
|
20835
18546
|
}
|
|
18547
|
+
if (environmentRaycast !== undefined) {
|
|
18548
|
+
overrides.environmentRaycastEnabled = environmentRaycast;
|
|
18549
|
+
}
|
|
18550
|
+
const configuration = getRecommendedConfiguration(target, overrides);
|
|
20836
18551
|
res = {
|
|
20837
18552
|
name: nameArg || 'iwsdk-app',
|
|
20838
|
-
|
|
20839
|
-
|
|
20840
|
-
|
|
20841
|
-
|
|
20842
|
-
mode,
|
|
18553
|
+
installNow: resolveBooleanFlag(process.argv, '--install', '--no-install') ?? true,
|
|
18554
|
+
target,
|
|
18555
|
+
xrEnabled: configuration.xrEnabled,
|
|
18556
|
+
mode: configuration.mode,
|
|
20843
18557
|
language,
|
|
20844
|
-
|
|
20845
|
-
|
|
20846
|
-
|
|
20847
|
-
locomotionUseWorker: locomotionEnabled ? true : undefined,
|
|
20848
|
-
grabbingEnabled: xrEnabled ? (cliOpts.grabbing ?? true) : false,
|
|
20849
|
-
physicsEnabled: cliOpts.physics ?? false,
|
|
20850
|
-
sceneUnderstandingEnabled: xrEnabled && mode === 'ar'
|
|
20851
|
-
? (cliOpts.sceneUnderstanding ?? true)
|
|
20852
|
-
: false,
|
|
20853
|
-
environmentRaycastEnabled: xrEnabled && mode === 'ar'
|
|
20854
|
-
? (cliOpts.environmentRaycast ?? true)
|
|
20855
|
-
: false,
|
|
20856
|
-
},
|
|
20857
|
-
gitInit: cliOpts.git ?? true,
|
|
20858
|
-
aiTools,
|
|
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' },
|
|
20871
|
-
mseInstallResult,
|
|
18558
|
+
featureFlags: configuration.featureFlags,
|
|
18559
|
+
gitInit: resolveBooleanFlag(process.argv, '--git', '--no-git') ?? true,
|
|
18560
|
+
xrFeatureStates: configuration.xrFeatureStates,
|
|
20872
18561
|
};
|
|
20873
18562
|
}
|
|
20874
18563
|
else {
|
|
20875
|
-
|
|
20876
|
-
res = await promptFlow(nameArg, xrFlagProvided ? { xrEnabled: cliOpts.xr ?? true } : {});
|
|
18564
|
+
res = await promptFlow(nameArg, { target: explicitTarget });
|
|
20877
18565
|
}
|
|
20878
|
-
// Validate
|
|
20879
|
-
if (
|
|
18566
|
+
// Validate the requested directory (both interactive and non-interactive paths).
|
|
18567
|
+
if (!isValidProjectTarget(res.name)) {
|
|
20880
18568
|
throw new Error(`Invalid project name "${res.name}". ` +
|
|
20881
|
-
'Use only letters, numbers, hyphens, underscores, dots, and @.');
|
|
18569
|
+
'Use "." for the current directory, or use only letters, numbers, hyphens, underscores, dots, and @.');
|
|
18570
|
+
}
|
|
18571
|
+
const projectTarget = resolveProjectTarget(res.name, process.cwd());
|
|
18572
|
+
const hasTargetContent = targetHasContent(projectTarget);
|
|
18573
|
+
if (hasTargetContent && !cliOpts.force) {
|
|
18574
|
+
throw new Error(`${projectTarget.inPlace ? 'Current directory' : `Directory "${projectTarget.displayPath}"`} is not empty. ` +
|
|
18575
|
+
'Re-run with --force to overwrite conflicting generated files; unrelated files will be preserved.');
|
|
18576
|
+
}
|
|
18577
|
+
if (hasTargetContent) {
|
|
18578
|
+
console.warn(chalk.yellow(`Warning: --force will overwrite conflicting generated files in ${projectTarget.displayPath}; unrelated files will be preserved.`));
|
|
20882
18579
|
}
|
|
18580
|
+
res.name = projectTarget.appName;
|
|
18581
|
+
printConfigurationSummary(res);
|
|
20883
18582
|
const source = resolveSource(cliOpts.canary);
|
|
20884
18583
|
// Prepare source (downloads tgz files for remote bundles)
|
|
20885
18584
|
if (source.isBundleMode) {
|
|
@@ -20906,126 +18605,33 @@ IWSDK Create CLI v${VERSION}\nNode ${process.version}`;
|
|
|
20906
18605
|
}
|
|
20907
18606
|
}
|
|
20908
18607
|
try {
|
|
20909
|
-
|
|
20910
|
-
|
|
20911
|
-
|
|
20912
|
-
|
|
20913
|
-
|
|
20914
|
-
|
|
20915
|
-
const recipe = await source.fetchRecipe(found.recipe);
|
|
20916
|
-
// Resolve relative asset URLs in the recipe
|
|
20917
|
-
const resolvedRecipe = source.resolveRecipeUrls(recipe);
|
|
20918
|
-
// Override Chef variables from prompts
|
|
20919
|
-
// Ensure edits exists
|
|
20920
|
-
resolvedRecipe.edits = resolvedRecipe.edits || {};
|
|
20921
|
-
// Project name
|
|
20922
|
-
resolvedRecipe.edits['@appName'] = res.name;
|
|
20923
|
-
// World features (stringified JS object-literal expected by recipes)
|
|
20924
|
-
const ff = res.featureFlags || {
|
|
20925
|
-
locomotionEnabled: res.xrEnabled && res.mode === 'vr',
|
|
20926
|
-
locomotionUseWorker: true,
|
|
20927
|
-
grabbingEnabled: res.xrEnabled,
|
|
20928
|
-
physicsEnabled: false,
|
|
20929
|
-
sceneUnderstandingEnabled: false,
|
|
20930
|
-
environmentRaycastEnabled: false,
|
|
18608
|
+
const configuration = {
|
|
18609
|
+
target: res.target,
|
|
18610
|
+
xrEnabled: res.xrEnabled,
|
|
18611
|
+
mode: res.mode,
|
|
18612
|
+
featureFlags: res.featureFlags,
|
|
18613
|
+
xrFeatureStates: res.xrFeatureStates,
|
|
20931
18614
|
};
|
|
20932
|
-
const
|
|
20933
|
-
|
|
20934
|
-
|
|
20935
|
-
|
|
20936
|
-
:
|
|
20937
|
-
|
|
20938
|
-
|
|
20939
|
-
|
|
20940
|
-
const environmentRaycastLiteral = res.xrEnabled && res.mode === 'ar' && ff.environmentRaycastEnabled
|
|
20941
|
-
? 'true'
|
|
20942
|
-
: 'false';
|
|
20943
|
-
resolvedRecipe.edits['@appFeaturesStr'] =
|
|
20944
|
-
`{ locomotion: ${locomotionLiteral}, grabbing: ${ff.grabbingEnabled ? 'true' : 'false'}, physics: ${ff.physicsEnabled ? 'true' : 'false'}, sceneUnderstanding: ${sceneUnderstandingLiteral}, environmentRaycast: ${environmentRaycastLiteral} }`;
|
|
20945
|
-
// XR features (tri-state -> JS object literal)
|
|
20946
|
-
const toFlag = (s) => s === 'required'
|
|
20947
|
-
? '{ required: true }'
|
|
20948
|
-
: s === 'optional'
|
|
20949
|
-
? 'true'
|
|
20950
|
-
: 'false';
|
|
20951
|
-
const entries = [];
|
|
20952
|
-
for (const [k, v] of Object.entries(res.xrFeatureStates || {})) {
|
|
20953
|
-
entries.push(`${k}: ${toFlag(v)}`);
|
|
20954
|
-
}
|
|
20955
|
-
const xrLiteral = `{ ${entries.join(', ')} }`;
|
|
20956
|
-
resolvedRecipe.edits['@xrFeaturesStr'] = xrLiteral;
|
|
20957
|
-
resolvedRecipe.edits['@xrConfigStr'] = res.xrEnabled
|
|
20958
|
-
? `{ sessionMode: SessionMode.Immersive${res.mode === 'ar' ? 'AR' : 'VR'}, offer: 'always', features: ${xrLiteral} }`
|
|
20959
|
-
: 'false';
|
|
20960
|
-
const outDir = join(process.cwd(), res.name);
|
|
20961
|
-
// Check if target directory already exists and is non-empty
|
|
20962
|
-
if (fs$2.existsSync(outDir) && fs$2.readdirSync(outDir).length > 0) {
|
|
20963
|
-
throw new Error(`Directory "${res.name}" already exists and is not empty. ` +
|
|
20964
|
-
'Please choose a different name or remove the existing directory.');
|
|
20965
|
-
}
|
|
20966
|
-
// Load AI tool configuration recipes based on user selection
|
|
20967
|
-
const aiRecipes = [];
|
|
20968
|
-
if (res.aiTools.includes('codex')) {
|
|
20969
|
-
// AGENTS.md recipe — Codex reads AGENTS.md natively; other tools have
|
|
20970
|
-
// their own config files with equivalent content.
|
|
20971
|
-
try {
|
|
20972
|
-
const rawAgentsRecipe = await source.fetchRecipe('base-agents-config.recipe.json');
|
|
20973
|
-
aiRecipes.push(source.resolveRecipeUrls(rawAgentsRecipe));
|
|
20974
|
-
}
|
|
20975
|
-
catch {
|
|
20976
|
-
// Not yet published — skip silently
|
|
20977
|
-
}
|
|
20978
|
-
}
|
|
20979
|
-
// Claude Code recipe (conditional)
|
|
20980
|
-
if (res.aiTools.includes('claude')) {
|
|
20981
|
-
try {
|
|
20982
|
-
const rawClaudeRecipe = await source.fetchRecipe('base-claude-config.recipe.json');
|
|
20983
|
-
aiRecipes.push(source.resolveRecipeUrls(rawClaudeRecipe));
|
|
20984
|
-
}
|
|
20985
|
-
catch {
|
|
20986
|
-
// Not yet published — skip silently
|
|
20987
|
-
}
|
|
20988
|
-
}
|
|
20989
|
-
// Cursor recipe (conditional)
|
|
20990
|
-
if (res.aiTools.includes('cursor')) {
|
|
20991
|
-
try {
|
|
20992
|
-
const rawCursorRecipe = await source.fetchRecipe('base-cursor-config.recipe.json');
|
|
20993
|
-
aiRecipes.push(source.resolveRecipeUrls(rawCursorRecipe));
|
|
20994
|
-
}
|
|
20995
|
-
catch {
|
|
20996
|
-
// Not yet published — skip silently
|
|
20997
|
-
}
|
|
20998
|
-
}
|
|
20999
|
-
// Copilot recipe (conditional)
|
|
21000
|
-
if (res.aiTools.includes('copilot')) {
|
|
21001
|
-
try {
|
|
21002
|
-
const rawCopilotRecipe = await source.fetchRecipe('base-copilot-config.recipe.json');
|
|
21003
|
-
aiRecipes.push(source.resolveRecipeUrls(rawCopilotRecipe));
|
|
21004
|
-
}
|
|
21005
|
-
catch {
|
|
21006
|
-
// Not yet published — skip silently
|
|
21007
|
-
}
|
|
21008
|
-
}
|
|
21009
|
-
// Codex recipe (conditional)
|
|
21010
|
-
if (res.aiTools.includes('codex')) {
|
|
21011
|
-
try {
|
|
21012
|
-
const rawCodexRecipe = await source.fetchRecipe('base-codex-config.recipe.json');
|
|
21013
|
-
aiRecipes.push(source.resolveRecipeUrls(rawCodexRecipe));
|
|
21014
|
-
}
|
|
21015
|
-
catch {
|
|
21016
|
-
// Not yet published — skip silently
|
|
21017
|
-
}
|
|
21018
|
-
}
|
|
21019
|
-
const recipes = [resolvedRecipe, ...aiRecipes];
|
|
21020
|
-
await scaffoldProject(recipes, outDir);
|
|
18615
|
+
const outDir = projectTarget.outDir;
|
|
18616
|
+
const projectFiles = await buildStarterProjectFiles({
|
|
18617
|
+
appName: res.name,
|
|
18618
|
+
configuration,
|
|
18619
|
+
language: res.language,
|
|
18620
|
+
packageSource: source,
|
|
18621
|
+
});
|
|
18622
|
+
await scaffoldProject(projectFiles, outDir, { force: cliOpts.force });
|
|
21021
18623
|
// Git init
|
|
21022
|
-
if (res.gitInit
|
|
18624
|
+
if (res.gitInit &&
|
|
18625
|
+
!(projectTarget.inPlace && isInsideGitWorkTree(outDir))) {
|
|
21023
18626
|
try {
|
|
21024
18627
|
const gitInit = spawn$1('git', ['init'], {
|
|
21025
18628
|
cwd: outDir,
|
|
21026
18629
|
stdio: 'ignore',
|
|
21027
18630
|
});
|
|
21028
|
-
await new Promise((resolve) =>
|
|
18631
|
+
await new Promise((resolve) => {
|
|
18632
|
+
gitInit.once('error', () => resolve());
|
|
18633
|
+
gitInit.once('exit', () => resolve());
|
|
18634
|
+
});
|
|
21029
18635
|
}
|
|
21030
18636
|
catch { }
|
|
21031
18637
|
}
|
|
@@ -21061,47 +18667,26 @@ IWSDK Create CLI v${VERSION}\nNode ${process.version}`;
|
|
|
21061
18667
|
else {
|
|
21062
18668
|
await installDependencies(outDir);
|
|
21063
18669
|
}
|
|
18670
|
+
await warmupReference(outDir);
|
|
21064
18671
|
}
|
|
21065
|
-
// Write MCP adapter configs for
|
|
21066
|
-
if (res.installNow
|
|
18672
|
+
// Write MCP adapter configs for every supported coding harness.
|
|
18673
|
+
if (res.installNow) {
|
|
21067
18674
|
try {
|
|
21068
18675
|
execFileSync(process.execPath, [
|
|
21069
18676
|
join(outDir, 'node_modules/@iwsdk/cli/dist/cli.js'),
|
|
21070
18677
|
'adapter',
|
|
21071
18678
|
'sync',
|
|
21072
|
-
'--tools',
|
|
21073
|
-
res.aiTools.join(','),
|
|
21074
18679
|
], { cwd: outDir, stdio: 'ignore', timeout: 15000 });
|
|
21075
18680
|
}
|
|
21076
|
-
catch {
|
|
21077
|
-
|
|
18681
|
+
catch (error) {
|
|
18682
|
+
console.warn(chalk.yellow(`Project created, but coding-tool adapter sync failed: ${error instanceof Error ? error.message : String(error)}. ` +
|
|
18683
|
+
'Run "npx iwsdk adapter sync" from the project directory.'));
|
|
21078
18684
|
}
|
|
21079
18685
|
}
|
|
21080
|
-
// Build prerequisites list (e.g., Meta Spatial Editor), including path-aware notes
|
|
21081
18686
|
const prereqs = [...(res.prerequisites || [])];
|
|
21082
|
-
if (res.metaspatial) {
|
|
21083
|
-
const metaProjectPath = join(outDir, 'metaspatial');
|
|
21084
|
-
const metaMainPath = join(metaProjectPath, 'Main.metaspatial');
|
|
21085
|
-
if (res.mseInstallResult?.installed && !res.mseInstallResult.manual) {
|
|
21086
|
-
prereqs.push({
|
|
21087
|
-
level: 'info',
|
|
21088
|
-
message: `Meta Spatial Editor is ready!\n` +
|
|
21089
|
-
`Project Folder: ${metaProjectPath}\n` +
|
|
21090
|
-
`Open in Meta Spatial Editor: ${metaMainPath}`,
|
|
21091
|
-
});
|
|
21092
|
-
}
|
|
21093
|
-
else {
|
|
21094
|
-
prereqs.push({
|
|
21095
|
-
level: 'important',
|
|
21096
|
-
message: `After installing Meta Spatial Editor, open the project:\n` +
|
|
21097
|
-
`Project Folder: ${metaProjectPath}\n` +
|
|
21098
|
-
`Open in Meta Spatial Editor: ${metaMainPath}`,
|
|
21099
|
-
});
|
|
21100
|
-
}
|
|
21101
|
-
}
|
|
21102
18687
|
// Print prerequisites first, then next steps
|
|
21103
18688
|
printPrerequisites(prereqs);
|
|
21104
|
-
printNextSteps(
|
|
18689
|
+
printNextSteps(projectTarget.displayPath, res.installNow, res.actionItems || [], projectTarget.inPlace, res.installNow);
|
|
21105
18690
|
}
|
|
21106
18691
|
finally {
|
|
21107
18692
|
await source.cleanup();
|