@webspatial/builder 0.1.15 → 0.1.17
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 +15 -75
- package/dist/index.js +99 -1
- package/dist/lib/cmds/build.js +116 -1
- package/dist/lib/cmds/check.js +41 -1
- package/dist/lib/cmds/help.js +66 -1
- package/dist/lib/cmds/launch.js +14 -1
- package/dist/lib/cmds/shutdown.js +8 -1
- package/dist/lib/cmds/version.js +11 -1
- package/dist/lib/pwa/config.js +208 -1
- package/dist/lib/pwa/index.js +92 -1
- package/dist/lib/pwa/validate.js +240 -1
- package/dist/lib/resource/file.js +45 -1
- package/dist/lib/resource/imageHelper.js +37 -1
- package/dist/lib/resource/index.js +102 -1
- package/dist/lib/resource/load.js +121 -1
- package/dist/lib/types.d.ts +2 -2
- package/dist/lib/types.js +2 -1
- package/dist/lib/utils/CustomError.js +11 -1
- package/dist/lib/utils/FetchUtils-1.js +25 -1
- package/dist/lib/utils/Log.js +98 -1
- package/dist/lib/utils/fetch.js +56 -1
- package/dist/lib/utils/history.d.ts +1 -0
- package/dist/lib/utils/history.js +116 -1
- package/dist/lib/utils/messages.js +102 -1
- package/dist/lib/utils/utils.js +15 -1
- package/dist/lib/xcode/index.js +35 -1
- package/dist/lib/xcode/manifestSwiftTemplate.js +109 -1
- package/dist/lib/xcode/xcodebuild.js +119 -1
- package/dist/lib/xcode/xcodeproject.js +239 -1
- package/dist/lib/xcode/xcrun.d.ts +1 -1
- package/dist/lib/xcode/xcrun.js +433 -1
- package/package.json +3 -3
|
@@ -1 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImageHelper = void 0;
|
|
4
|
+
const Jimp = require("jimp");
|
|
5
|
+
const sharp = require("sharp");
|
|
6
|
+
const resvg_js_1 = require("@resvg/resvg-js");
|
|
7
|
+
class ImageHelper {
|
|
8
|
+
static createImg(size) {
|
|
9
|
+
return new Jimp(size, size, 0x00000000);
|
|
10
|
+
}
|
|
11
|
+
static async webp2PngBuffer(buffer) {
|
|
12
|
+
return await sharp(buffer).toFormat('png').toBuffer();
|
|
13
|
+
}
|
|
14
|
+
static async svg2img(svg) {
|
|
15
|
+
const opt = {
|
|
16
|
+
fitTo: {
|
|
17
|
+
mode: 'width',
|
|
18
|
+
value: 1024, // Generate the SVG with 1024px width, for larger icons.
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const resvg = new resvg_js_1.Resvg(svg, opt);
|
|
22
|
+
const pngData = resvg.render();
|
|
23
|
+
const pngBuffer = pngData.asPng();
|
|
24
|
+
return pngBuffer;
|
|
25
|
+
}
|
|
26
|
+
static isFullyOpaque(image) {
|
|
27
|
+
const pixelNum = image.getWidth() * image.getHeight();
|
|
28
|
+
for (var i = 0; i < pixelNum; i++) {
|
|
29
|
+
const idx = i * 4 + 3;
|
|
30
|
+
if (image.bitmap.data[idx] < 255) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.ImageHelper = ImageHelper;
|
|
@@ -1 +1,102 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResourceManager = exports.MIDDLE_APPICON_DIRECTORY = exports.BACK_APPICON_DIRECTORY = exports.ASSET_DIRECTORY = exports.WEB_PROJECT_DIRECTORY = exports.PROJECT_TEST_DIRECTORY = exports.PROJECT_EXPORT_DIRECTORY = exports.PROJECT_BUILD_DIRECTORY = exports.PROJECT_DIRECTORY = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const file_1 = require("./file");
|
|
7
|
+
const load_1 = require("./load");
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
exports.PROJECT_DIRECTORY = '';
|
|
10
|
+
exports.PROJECT_BUILD_DIRECTORY = '';
|
|
11
|
+
exports.PROJECT_EXPORT_DIRECTORY = '';
|
|
12
|
+
exports.PROJECT_TEST_DIRECTORY = '';
|
|
13
|
+
exports.WEB_PROJECT_DIRECTORY = 'web-spatial/static-web';
|
|
14
|
+
exports.ASSET_DIRECTORY = 'web-spatial/Assets.xcassets';
|
|
15
|
+
exports.BACK_APPICON_DIRECTORY = exports.ASSET_DIRECTORY +
|
|
16
|
+
'/AppIcon.solidimagestack/Back.solidimagestacklayer/Content.imageset';
|
|
17
|
+
exports.MIDDLE_APPICON_DIRECTORY = exports.ASSET_DIRECTORY +
|
|
18
|
+
'/AppIcon.solidimagestack/Middle.solidimagestacklayer/Content.imageset';
|
|
19
|
+
const supportPlatform = ['visionos'];
|
|
20
|
+
class ResourceManager {
|
|
21
|
+
static async moveProjectFrom(dir) {
|
|
22
|
+
// Copy the web project to the static-web directory under the xcode project
|
|
23
|
+
const fromDirectory = (0, path_1.join)(process.cwd(), dir);
|
|
24
|
+
const targetDirctory = (0, path_1.join)(exports.PROJECT_DIRECTORY, exports.WEB_PROJECT_DIRECTORY);
|
|
25
|
+
// Ensure `targetDirectory` exists.
|
|
26
|
+
if (!fs.existsSync(targetDirctory)) {
|
|
27
|
+
fs.mkdirSync(targetDirctory, { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// If a directory already exists, clear it first
|
|
31
|
+
(0, file_1.clearDir)(targetDirctory);
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
(0, file_1.copyDir)(fromDirectory, targetDirctory);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
console.log(err);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
static async generateIcon(info) {
|
|
41
|
+
const manifestJson = info.json;
|
|
42
|
+
const imgUrl = manifestJson.icons[0].src;
|
|
43
|
+
const icon = !imgUrl.startsWith('http')
|
|
44
|
+
? await (0, load_1.loadImageFromDisk)(imgUrl)
|
|
45
|
+
: await (0, load_1.loadImageFromNet)(imgUrl);
|
|
46
|
+
icon.resize(1024, 1024);
|
|
47
|
+
return icon;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @description Check and set the platform path to ensure the existence of the specified platform module.
|
|
51
|
+
* If the module does not exist, it will be installed automatically.
|
|
52
|
+
* Also set the project directory, build directory, and export directory.
|
|
53
|
+
* @param platform The name of the platform to check, defaulting to 'visionos'
|
|
54
|
+
*/
|
|
55
|
+
static checkPlatformPath(platform) {
|
|
56
|
+
const usePlatform = platform !== null && platform !== void 0 ? platform : supportPlatform[0];
|
|
57
|
+
if (!supportPlatform.includes(usePlatform)) {
|
|
58
|
+
throw new Error(`not support platform ${usePlatform}, now WebSpatial only support ${supportPlatform.join(',')}`);
|
|
59
|
+
}
|
|
60
|
+
let modulePath = (0, path_1.join)(process.cwd(), `node_modules/@webspatial/platform-${usePlatform}`);
|
|
61
|
+
// If the module does not exist in the current working directory, try to get it from the cli directory
|
|
62
|
+
if (!fs.existsSync(modulePath)) {
|
|
63
|
+
modulePath = (0, path_1.join)(__dirname, `../../../node_modules/@webspatial/platform-${usePlatform}`);
|
|
64
|
+
}
|
|
65
|
+
const hasModule = fs.existsSync(modulePath);
|
|
66
|
+
// If the module does not exist, execute the npm installation command
|
|
67
|
+
if (!hasModule) {
|
|
68
|
+
(0, child_process_1.execSync)(`cd ${(0, path_1.join)(__dirname, '../../../')} && pnpm add @webspatial/platform-${usePlatform}`);
|
|
69
|
+
}
|
|
70
|
+
let tempDir = (0, path_1.join)(__dirname, `../../temp`);
|
|
71
|
+
let tempPlatformDir = (0, path_1.join)(tempDir, `platform-${usePlatform}`);
|
|
72
|
+
let tempProjectDir = (0, path_1.join)(tempPlatformDir, './project');
|
|
73
|
+
let temBuildDir = (0, path_1.join)(tempPlatformDir, './build');
|
|
74
|
+
let temExportDir = (0, path_1.join)(tempPlatformDir, './export');
|
|
75
|
+
let temTestDir = (0, path_1.join)(tempPlatformDir, './test');
|
|
76
|
+
if (!fs.existsSync(tempDir)) {
|
|
77
|
+
fs.mkdirSync(tempDir);
|
|
78
|
+
}
|
|
79
|
+
if (!fs.existsSync(tempPlatformDir)) {
|
|
80
|
+
fs.mkdirSync(tempPlatformDir);
|
|
81
|
+
}
|
|
82
|
+
if (fs.existsSync(tempProjectDir)) {
|
|
83
|
+
(0, child_process_1.execSync)(`rm -rf ${tempProjectDir}`);
|
|
84
|
+
}
|
|
85
|
+
if (!fs.existsSync(temBuildDir)) {
|
|
86
|
+
fs.mkdirSync(temBuildDir);
|
|
87
|
+
}
|
|
88
|
+
if (!fs.existsSync(temExportDir)) {
|
|
89
|
+
fs.mkdirSync(temExportDir);
|
|
90
|
+
}
|
|
91
|
+
if (!fs.existsSync(temTestDir)) {
|
|
92
|
+
fs.mkdirSync(temTestDir);
|
|
93
|
+
}
|
|
94
|
+
fs.mkdirSync(tempProjectDir);
|
|
95
|
+
(0, file_1.copyDir)(modulePath, tempProjectDir);
|
|
96
|
+
exports.PROJECT_DIRECTORY = tempProjectDir;
|
|
97
|
+
exports.PROJECT_BUILD_DIRECTORY = temBuildDir;
|
|
98
|
+
exports.PROJECT_EXPORT_DIRECTORY = temExportDir;
|
|
99
|
+
exports.PROJECT_TEST_DIRECTORY = temTestDir;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.ResourceManager = ResourceManager;
|
|
@@ -1 +1,121 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadJsonFromNet = loadJsonFromNet;
|
|
4
|
+
exports.loadJsonFromDisk = loadJsonFromDisk;
|
|
5
|
+
exports.loadImageFromNet = loadImageFromNet;
|
|
6
|
+
exports.loadImageFromDisk = loadImageFromDisk;
|
|
7
|
+
exports.loadFileString = loadFileString;
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const FetchUtils_1_1 = require("../utils/FetchUtils-1");
|
|
10
|
+
const CustomError_1 = require("../utils/CustomError");
|
|
11
|
+
const Jimp = require("jimp");
|
|
12
|
+
const imageHelper_1 = require("./imageHelper");
|
|
13
|
+
async function loadJsonFromNet(url) {
|
|
14
|
+
const response = await FetchUtils_1_1.fetchUtils.fetch(url, { encoding: 'binary' });
|
|
15
|
+
if (response.status !== 200) {
|
|
16
|
+
throw new CustomError_1.CustomError({
|
|
17
|
+
code: 3004,
|
|
18
|
+
message: `Failed to download Web Manifest ${url}.` +
|
|
19
|
+
`The response status is ${response.status}, please check the Web Manifest access address`,
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
21
|
+
message_staring_params: {
|
|
22
|
+
web_manifest_url: url,
|
|
23
|
+
status: response.status,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
let body;
|
|
29
|
+
if (response.text) {
|
|
30
|
+
body = await response.text();
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
if (['gzip', 'deflate', 'br'].includes(response.headers['content-encoding'])) {
|
|
34
|
+
body = FetchUtils_1_1.fetchUtils
|
|
35
|
+
.decompressResponseBuffer(Buffer.from(response.data, 'binary'), response.headers['content-encoding'])
|
|
36
|
+
.toString();
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
body = Buffer.from(response.data, 'binary').toString();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return JSON.parse(body.trim());
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
throw new CustomError_1.CustomError({
|
|
46
|
+
code: 3005,
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
48
|
+
message: 'Manifest file embedded in the website is not a legal JSON file, please reconfigure',
|
|
49
|
+
message_staring_params: {},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function loadJsonFromDisk(url) {
|
|
54
|
+
const jsonString = await loadFileString(url.toString());
|
|
55
|
+
return JSON.parse(jsonString);
|
|
56
|
+
}
|
|
57
|
+
async function loadImageFromNet(src) {
|
|
58
|
+
const response = await FetchUtils_1_1.fetchUtils.fetch(src, { encoding: 'binary' });
|
|
59
|
+
if (response.status !== 200) {
|
|
60
|
+
// throw new Error(
|
|
61
|
+
// `Failed to download icon ${iconUrl}. Responded with status ${response.status}`);
|
|
62
|
+
throw new CustomError_1.CustomError({
|
|
63
|
+
code: 2002,
|
|
64
|
+
message: `Failed to download icon. Responded with status ${response.status}`,
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
66
|
+
message_staring_params: { icon_url: src, status: response.status },
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const contentType = response.headers.get
|
|
70
|
+
? response.headers.get('content-type')
|
|
71
|
+
: response.headers['content-type'];
|
|
72
|
+
if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('image/'))) {
|
|
73
|
+
// throw new Error(`Received icon "${iconUrl}" with invalid Content-Type.` +
|
|
74
|
+
// ` Responded with Content-Type "${contentType}"`);
|
|
75
|
+
throw new CustomError_1.CustomError({
|
|
76
|
+
code: 2003,
|
|
77
|
+
message: `Received icon with invalid Content-Type.` +
|
|
78
|
+
` Responded with Content-Type "${contentType}"`,
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
80
|
+
message_staring_params: { icon_url: src, contentType },
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
let body;
|
|
84
|
+
if (response.arrayBuffer) {
|
|
85
|
+
body = await response.arrayBuffer();
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (['gzip', 'deflate', 'br'].includes(response.headers['content-encoding'])) {
|
|
89
|
+
body = FetchUtils_1_1.fetchUtils.decompressResponseBuffer(Buffer.from(response.data, 'binary'), response.headers['content-encoding']);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
body = Buffer.from(response.data, 'binary');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (contentType.startsWith('image/svg')) {
|
|
96
|
+
const textDecoder = new TextDecoder();
|
|
97
|
+
try {
|
|
98
|
+
body = await imageHelper_1.ImageHelper.svg2img(textDecoder.decode(body));
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
// throw new Error(`Problem reading ${iconUrl}: ${error}`);
|
|
102
|
+
throw new CustomError_1.CustomError({
|
|
103
|
+
code: 2004,
|
|
104
|
+
message: `Problem reading ${src}: ${error}`,
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
106
|
+
message_staring_params: { icon_url: src, error },
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (contentType.startsWith('image/webp')) {
|
|
111
|
+
body = await imageHelper_1.ImageHelper.webp2PngBuffer(body);
|
|
112
|
+
}
|
|
113
|
+
return await Jimp.read(Buffer.from(body));
|
|
114
|
+
}
|
|
115
|
+
async function loadImageFromDisk(src) {
|
|
116
|
+
return await Jimp.read(src);
|
|
117
|
+
}
|
|
118
|
+
async function loadFileString(url) {
|
|
119
|
+
let file = await fs.promises.readFile(url.toString());
|
|
120
|
+
return file.toString();
|
|
121
|
+
}
|
package/dist/lib/types.d.ts
CHANGED
package/dist/lib/types.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomError = void 0;
|
|
4
|
+
class CustomError extends Error {
|
|
5
|
+
constructor(customMessage, type) {
|
|
6
|
+
super(JSON.stringify(customMessage));
|
|
7
|
+
this.customMessage = customMessage;
|
|
8
|
+
this.type = type || 'info';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.CustomError = CustomError;
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchUtils = void 0;
|
|
4
|
+
class FetchUtils {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.fetchEngine = null;
|
|
7
|
+
this.fetch = null;
|
|
8
|
+
this.downloadFile = null;
|
|
9
|
+
this.decompressResponseBuffer = null;
|
|
10
|
+
}
|
|
11
|
+
setFetchEngine(newFetchEngine) {
|
|
12
|
+
this.fetchEngine = newFetchEngine;
|
|
13
|
+
}
|
|
14
|
+
setFetch(newFetch) {
|
|
15
|
+
this.fetch = newFetch;
|
|
16
|
+
}
|
|
17
|
+
setDownloadFile(newDownloadFile) {
|
|
18
|
+
this.downloadFile = newDownloadFile;
|
|
19
|
+
}
|
|
20
|
+
setDecompressResponseBuffer(newDecompressResponseBuffer) {
|
|
21
|
+
this.decompressResponseBuffer = newDecompressResponseBuffer;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const fetchUtils = new FetchUtils();
|
|
25
|
+
exports.fetchUtils = fetchUtils;
|
package/dist/lib/utils/Log.js
CHANGED
|
@@ -1 +1,98 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConsoleLog = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* An utility class to print nice Log messages.
|
|
6
|
+
*/
|
|
7
|
+
class ConsoleLog {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new Log instance
|
|
10
|
+
* @param tag The tag used when logging. Printed at the beggining of a log message.
|
|
11
|
+
* @param verbose If the Log is verbose. Debug messages are only printed on verbose logs.
|
|
12
|
+
* @param output Where to output the log messages.
|
|
13
|
+
*/
|
|
14
|
+
constructor(tag = '', verbose = false, output = console) {
|
|
15
|
+
this.tag = tag;
|
|
16
|
+
this.verbose = verbose;
|
|
17
|
+
this.prefix = this.inverse(tag);
|
|
18
|
+
this.output = output;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Prints a debug message to the Log. Message is ignored if the Log is not set to verbose.
|
|
22
|
+
* @param message The message the be printed.
|
|
23
|
+
* @param args Extra arguments for the console.
|
|
24
|
+
*/
|
|
25
|
+
debug(message, ...args) {
|
|
26
|
+
if (!this.verbose) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
this.log(this.output.log, this.dim(message), ...args);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Prints an info message to the Log. Message is ignored if the Log is not set to verbose.
|
|
33
|
+
* @param message The message the be printed.
|
|
34
|
+
* @param args Extra arguments for the console.
|
|
35
|
+
*/
|
|
36
|
+
info(message, ...args) {
|
|
37
|
+
this.log(this.output.log, message, ...args);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Prints an warning message to the Log. Message is ignored if the Log is not set to verbose.
|
|
41
|
+
* @param message The message the be printed.
|
|
42
|
+
* @param args Extra arguments for the console.
|
|
43
|
+
*/
|
|
44
|
+
warn(message, ...args) {
|
|
45
|
+
this.log(this.output.warn, this.yellow('WARNING ' + message), ...args);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Prints an error message to the Log. Message is ignored if the Log is not set to verbose.
|
|
49
|
+
* @param message The message the be printed.
|
|
50
|
+
* @param args Extra arguments for the console.
|
|
51
|
+
*/
|
|
52
|
+
error(message, ...args) {
|
|
53
|
+
this.output.error('\n');
|
|
54
|
+
this.log(this.output.error, this.red('ERROR ' + message), ...args);
|
|
55
|
+
this.output.error('\n');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Sets the verbose.
|
|
59
|
+
* @param verbose The verbose value to set.
|
|
60
|
+
*/
|
|
61
|
+
setVerbose(verbose) {
|
|
62
|
+
this.verbose = verbose;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new Log using the same output and verbositity of the current Log.
|
|
66
|
+
* @param newTag The tag the be used on the new Log instance.
|
|
67
|
+
*/
|
|
68
|
+
newLog(newTag) {
|
|
69
|
+
if (this.tag) {
|
|
70
|
+
newTag = this.tag + ' ' + newTag;
|
|
71
|
+
}
|
|
72
|
+
return new ConsoleLog(newTag, this.verbose, this.output);
|
|
73
|
+
}
|
|
74
|
+
log(fn, message, ...args) {
|
|
75
|
+
if (this.prefix) {
|
|
76
|
+
message = this.prefix + ' ' + message;
|
|
77
|
+
}
|
|
78
|
+
if (args) {
|
|
79
|
+
fn(...[message].concat(args));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
fn(message);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
inverse(input) {
|
|
86
|
+
return `\x1b[7m${input}\x1b[0m`;
|
|
87
|
+
}
|
|
88
|
+
dim(input) {
|
|
89
|
+
return `\x1b[36m${input}\x1b[0m`;
|
|
90
|
+
}
|
|
91
|
+
yellow(input) {
|
|
92
|
+
return `\x1b[33m${input}\x1b[0m`;
|
|
93
|
+
}
|
|
94
|
+
red(input) {
|
|
95
|
+
return `\x1b[31m${input}\x1b[0m`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.ConsoleLog = ConsoleLog;
|
package/dist/lib/utils/fetch.js
CHANGED
|
@@ -1 +1,56 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetch = fetch;
|
|
4
|
+
exports.downloadFile = downloadFile;
|
|
5
|
+
exports.decompressResponseBuffer = decompressResponseBuffer;
|
|
6
|
+
const fetch_h2_1 = require("fetch-h2");
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
const zlib = require("zlib");
|
|
9
|
+
// const userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0';
|
|
10
|
+
const userAgent = 'Mozilla/5.0 (X11; Linux x86_64; PICO 4 OS5.5.0 like Quest) AppleWebKit/537.36 (KHTML, like Gecko) PicoBrowser/3.3.24 Chrome/105.0.5195.68 VR Safari/537.36 OculusBrowser/7.0';
|
|
11
|
+
const fetchh2Ctx = (0, fetch_h2_1.context)({ userAgent: userAgent, overwriteUserAgent: true });
|
|
12
|
+
const fetchh2 = fetchh2Ctx.fetch;
|
|
13
|
+
async function fetch(input, headers) {
|
|
14
|
+
return await fetchh2(input, headers ? { redirect: 'follow', ...headers } : { redirect: 'follow' });
|
|
15
|
+
}
|
|
16
|
+
async function downloadFile(url, path, progressCallback) {
|
|
17
|
+
let result;
|
|
18
|
+
let readableStream;
|
|
19
|
+
result = await fetchh2(url, { redirect: 'follow' });
|
|
20
|
+
readableStream = await result.readable();
|
|
21
|
+
// Try to determine the file size via the `Content-Length` header. This may not be available
|
|
22
|
+
// for all cases.
|
|
23
|
+
const contentLength = result.headers.get('Content-Length');
|
|
24
|
+
const fileSize = contentLength ? parseInt(contentLength) : -1;
|
|
25
|
+
const fileStream = fs.createWriteStream(path);
|
|
26
|
+
let received = 0;
|
|
27
|
+
await new Promise((resolve, reject) => {
|
|
28
|
+
readableStream.pipe(fileStream);
|
|
29
|
+
// Even though we're piping the chunks, we intercept them to check for the download progress.
|
|
30
|
+
if (progressCallback) {
|
|
31
|
+
readableStream.on('data', chunk => {
|
|
32
|
+
received = received + chunk.length;
|
|
33
|
+
progressCallback(received, fileSize);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
readableStream.on('error', err => {
|
|
37
|
+
reject(err);
|
|
38
|
+
});
|
|
39
|
+
fileStream.on('finish', () => {
|
|
40
|
+
resolve();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function decompressResponseBuffer(buffer, contentEncoding) {
|
|
45
|
+
let result = buffer;
|
|
46
|
+
if (/\bgzip\b/.test(contentEncoding) || /\bdeflate\b/.test(contentEncoding)) {
|
|
47
|
+
result = zlib.unzipSync(buffer, {
|
|
48
|
+
flush: zlib.constants.Z_SYNC_FLUSH,
|
|
49
|
+
finishFlush: zlib.constants.Z_SYNC_FLUSH,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else if (/\bbr\b/.test(contentEncoding)) {
|
|
53
|
+
result = zlib.brotliDecompressSync(buffer);
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
@@ -9,6 +9,7 @@ export default class CliHistory {
|
|
|
9
9
|
static recordManifest(manifest: Record<string, any>): void;
|
|
10
10
|
static recordSimulator(simulator: string): void;
|
|
11
11
|
static checkManifest(manifest: Record<string, any>): boolean;
|
|
12
|
+
static checkTestAppIsExist(): boolean;
|
|
12
13
|
private static compareObjects;
|
|
13
14
|
static checkCommand(cmd: string): boolean;
|
|
14
15
|
static write(): void;
|