@webspatial/builder 0.1.21 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ const version_1 = require("./lib/cmds/version");
8
8
  const fetch_1 = require("./lib/utils/fetch");
9
9
  const launch_1 = require("./lib/cmds/launch");
10
10
  const shutdown_1 = require("./lib/cmds/shutdown");
11
+ const test_1 = require("./lib/cmds/test");
11
12
  module.exports = async () => {
12
13
  if ((0, semver_1.major)(process.versions.node) < 14) {
13
14
  throw new Error(`Current Node.js version is ${process.versions.node}.` +
@@ -96,4 +97,8 @@ async function setupCommands(program) {
96
97
  console.log(options);
97
98
  await (0, shutdown_1.shutdown)(options);
98
99
  });
100
+ program.command('test').action(async (options) => {
101
+ console.log(options);
102
+ (0, test_1.test)();
103
+ });
99
104
  }
@@ -12,7 +12,7 @@ const history_1 = require("../utils/history");
12
12
  async function build(args) {
13
13
  var _a;
14
14
  console.log('------------------- parse start -------------------');
15
- resource_1.ResourceManager.checkPlatformPath(args['platform']);
15
+ resource_1.ResourceManager.initPlatform(args['platform']);
16
16
  const manifestInfo = await doPwa(args);
17
17
  const icon = await doReadyProject((_a = args['project']) !== null && _a !== void 0 ? _a : 'dist', manifestInfo);
18
18
  await doXcode(args, icon, manifestInfo);
@@ -22,7 +22,7 @@ async function build(args) {
22
22
  }
23
23
  // build and upload ipa to App Store Connect
24
24
  async function store(args) {
25
- resource_1.ResourceManager.checkPlatformPath(args['platform']);
25
+ resource_1.ResourceManager.initPlatform(args['platform']);
26
26
  (0, check_1.checkStoreParams)(args);
27
27
  /*
28
28
  There are two ways to upload ipa to App Store Connect:
@@ -45,8 +45,8 @@ async function run(args) {
45
45
  var _a;
46
46
  const runCmd = JSON.stringify(args);
47
47
  history_1.default.init(runCmd);
48
+ resource_1.ResourceManager.setupTempPath(args['platform']);
48
49
  console.log('------------------- parse start -------------------');
49
- resource_1.ResourceManager.checkPlatformPath(args['platform']);
50
50
  const manifestInfo = await doPwa(args, true);
51
51
  history_1.default.recordManifest(manifestInfo.json);
52
52
  /*
@@ -64,6 +64,7 @@ async function run(args) {
64
64
  return;
65
65
  }
66
66
  }
67
+ resource_1.ResourceManager.pullPlatformModule(args['platform']);
67
68
  const icon = await doReadyProject((_a = args['project']) !== null && _a !== void 0 ? _a : 'dist', manifestInfo);
68
69
  await doXcode(args, icon, manifestInfo, true);
69
70
  console.log('------------------- parse end -------------------');
@@ -0,0 +1 @@
1
+ export declare function test(): void;
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.test = test;
4
+ const path_1 = require("path");
5
+ function configStartUrl(manifestStartUrl, base, manifestUrl, isNet) {
6
+ let start_url = manifestStartUrl !== null && manifestStartUrl !== void 0 ? manifestStartUrl : '/index.html';
7
+ if (!start_url.match(/\.html(\?|$)/)) {
8
+ const [path, query] = start_url.split('?');
9
+ start_url = path.endsWith('/') ? `${path}index.html` : `${path}/index.html`;
10
+ if (query)
11
+ start_url += `?${query}`;
12
+ }
13
+ const isStartUrl = validateURL(start_url);
14
+ const hasBase = base.length > 0;
15
+ if (hasBase) {
16
+ const isBaseUrl = validateURL(base);
17
+ if (!isStartUrl && !isBaseUrl) {
18
+ const staticWebRoot = (0, path_1.resolve)('./static-web');
19
+ let resolvedPath = (0, path_1.join)(base, start_url);
20
+ const normalizedPath = (0, path_1.normalize)(resolvedPath);
21
+ const safePath = (0, path_1.join)(staticWebRoot, normalizedPath);
22
+ start_url = (0, path_1.relative)(process.cwd(), safePath)
23
+ .replace(/^(\.\.\/)+/, './')
24
+ .replace(/\/$/, '');
25
+ }
26
+ else if (isStartUrl && !isBaseUrl) {
27
+ const startUrl = new URL(start_url);
28
+ const fullPath = (0, path_1.join)(base, startUrl.pathname) + startUrl.search + startUrl.hash;
29
+ let newBase = new URL('/', startUrl.origin);
30
+ start_url = new URL(fullPath, newBase).href;
31
+ }
32
+ else if (!isStartUrl && isBaseUrl) {
33
+ if (start_url.startsWith('/')) {
34
+ const baseUrl = new URL(base);
35
+ start_url = baseUrl.origin + (0, path_1.join)(baseUrl.pathname, start_url);
36
+ }
37
+ else {
38
+ start_url = new URL(start_url, base).href;
39
+ }
40
+ }
41
+ else if (isStartUrl && isBaseUrl) {
42
+ const startUrl = new URL(start_url);
43
+ const baseUrl = new URL(base);
44
+ const startFullPath = startUrl.pathname + startUrl.search + startUrl.hash;
45
+ start_url = new URL(startFullPath, baseUrl.origin + baseUrl.pathname).href;
46
+ }
47
+ }
48
+ else {
49
+ if (isNet) {
50
+ const murl = new URL(manifestUrl);
51
+ if (!isStartUrl) {
52
+ const newStartUrl = new URL(start_url, murl.origin);
53
+ start_url = newStartUrl.href;
54
+ }
55
+ else {
56
+ const startUrl = new URL(start_url);
57
+ start_url =
58
+ murl.origin + startUrl.pathname + startUrl.search + startUrl.hash;
59
+ }
60
+ }
61
+ else if (!isStartUrl) {
62
+ const staticWebRoot = (0, path_1.resolve)('./static-web');
63
+ const resolvedPath = (0, path_1.resolve)(staticWebRoot, start_url);
64
+ const normalizedPath = (0, path_1.normalize)(resolvedPath);
65
+ const safePath = (0, path_1.join)(staticWebRoot, normalizedPath);
66
+ start_url = (0, path_1.relative)(process.cwd(), safePath)
67
+ .replace(/^(\.\.\/)+/, './')
68
+ .replace(/\/$/, '');
69
+ }
70
+ }
71
+ return start_url;
72
+ }
73
+ function configScope(start_url, scope) {
74
+ const isStartUrl = validateURL(start_url);
75
+ const isUrl = validateURL(scope);
76
+ if (isStartUrl && isUrl) {
77
+ const scopeURL = new URL(scope);
78
+ const startURL = new URL(start_url);
79
+ if (scopeURL.host !== startURL.host || start_url.indexOf(scope) !== 0) {
80
+ scope = parseRouter(start_url);
81
+ }
82
+ }
83
+ else if (isStartUrl && !isUrl) {
84
+ scope = new URL(scope, start_url).href;
85
+ }
86
+ else if (!isStartUrl && isUrl) {
87
+ const cleanPath = start_url.replace(/\/[^\/]+$/, '');
88
+ scope = (0, path_1.normalize)(cleanPath + '/');
89
+ }
90
+ // else {
91
+ // scope = join(parseRouter(start_url), scope)
92
+ // }
93
+ // scope = scope
94
+ return scope;
95
+ }
96
+ function validateURL(url) {
97
+ try {
98
+ new URL(url);
99
+ return true;
100
+ }
101
+ catch (error) {
102
+ return false;
103
+ }
104
+ }
105
+ function parseRouter(url) {
106
+ let urlParts = url.split('/');
107
+ urlParts.pop();
108
+ let pathUrl = urlParts.join();
109
+ while (pathUrl.indexOf(',') >= 0) {
110
+ pathUrl = pathUrl.replace(',', '/');
111
+ }
112
+ return pathUrl;
113
+ }
114
+ function testStartUrl() {
115
+ console.log(configStartUrl('/', '', '/manifest.json', false));
116
+ console.log(configStartUrl('http://www.baidu.com', '', 'http://www.baidu.com/manifest.json', true));
117
+ console.log(configStartUrl('/', '/', '/manifest.json', false));
118
+ console.log(configStartUrl('/a.html?a=1', '/', '/manifest.json', false));
119
+ console.log(configStartUrl('http://www.baidu.com/test/a.html?a=1', '/xx', '/manifest.json', false));
120
+ console.log(configStartUrl('http://www.baidu.com/a.html?a=1', 'http://www.google.com/test', '/manifest.json', false));
121
+ console.log(configStartUrl('/test/index.html', '/public/aaa', '/manifest.json', false));
122
+ }
123
+ function testScope() {
124
+ console.log(configScope('/test/index.html', '/test'));
125
+ }
126
+ function test() {
127
+ // testStartUrl()
128
+ // testScope()
129
+ }
@@ -28,12 +28,6 @@ function configId(manifestJson, bundleId) {
28
28
  function configStartUrl(manifestJson, base, manifestUrl, isNet) {
29
29
  var _a;
30
30
  let start_url = (_a = manifestJson.start_url) !== null && _a !== void 0 ? _a : '/index.html';
31
- if (!start_url.match(/\.html(\?|$)/)) {
32
- const [path, query] = start_url.split('?');
33
- start_url = path.endsWith('/') ? `${path}index.html` : `${path}/index.html`;
34
- if (query)
35
- start_url += `?${query}`;
36
- }
37
31
  const isStartUrl = (0, validate_1.validateURL)(start_url);
38
32
  const hasBase = base.length > 0;
39
33
  if (hasBase) {
@@ -92,6 +86,13 @@ function configStartUrl(manifestJson, base, manifestUrl, isNet) {
92
86
  .replace(/\/$/, '');
93
87
  }
94
88
  }
89
+ if (!start_url.match(/\.html(\?|$)/) &&
90
+ !(start_url.startsWith('http://') || start_url.startsWith('https://'))) {
91
+ const [path, query] = start_url.split('?');
92
+ start_url = path.endsWith('/') ? `${path}index.html` : `${path}/index.html`;
93
+ if (query)
94
+ start_url += `?${query}`;
95
+ }
95
96
  return start_url;
96
97
  }
97
98
  function configScope(manifestJson) {
@@ -44,46 +44,18 @@ function checkManifestJson(manifestJson, isDev = false) {
44
44
  }
45
45
  }
46
46
  function checkStartUrl(startUrl, manifestUrl, isNet, isDev = false) {
47
- var isNetWeb = false;
48
47
  if (isDev) {
49
48
  return startUrl.startsWith('https://') || startUrl.startsWith('http://');
50
49
  }
51
- if (isNet) {
52
- // Determine whether it is of the same origin as the manifest
53
- if (startUrl.startsWith('https://')) {
54
- const urlStart = new URL(startUrl);
55
- const urlManifest = new URL(manifestUrl);
56
- // The start_url and manifest need to be of the same origin
57
- if (urlStart.host !== urlManifest.host) {
58
- throw new CustomError_1.CustomError({
59
- code: 4000,
60
- // eslint-disable-next-line @typescript-eslint/camelcase
61
- message: 'In the WebSpatial App Manifest, the start_url must be the same origin with manifest',
62
- message_staring_params: {},
63
- });
64
- }
65
- }
66
- // Start_url must be HTTPS protocol
67
- else if (startUrl.startsWith('http://')) {
68
- throw new CustomError_1.CustomError({
69
- code: 4000,
70
- // eslint-disable-next-line @typescript-eslint/camelcase
71
- message: 'In the Web Spatial App Manifest, the start_url must use https',
72
- message_staring_params: {},
73
- });
74
- }
75
- }
76
- else {
77
- if (startUrl.startsWith('https://') || startUrl.startsWith('http://')) {
78
- throw new CustomError_1.CustomError({
79
- code: 4000,
80
- // eslint-disable-next-line @typescript-eslint/camelcase
81
- message: 'Local manifest cannot package network project',
82
- message_staring_params: {},
83
- });
84
- }
50
+ if (startUrl.startsWith('http://')) {
51
+ throw new CustomError_1.CustomError({
52
+ code: 4000,
53
+ // eslint-disable-next-line @typescript-eslint/camelcase
54
+ message: 'In the Web Spatial App Manifest, the start_url must use https',
55
+ message_staring_params: {},
56
+ });
85
57
  }
86
- return isNetWeb;
58
+ return startUrl.startsWith('https://');
87
59
  }
88
60
  async function checkIcons(manifest, manifestUrl, isDev = false) {
89
61
  var _a, _b;
@@ -12,11 +12,13 @@ export declare const LOGO_DIRECTORY: string;
12
12
  export declare class ResourceManager {
13
13
  static moveProjectFrom(dir: string): Promise<void>;
14
14
  static generateIcon(info: ManifestInfo): Promise<Jimp>;
15
+ static initPlatform(platform: string): void;
16
+ static setupTempPath(platform: string): void;
15
17
  /**
16
18
  * @description Check and set the platform path to ensure the existence of the specified platform module.
17
19
  * If the module does not exist, it will be installed automatically.
18
20
  * Also set the project directory, build directory, and export directory.
19
21
  * @param platform The name of the platform to check, defaulting to 'visionos'
20
22
  */
21
- static checkPlatformPath(platform: string): void;
23
+ static pullPlatformModule(platform: string): void;
22
24
  }
@@ -47,13 +47,39 @@ class ResourceManager {
47
47
  icon.resize(1024, 1024);
48
48
  return icon;
49
49
  }
50
+ static initPlatform(platform) {
51
+ this.setupTempPath(platform);
52
+ this.pullPlatformModule(platform);
53
+ }
54
+ static setupTempPath(platform) {
55
+ const usePlatform = platform !== null && platform !== void 0 ? platform : supportPlatform[0];
56
+ if (!supportPlatform.includes(usePlatform)) {
57
+ throw new Error(`not support platform ${usePlatform}, now WebSpatial only support ${supportPlatform.join(',')}`);
58
+ }
59
+ let tempDir = './node_modules/.webspatial-builder-temp';
60
+ let tempPlatformDir = (0, path_1.join)(tempDir, `platform-${usePlatform}`);
61
+ let tempProjectDir = (0, path_1.join)(tempPlatformDir, './project');
62
+ let temBuildDir = (0, path_1.join)(tempPlatformDir, './build');
63
+ let temExportDir = (0, path_1.join)(tempPlatformDir, './export');
64
+ let temTestDir = (0, path_1.join)(tempPlatformDir, './test');
65
+ if (!fs.existsSync(tempDir)) {
66
+ fs.mkdirSync(tempDir);
67
+ }
68
+ if (!fs.existsSync(tempPlatformDir)) {
69
+ fs.mkdirSync(tempPlatformDir);
70
+ }
71
+ exports.PROJECT_DIRECTORY = tempProjectDir;
72
+ exports.PROJECT_BUILD_DIRECTORY = temBuildDir;
73
+ exports.PROJECT_EXPORT_DIRECTORY = temExportDir;
74
+ exports.PROJECT_TEST_DIRECTORY = temTestDir;
75
+ }
50
76
  /**
51
77
  * @description Check and set the platform path to ensure the existence of the specified platform module.
52
78
  * If the module does not exist, it will be installed automatically.
53
79
  * Also set the project directory, build directory, and export directory.
54
80
  * @param platform The name of the platform to check, defaulting to 'visionos'
55
81
  */
56
- static checkPlatformPath(platform) {
82
+ static pullPlatformModule(platform) {
57
83
  const usePlatform = platform !== null && platform !== void 0 ? platform : supportPlatform[0];
58
84
  if (!supportPlatform.includes(usePlatform)) {
59
85
  throw new Error(`not support platform ${usePlatform}, now WebSpatial only support ${supportPlatform.join(',')}`);
@@ -68,36 +94,20 @@ class ResourceManager {
68
94
  if (!hasModule) {
69
95
  (0, child_process_1.execSync)(`cd ${(0, path_1.join)(__dirname, '../../../')} && pnpm add @webspatial/platform-${usePlatform}`);
70
96
  }
71
- let tempDir = './node_modules/.webspatial-builder-temp';
72
- let tempPlatformDir = (0, path_1.join)(tempDir, `platform-${usePlatform}`);
73
- let tempProjectDir = (0, path_1.join)(tempPlatformDir, './project');
74
- let temBuildDir = (0, path_1.join)(tempPlatformDir, './build');
75
- let temExportDir = (0, path_1.join)(tempPlatformDir, './export');
76
- let temTestDir = (0, path_1.join)(tempPlatformDir, './test');
77
- if (!fs.existsSync(tempDir)) {
78
- fs.mkdirSync(tempDir);
79
- }
80
- if (!fs.existsSync(tempPlatformDir)) {
81
- fs.mkdirSync(tempPlatformDir);
82
- }
83
- if (fs.existsSync(tempProjectDir)) {
84
- (0, child_process_1.execSync)(`rm -rf ${tempProjectDir}`);
97
+ if (fs.existsSync(exports.PROJECT_DIRECTORY)) {
98
+ (0, child_process_1.execSync)(`rm -rf ${exports.PROJECT_DIRECTORY}`);
85
99
  }
86
- if (!fs.existsSync(temBuildDir)) {
87
- fs.mkdirSync(temBuildDir);
100
+ if (!fs.existsSync(exports.PROJECT_BUILD_DIRECTORY)) {
101
+ fs.mkdirSync(exports.PROJECT_BUILD_DIRECTORY);
88
102
  }
89
- if (!fs.existsSync(temExportDir)) {
90
- fs.mkdirSync(temExportDir);
103
+ if (!fs.existsSync(exports.PROJECT_EXPORT_DIRECTORY)) {
104
+ fs.mkdirSync(exports.PROJECT_EXPORT_DIRECTORY);
91
105
  }
92
- if (!fs.existsSync(temTestDir)) {
93
- fs.mkdirSync(temTestDir);
106
+ if (!fs.existsSync(exports.PROJECT_TEST_DIRECTORY)) {
107
+ fs.mkdirSync(exports.PROJECT_TEST_DIRECTORY);
94
108
  }
95
- fs.mkdirSync(tempProjectDir);
96
- (0, file_1.copyDir)(modulePath, tempProjectDir);
97
- exports.PROJECT_DIRECTORY = tempProjectDir;
98
- exports.PROJECT_BUILD_DIRECTORY = temBuildDir;
99
- exports.PROJECT_EXPORT_DIRECTORY = temExportDir;
100
- exports.PROJECT_TEST_DIRECTORY = temTestDir;
109
+ fs.mkdirSync(exports.PROJECT_DIRECTORY);
110
+ (0, file_1.copyDir)(modulePath, exports.PROJECT_DIRECTORY);
101
111
  }
102
112
  }
103
113
  exports.ResourceManager = ResourceManager;
@@ -193,7 +193,7 @@ class XcodeProject {
193
193
  var _a;
194
194
  xcodeProject.updateProductName(manifest.name);
195
195
  // set PRODUCT_BUNDLE_IDENTIFIER need ""
196
- if (manifest.id && !isDev) {
196
+ if (manifest.id) {
197
197
  xcodeProject.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', `"${manifest.id}"`);
198
198
  }
199
199
  this.updateDeeplink((_a = manifest.protocol_handlers) !== null && _a !== void 0 ? _a : []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webspatial/builder",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
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.21"
43
+ "@webspatial/platform-visionos": "^0.1.22"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@rollup/plugin-terser": "^0.4.3",
@@ -65,6 +65,7 @@
65
65
  },
66
66
  "scripts": {
67
67
  "start": "tsc -w",
68
+ "test": "npm run build && bin/bundlepwa.js test",
68
69
  "test1": "npm run build && bin/bundlepwa.js build --manifest=../testLocal/manifest.json --project=../testLocal --export=./export --version=1.0 --teamId=teamId",
69
70
  "test2": "npm run build && bin/bundlepwa.js publish --manifest=../pack-test/pwa_test.json --project=../pack-test --version=1.0 --teamId=teamId --u=username --p=password",
70
71
  "test3": "npm run build && bin/bundlepwa.js publish --name=webspatial --version=1.0 --u=username --p=password",