@webspatial/builder 0.1.23 → 1.0.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.
@@ -55,6 +55,7 @@ async function run(args) {
55
55
  If the --tryWithoutBuild=true parameter is used, it will be judged whether it is the same as the previous command.
56
56
  If it is the same, it will be defaulted as already compiled, and the compilation will be skipped and the application will be launched directly.
57
57
  */
58
+ // fixme: the cache not invalidate when npm version change
58
59
  if (manifestInfo.fromNet || args['tryWithoutBuild'] === 'true') {
59
60
  // If this command is a new command, go through the build process; otherwise, go through the launch process
60
61
  if (history_1.default.checkManifest(manifestInfo.json) &&
@@ -27,7 +27,7 @@ function configId(manifestJson, bundleId) {
27
27
  }
28
28
  function configStartUrl(manifestJson, base, manifestUrl, isNet) {
29
29
  var _a;
30
- let start_url = (_a = manifestJson.start_url) !== null && _a !== void 0 ? _a : '/index.html';
30
+ let start_url = (_a = manifestJson.start_url) !== null && _a !== void 0 ? _a : '/';
31
31
  const isStartUrl = (0, validate_1.validateURL)(start_url);
32
32
  const hasBase = base.length > 0;
33
33
  if (hasBase) {
@@ -140,34 +140,39 @@ function configDisplay(manifestJson) {
140
140
  }
141
141
  function configMainScene(manifestJson) {
142
142
  var _a, _b;
143
- const resizabilities = ['automatic', 'contentMinSize', 'contentSize'];
143
+ const resizabilities = ['minWidth', 'minHeight', 'maxWidth', 'maxHeight'];
144
144
  let mainScene = {
145
145
  defaultSize: {
146
146
  width: 1280,
147
147
  height: 1280,
148
148
  },
149
- resizability: 'automatic',
149
+ resizability: {},
150
150
  };
151
- if (manifestJson.xr_main_scene) {
152
- if (typeof manifestJson.xr_main_scene === 'object') {
153
- mainScene.defaultSize.width =
154
- Number((_a = manifestJson.xr_main_scene.default_size) === null || _a === void 0 ? void 0 : _a.width) > 0
155
- ? manifestJson.xr_main_scene.default_size.width
156
- : 1280;
157
- mainScene.defaultSize.height =
158
- Number((_b = manifestJson.xr_main_scene.default_size) === null || _b === void 0 ? void 0 : _b.height) > 0
159
- ? manifestJson.xr_main_scene.default_size.height
160
- : 1280;
161
- mainScene.resizability = resizabilities.includes(manifestJson.xr_main_scene.resizability)
162
- ? manifestJson.xr_main_scene.resizability
163
- : 'automatic';
164
- manifestJson.mainScene = mainScene;
165
- }
166
- else if (typeof manifestJson.xr_main_scene === 'string') {
167
- manifestJson.mainScene = 'dynamic'; // only support this
151
+ let hasResizability = false;
152
+ if (manifestJson.xr_main_scene &&
153
+ typeof manifestJson.xr_main_scene === 'object') {
154
+ mainScene.defaultSize.width =
155
+ Number((_a = manifestJson.xr_main_scene.default_size) === null || _a === void 0 ? void 0 : _a.width) > 0
156
+ ? manifestJson.xr_main_scene.default_size.width
157
+ : 1280;
158
+ mainScene.defaultSize.height =
159
+ Number((_b = manifestJson.xr_main_scene.default_size) === null || _b === void 0 ? void 0 : _b.height) > 0
160
+ ? manifestJson.xr_main_scene.default_size.height
161
+ : 1280;
162
+ if (typeof manifestJson.xr_main_scene.resizability === 'object') {
163
+ for (var i = 0; i < resizabilities.length; i++) {
164
+ if (manifestJson.xr_main_scene.resizability[resizabilities[i]] >= 0) {
165
+ hasResizability = true;
166
+ mainScene.resizability[resizabilities[i]] =
167
+ manifestJson.xr_main_scene.resizability[resizabilities[i]];
168
+ }
169
+ }
168
170
  }
169
- // other type like string should be ignored
170
171
  }
172
+ if (!hasResizability) {
173
+ mainScene.resizability = null;
174
+ }
175
+ manifestJson.xr_main_scene = mainScene;
171
176
  }
172
177
  function configDeeplink(manifestJson) {
173
178
  if (manifestJson.protocol_handlers &&
@@ -6,5 +6,6 @@ export declare class PWAGenerator {
6
6
  private static useDefaultManifestJson;
7
7
  static generator(args: PWAInitArgs, isDev?: boolean): Promise<ManifestInfo>;
8
8
  static validate(args: PWAInitArgs, isDev?: boolean): Promise<ManifestInfo>;
9
+ private static compareManifest;
9
10
  static config(manifestInfo: ManifestInfo, args: PWAInitArgs, isDev: boolean): void;
10
11
  }
@@ -49,6 +49,8 @@ class PWAGenerator {
49
49
  manifest = useDefault
50
50
  ? this.defaultManifestJson
51
51
  : await (0, load_1.loadJsonFromDisk)(url);
52
+ manifest =
53
+ isDev && !useDefault ? this.compareManifest(manifest) : manifest;
52
54
  this.useDefaultManifestJson = useDefault;
53
55
  }
54
56
  // check manifest.json
@@ -65,6 +67,18 @@ class PWAGenerator {
65
67
  fromNet: isNetWeb,
66
68
  };
67
69
  }
70
+ static compareManifest(manifest) {
71
+ var _a, _b, _c;
72
+ manifest.name =
73
+ manifest.name && manifest.name.length > 0
74
+ ? manifest.name
75
+ : this.defaultManifestJson.name;
76
+ manifest.display = (_a = manifest.display) !== null && _a !== void 0 ? _a : this.defaultManifestJson.display;
77
+ manifest.start_url =
78
+ (_b = manifest.start_url) !== null && _b !== void 0 ? _b : this.defaultManifestJson.start_url;
79
+ manifest.scope = (_c = manifest.scope) !== null && _c !== void 0 ? _c : this.defaultManifestJson.scope;
80
+ return manifest;
81
+ }
68
82
  // generate manifest
69
83
  static config(manifestInfo, args, isDev) {
70
84
  var _a;
@@ -86,7 +100,7 @@ PWAGenerator.defaultBundleId = 'com.webspatial.test';
86
100
  PWAGenerator.defaultManifestJson = {
87
101
  name: 'WebSpatialTest',
88
102
  display: 'minimal-ui',
89
- start_url: '/index.html',
103
+ start_url: '/',
90
104
  scope: '/',
91
105
  };
92
106
  PWAGenerator.useDefaultManifestJson = false;
@@ -15,7 +15,9 @@ const utils_2 = require("../utils/utils");
15
15
  function checkManifestJson(manifestJson, isDev = false) {
16
16
  var _a;
17
17
  const errors = [];
18
- if (!manifestJson.name && !manifestJson['short_name'] && !isDev) {
18
+ if ((!manifestJson.name || manifestJson.name.length === 0) &&
19
+ !manifestJson['short_name'] &&
20
+ !isDev) {
19
21
  errors.push({
20
22
  code: 3006,
21
23
  message: 'In the Web Spatial App Manifest, it is necessary to provide the name property or short_name property (preferably both)',
@@ -63,6 +63,9 @@ class CliHistory {
63
63
  }
64
64
  // Compare whether two objects are equal
65
65
  static compareObjects(obj1, obj2) {
66
+ if (obj1 === null || obj2 === null) {
67
+ return false;
68
+ }
66
69
  // 1. Check if the number of properties is the same
67
70
  const keys1 = Object.keys(obj1);
68
71
  const keys2 = Object.keys(obj2);
@@ -18,11 +18,11 @@ class XcodeManager {
18
18
  static async upload(option, appInfo) {
19
19
  if (option['u'] && option['p']) {
20
20
  // use username, password
21
- xcrun_1.default.uploadApp((0, path_1.join)(resource_1.PROJECT_EXPORT_DIRECTORY, `${appInfo.name}.ipa`), option['u'], option['p'], true);
21
+ xcrun_1.default.uploadApp('"' + (0, path_1.join)(resource_1.PROJECT_EXPORT_DIRECTORY, `${appInfo.name}.ipa`) + '"', option['u'], option['p'], true);
22
22
  }
23
23
  else if (option['k'] && option['i']) {
24
24
  // use apiKey, apiIssuer
25
- xcrun_1.default.uploadApp((0, path_1.join)(resource_1.PROJECT_EXPORT_DIRECTORY, `${appInfo.name}.ipa`), option['k'], option['i'], false);
25
+ xcrun_1.default.uploadApp('"' + (0, path_1.join)(resource_1.PROJECT_EXPORT_DIRECTORY, `${appInfo.name}.ipa`) + '"', option['k'], option['i'], false);
26
26
  }
27
27
  }
28
28
  static async runWithSimulator() {
@@ -1 +1 @@
1
- export declare const manifestSwiftTemplate = "\nimport Foundation\n\nvar pwaManager = PWAManager()\n\nstruct PWAManager: Codable {\n var isLocal: Bool = false\n var start_url: String = \"START_URL\"\n var scope: String = \"SCOPE\"\n var id: String = \"AppID\"\n\n var name: String = \"AppName\"\n var short_name: String = \"name\"\n var description: String = \"Description\"\n\n var display: PWADisplayMode = .minimal\n var display_override: [PWADisplayMode] = []\n var protocol_handlers: [PWAProtocol] = [PWAProtocol(protocolValue: \"\", url: \"\")]\n var mainScene: WindowContainerOptions = .init(\n defaultSize: .init(\n width: SceneWidth,\n height: SceneHeight\n ),\n resizability: SceneResizability\n )\n var useMainScene: Bool = USE_MAIN_SCENE\n private var version: String = \"PACKAGE_VERSION\"\n\n mutating func _init() {\n let urlType = start_url.split(separator: \"://\").first\n if !(urlType == \"http\" || urlType == \"https\") {\n if scope == \"\" || scope == \"/\" {\n scope = \"./\"\n }\n let startUrl = Bundle.main.url(forResource: start_url, withExtension: \"\", subdirectory: \"\")\n start_url = startUrl!.absoluteString\n scope = URL(string: (scope.starts(with: \"/\") ? \".\" : \"./\") + scope, relativeTo: Bundle.main.executableURL)!.absoluteString\n isLocal = true\n }\n\n if display_override.count > 0 {\n display = display_override[0]\n }\n\n for i in 0 ... protocol_handlers.count - 1 {\n let item = protocol_handlers[i]\n protocol_handlers[i].updateUrl(scope + item.url)\n }\n }\n\n func checkInScope(url: String) -> Bool {\n return url.starts(with: scope)\n }\n\n // web+spatial://test\n func checkInDeeplink(url: String) -> String {\n var linkUrl: String = url\n for item in protocol_handlers {\n if linkUrl.starts(with: item.protocolValue) {\n let queryString: String = linkUrl.replacingOccurrences(of: item.protocolValue, with: \"\").addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!\n linkUrl = item.url.replacingOccurrences(of: \"%s\", with: item.protocolValue + queryString)\n }\n }\n logger.debug(linkUrl)\n return linkUrl\n }\n\n func getLocalResourceURL(url: String) -> String {\n let path = String(url.split(separator: \"file://\").first!.split(separator: \"?\").first!)\n let newUrl = URL(string: url)\n let fileManager = FileManager.default\n if fileManager.fileExists(atPath: newUrl!.path) {\n return url\n }\n var resource: String = Bundle.main.url(forResource: newUrl?.path, withExtension: \"\", subdirectory: \"\")?.absoluteString ?? \"\"\n if resource == \"\" {\n resource = Bundle.main.url(forResource: \"static-web\" + path, withExtension: \"\", subdirectory: \"\")?.absoluteString ?? \"\"\n }\n if resource == \"\" {\n return url\n }\n if newUrl?.query() != nil {\n resource += \"?\" + (newUrl?.query())!\n }\n if newUrl?.fragment() != nil {\n resource += \"#\" + (newUrl?.fragment())!\n }\n return resource\n }\n \n func getVersion() -> String {\n return version\n }\n}\n\nenum PWADisplayMode: Codable {\n case minimal\n case standalone\n case fullscreen\n}\n\nstruct PWAProtocol: Codable {\n var protocolValue: String = \"\"\n var url: String = \"\"\n\n mutating func updateUrl(_ str: String) {\n url = str\n }\n}\n\n";
1
+ export declare const manifestSwiftTemplate = "\nimport Foundation\n\nvar pwaManager = PWAManager()\n\nstruct PWAManager: Codable {\n var isLocal: Bool = false\n var start_url: String = \"START_URL\"\n var scope: String = \"SCOPE\"\n var id: String = \"AppID\"\n\n var name: String = \"AppName\"\n var short_name: String = \"name\"\n var description: String = \"Description\"\n\n var display: PWADisplayMode = .minimal\n var display_override: [PWADisplayMode] = []\n var protocol_handlers: [PWAProtocol] = [PWAProtocol(protocolValue: \"\", url: \"\")]\n var mainScene: WindowContainerOptions = .init(\n defaultSize: .init(\n width: SceneWidth,\n height: SceneHeight\n ),\n resizability: SceneResizability\n )\n private var version: String = \"PACKAGE_VERSION\"\n\n mutating func _init() {\n let urlType = start_url.split(separator: \"://\").first\n if !(urlType == \"http\" || urlType == \"https\") {\n if scope == \"\" || scope == \"/\" {\n scope = \"./\"\n }\n let startUrl = Bundle.main.url(forResource: start_url, withExtension: \"\", subdirectory: \"\")\n start_url = startUrl!.absoluteString\n scope = URL(string: (scope.starts(with: \"/\") ? \".\" : \"./\") + scope, relativeTo: Bundle.main.executableURL)!.absoluteString\n isLocal = true\n }\n\n if display_override.count > 0 {\n display = display_override[0]\n }\n\n for i in 0 ... protocol_handlers.count - 1 {\n let item = protocol_handlers[i]\n protocol_handlers[i].updateUrl(scope + item.url)\n }\n }\n\n func checkInScope(url: String) -> Bool {\n return url.starts(with: scope)\n }\n\n // web+spatial://test\n func checkInDeeplink(url: String) -> String {\n var linkUrl: String = url\n for item in protocol_handlers {\n if linkUrl.starts(with: item.protocolValue) {\n let queryString: String = linkUrl.replacingOccurrences(of: item.protocolValue, with: \"\").addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!\n linkUrl = item.url.replacingOccurrences(of: \"%s\", with: item.protocolValue + queryString)\n }\n }\n logger.debug(linkUrl)\n return linkUrl\n }\n\n func getLocalResourceURL(url: String) -> String {\n let path = String(url.split(separator: \"file://\").first!.split(separator: \"?\").first!)\n let newUrl = URL(string: url)\n let fileManager = FileManager.default\n if fileManager.fileExists(atPath: newUrl!.path) {\n return url\n }\n var resource: String = Bundle.main.url(forResource: newUrl?.path, withExtension: \"\", subdirectory: \"\")?.absoluteString ?? \"\"\n if resource == \"\" {\n resource = Bundle.main.url(forResource: \"static-web\" + path, withExtension: \"\", subdirectory: \"\")?.absoluteString ?? \"\"\n }\n if resource == \"\" {\n return url\n }\n if newUrl?.query() != nil {\n resource += \"?\" + (newUrl?.query())!\n }\n if newUrl?.fragment() != nil {\n resource += \"#\" + (newUrl?.fragment())!\n }\n return resource\n }\n \n func getVersion() -> String {\n return version\n }\n}\n\nenum PWADisplayMode: Codable {\n case minimal\n case standalone\n case fullscreen\n}\n\nstruct PWAProtocol: Codable {\n var protocolValue: String = \"\"\n var url: String = \"\"\n\n mutating func updateUrl(_ str: String) {\n url = str\n }\n}\n\n";
@@ -26,7 +26,6 @@ struct PWAManager: Codable {
26
26
  ),
27
27
  resizability: SceneResizability
28
28
  )
29
- var useMainScene: Bool = USE_MAIN_SCENE
30
29
  private var version: String = "PACKAGE_VERSION"
31
30
 
32
31
  mutating func _init() {
@@ -231,20 +231,21 @@ class XcodeProject {
231
231
  }
232
232
  manifestSwift = manifestSwift.replace('PWAProtocol(protocolValue: "", url: "")', deeplinkString);
233
233
  }
234
- if (typeof manifest.mainScene === 'object') {
235
- manifestSwift = manifestSwift.replace('SceneWidth', manifest.mainScene.defaultSize.width);
236
- manifestSwift = manifestSwift.replace('SceneHeight', manifest.mainScene.defaultSize.height);
237
- manifestSwift = manifestSwift.replace('SceneResizability', `"${manifest.mainScene.resizability}"`);
238
- manifestSwift = manifestSwift.replace('USE_MAIN_SCENE', 'true');
239
- }
240
- else {
241
- // string or other type
242
- // set these to bypass lint
243
- manifestSwift = manifestSwift.replace('SceneWidth', '1280');
244
- manifestSwift = manifestSwift.replace('SceneHeight', '1280');
245
- manifestSwift = manifestSwift.replace('SceneResizability', `"automatic"`);
246
- manifestSwift = manifestSwift.replace('USE_MAIN_SCENE', 'false');
234
+ manifestSwift = manifestSwift.replace('SceneWidth', manifest.xr_main_scene.defaultSize.width);
235
+ manifestSwift = manifestSwift.replace('SceneHeight', manifest.xr_main_scene.defaultSize.height);
236
+ let res = 'nil';
237
+ const resizabilities = ['minWidth', 'minHeight', 'maxWidth', 'maxHeight'];
238
+ if (manifest.xr_main_scene.resizability) {
239
+ res = 'ResizeRange(';
240
+ for (var i = 0; i < resizabilities.length; i++) {
241
+ if (manifest.xr_main_scene.resizability[resizabilities[i]] >= 0) {
242
+ res += `${resizabilities[i]}: ${manifest.xr_main_scene.resizability[resizabilities[i]]},`;
243
+ }
244
+ }
245
+ res = res.substring(0, res.length - 1);
246
+ res += ')';
247
247
  }
248
+ manifestSwift = manifestSwift.replace('SceneResizability', res);
248
249
  fs.writeFileSync(manifestSwiftPath, manifestSwift, 'utf-8');
249
250
  }
250
251
  }
@@ -30,6 +30,7 @@ export default class Xcrun {
30
30
  static shutdownSimulator(): Promise<void>;
31
31
  private static launchSimulator;
32
32
  private static buildTestApp;
33
+ private static terminateApp;
33
34
  private static installApp;
34
35
  private static launchApp;
35
36
  private static parseDestinationDevices;
@@ -110,6 +110,10 @@ class Xcrun {
110
110
  console.log(`use simulator: ${device.deviceId}`);
111
111
  // launch visionOS simulator
112
112
  this.launchSimulator(device);
113
+ try {
114
+ this.terminateApp(device.deviceId, appInfo.id);
115
+ }
116
+ catch (_a) { }
113
117
  // install app
114
118
  console.log('installing app');
115
119
  this.installApp(resource_1.PROJECT_TEST_DIRECTORY, device.deviceId, appInfo.name);
@@ -169,6 +173,9 @@ class Xcrun {
169
173
  console.log('------------------- build end -------------------');
170
174
  return true;
171
175
  }
176
+ static terminateApp(deviceId, appId) {
177
+ (0, child_process_1.execSync)(new XcrunCMD().simctl().terminate(deviceId, appId).line);
178
+ }
172
179
  static installApp(path, deviceId, appName) {
173
180
  const appFile = (0, path_1.join)(path, `Build/Products/Debug-xrsimulator/${appName}.app`);
174
181
  let cmd = new XcrunCMD().simctl();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webspatial/builder",
3
- "version": "0.1.23",
3
+ "version": "1.0.1",
4
4
  "description": "Client CLI tool to Generate XRApp project for Apple Vision Pro",
5
5
  "type": "commonjs",
6
6
  "engines": {
@@ -40,7 +40,7 @@
40
40
  "sharp": "^0.33.5",
41
41
  "valid-url": "^1.0.9",
42
42
  "xcode": "^3.0.1",
43
- "@webspatial/platform-visionos": "^0.1.23"
43
+ "@webspatial/platform-visionos": "^1.0.1"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@rollup/plugin-terser": "^0.4.3",