@applicaster/zapplicaster-cli 15.0.0-rc.98 → 15.1.0-alpha.1852552014
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/package.json +5 -5
- package/src/commands/index.js +1 -5
- package/src/commands/prepareWorkspace/appBootstrapper.js +4 -0
- package/src/commands/prepareWorkspace/configurator.js +7 -1
- package/src/commands/prepareWorkspace/parseFonts.js +6 -0
- package/src/commands/publishPlugin/__tests__/__snapshots__/configurator.test.js.snap +0 -3
- package/src/commands/publishPlugin/__tests__/configurator.test.js +3 -2
- package/src/commands/publishPlugin/__tests__/generateManifest.test.js +5 -14
- package/src/commands/publishPlugin/configurator.js +0 -6
- package/src/commands/publishPlugin/generateManifest.js +6 -6
- package/src/commands/publishPlugin/zappifestPublish.js +1 -1
- package/src/download/__tests__/download.test.js +53 -0
- package/src/download/index.js +65 -1
- package/src/file/index.js +15 -9
- package/src/templates/__tests__/__snapshots__/templates.test.js.snap +1 -1
- package/src/templates/index.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapplicaster-cli",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.1.0-alpha.1852552014",
|
|
4
4
|
"description": "CLI Tool for the zapp app and Quick Brick project",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/zapp-react-dom-cli-template": "15.
|
|
32
|
-
"@applicaster/zapp-react-native-android-tv-cli-template": "15.
|
|
33
|
-
"@applicaster/zapp-react-native-cli-template": "15.
|
|
34
|
-
"@applicaster/zapp-react-native-tvos-cli-template": "15.
|
|
31
|
+
"@applicaster/zapp-react-dom-cli-template": "15.1.0-alpha.1852552014",
|
|
32
|
+
"@applicaster/zapp-react-native-android-tv-cli-template": "15.1.0-alpha.1852552014",
|
|
33
|
+
"@applicaster/zapp-react-native-cli-template": "15.1.0-alpha.1852552014",
|
|
34
|
+
"@applicaster/zapp-react-native-tvos-cli-template": "15.1.0-alpha.1852552014",
|
|
35
35
|
"axios": "^0.28.0",
|
|
36
36
|
"camelize": "^1.0.0",
|
|
37
37
|
"chalk": "^2.3.2",
|
package/src/commands/index.js
CHANGED
|
@@ -117,16 +117,12 @@ const commands = [
|
|
|
117
117
|
["-g, --skip-git", "Doesn't commit changes to git"],
|
|
118
118
|
[
|
|
119
119
|
"-s, --single-platform [singlePlatform]",
|
|
120
|
-
"Platform to deploy.
|
|
120
|
+
"Platform to deploy. Ommit to publish for all supported platforms",
|
|
121
121
|
],
|
|
122
122
|
[
|
|
123
123
|
"-m, --manifest-only",
|
|
124
124
|
"Only generates the manifest file, doesn't publish the plugin",
|
|
125
125
|
],
|
|
126
|
-
[
|
|
127
|
-
"-t, --targets [targets]",
|
|
128
|
-
"Comma-separated list of targets (e.g., 'tv,mobile,tablet') for iterative releases",
|
|
129
|
-
],
|
|
130
126
|
],
|
|
131
127
|
action: publishPlugin,
|
|
132
128
|
},
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
const R = require("ramda");
|
|
2
2
|
const axios = require("axios");
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
platformIsTV,
|
|
6
|
+
} = require("@applicaster/zapp-react-native-utils/manifestUtils/platformIsTV");
|
|
7
|
+
|
|
3
8
|
const { getAppVersionParams } = require("../../zapp");
|
|
4
9
|
const { resolveAppTemplate } = require("../../templates");
|
|
5
10
|
const { isZappReactNativeRepo } = require("../../settings");
|
|
@@ -11,6 +16,7 @@ const store_map = {
|
|
|
11
16
|
samsung_app_store: "samsung_tv",
|
|
12
17
|
lg_content_store: "lg_tv",
|
|
13
18
|
vizio_app_store: "vizio",
|
|
19
|
+
vidaa_app_store: "vidaa",
|
|
14
20
|
};
|
|
15
21
|
|
|
16
22
|
/**
|
|
@@ -21,7 +27,7 @@ const store_map = {
|
|
|
21
27
|
*/
|
|
22
28
|
async function retrievesSpinnerColor(url, platform) {
|
|
23
29
|
try {
|
|
24
|
-
if (!
|
|
30
|
+
if (!platformIsTV(platform)) {
|
|
25
31
|
return;
|
|
26
32
|
}
|
|
27
33
|
|
|
@@ -10,7 +10,6 @@ const getOptions = (opts = {}) => ({
|
|
|
10
10
|
version: "1.5.0",
|
|
11
11
|
singlePlatform: "",
|
|
12
12
|
skipGit: false,
|
|
13
|
-
targets: "tv",
|
|
14
13
|
...opts,
|
|
15
14
|
},
|
|
16
15
|
});
|
|
@@ -103,7 +102,9 @@ describe("publish plugin configurator", () => {
|
|
|
103
102
|
|
|
104
103
|
it("returns the configuration", async () => {
|
|
105
104
|
const options = getOptions();
|
|
106
|
-
|
|
105
|
+
const config = await configurator(options);
|
|
106
|
+
|
|
107
|
+
expect(config).toMatchSnapshot();
|
|
107
108
|
expect(logger.log.mock.calls).toMatchSnapshot();
|
|
108
109
|
});
|
|
109
110
|
|
|
@@ -42,19 +42,9 @@ function clearMocks() {
|
|
|
42
42
|
describe("generate manifest", () => {
|
|
43
43
|
beforeEach(clearMocks);
|
|
44
44
|
|
|
45
|
-
it("
|
|
46
|
-
const configuration = getConfig({
|
|
47
|
-
platforms: ["android", "invalid_platform"],
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
await expect(generateManifest(configuration)).rejects.toThrow(
|
|
51
|
-
/Invalid platform provided/
|
|
52
|
-
);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("doesn't create the manifest if there is no platform", async () => {
|
|
45
|
+
it("doesn't create the manifest if there is no platform", () => {
|
|
56
46
|
const configuration = getConfig({ platforms: undefined });
|
|
57
|
-
|
|
47
|
+
expect(generateManifest(configuration)).resolves.toBe(true);
|
|
58
48
|
expect(writeJsonToFile).not.toHaveBeenCalled();
|
|
59
49
|
});
|
|
60
50
|
|
|
@@ -101,11 +91,12 @@ describe("generate manifest", () => {
|
|
|
101
91
|
|
|
102
92
|
it("throws if the config file cannot be found", async () => {
|
|
103
93
|
const configuration = getConfig({ pluginPath: "resolve_error" });
|
|
104
|
-
|
|
94
|
+
|
|
95
|
+
expect(generateManifest(configuration)).rejects.toMatchSnapshot();
|
|
105
96
|
});
|
|
106
97
|
|
|
107
98
|
it("throws if the manifests cannot be written", async () => {
|
|
108
99
|
const configuration = getConfig({ pluginPath: "write_error" });
|
|
109
|
-
|
|
100
|
+
expect(generateManifest(configuration)).rejects.toMatchSnapshot();
|
|
110
101
|
});
|
|
111
102
|
});
|
|
@@ -74,7 +74,6 @@ async function configurator({ cliArgs, cliOptions }) {
|
|
|
74
74
|
singlePlatform: platform = "",
|
|
75
75
|
skipGit = false,
|
|
76
76
|
manifestOnly = false,
|
|
77
|
-
targets,
|
|
78
77
|
} = cliOptions;
|
|
79
78
|
|
|
80
79
|
if (!version || !semver.valid(version)) {
|
|
@@ -122,10 +121,6 @@ async function configurator({ cliArgs, cliOptions }) {
|
|
|
122
121
|
);
|
|
123
122
|
}
|
|
124
123
|
|
|
125
|
-
const parsedTargets = targets
|
|
126
|
-
? targets.split(",").map((t) => t.trim())
|
|
127
|
-
: undefined;
|
|
128
|
-
|
|
129
124
|
const config = {
|
|
130
125
|
pluginPath: resolvedPluginPath,
|
|
131
126
|
pluginPackageJson,
|
|
@@ -138,7 +133,6 @@ async function configurator({ cliArgs, cliOptions }) {
|
|
|
138
133
|
skipGit,
|
|
139
134
|
zappOwnerAccountId,
|
|
140
135
|
manifestOnly,
|
|
141
|
-
targets: parsedTargets,
|
|
142
136
|
};
|
|
143
137
|
|
|
144
138
|
return config;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const R = require("ramda");
|
|
1
2
|
const { resolve } = require("path");
|
|
2
3
|
const { inspect } = require("util");
|
|
3
4
|
|
|
@@ -26,10 +27,9 @@ function renderManifest({
|
|
|
26
27
|
pluginPath,
|
|
27
28
|
version,
|
|
28
29
|
dryRun,
|
|
29
|
-
targets,
|
|
30
30
|
}) {
|
|
31
31
|
return async function (platform) {
|
|
32
|
-
const manifest = manifestConfig({ platform, version
|
|
32
|
+
const manifest = manifestConfig({ platform, version });
|
|
33
33
|
|
|
34
34
|
const enrichedManifest = enrichManifest({ manifest, packageJson });
|
|
35
35
|
|
|
@@ -50,6 +50,7 @@ function renderManifest({
|
|
|
50
50
|
|
|
51
51
|
const validPlatforms = [
|
|
52
52
|
"lg_tv",
|
|
53
|
+
"vidaa",
|
|
53
54
|
"samsung_tv",
|
|
54
55
|
"vizio",
|
|
55
56
|
"android_tv_for_quickbrick",
|
|
@@ -62,10 +63,10 @@ const validPlatforms = [
|
|
|
62
63
|
];
|
|
63
64
|
|
|
64
65
|
async function generateManifest(configuration) {
|
|
65
|
-
const { pluginPath, platforms, version, dryRun
|
|
66
|
+
const { pluginPath, platforms, version, dryRun } = configuration;
|
|
66
67
|
|
|
67
68
|
if (!platforms) {
|
|
68
|
-
logger.log("Manifest does not
|
|
69
|
+
logger.log("Manifest does not exist, Skipping generation");
|
|
69
70
|
|
|
70
71
|
return true;
|
|
71
72
|
}
|
|
@@ -89,10 +90,9 @@ async function generateManifest(configuration) {
|
|
|
89
90
|
packageJson,
|
|
90
91
|
version,
|
|
91
92
|
dryRun,
|
|
92
|
-
targets,
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
return Promise.all(
|
|
95
|
+
return Promise.all(R.map(manifestRenderer, platforms));
|
|
96
96
|
} catch (e) {
|
|
97
97
|
throw new Error(
|
|
98
98
|
"An error occured when generating the manifest: " + e.message
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { saveRemoteJsonToFile, saveAssets, saveFontFiles } = require("../index");
|
|
2
2
|
const nock = require("nock");
|
|
3
3
|
const R = require("ramda");
|
|
4
|
+
const fs = require("fs");
|
|
4
5
|
const logger = require("../../logger");
|
|
5
6
|
|
|
6
7
|
const getFileName = R.compose(R.last, R.split("/"));
|
|
@@ -109,9 +110,37 @@ describe("saveAssets", () => {
|
|
|
109
110
|
|
|
110
111
|
afterEach(() => {
|
|
111
112
|
clearAllMocks();
|
|
113
|
+
|
|
114
|
+
["existsSync", "openSync", "closeSync", "readSync", "readFileSync"].forEach(
|
|
115
|
+
(method) => {
|
|
116
|
+
if (fs[method] && fs[method].mockRestore) {
|
|
117
|
+
fs[method].mockRestore();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
);
|
|
112
121
|
});
|
|
113
122
|
|
|
123
|
+
function mockDownloadedFile({ isZip, content } = {}) {
|
|
124
|
+
jest.spyOn(fs, "existsSync").mockReturnValue(true);
|
|
125
|
+
jest.spyOn(fs, "openSync").mockReturnValue(1);
|
|
126
|
+
jest.spyOn(fs, "closeSync").mockImplementation(() => ({}));
|
|
127
|
+
|
|
128
|
+
jest.spyOn(fs, "readSync").mockImplementation((fd, buffer) => {
|
|
129
|
+
const header = isZip
|
|
130
|
+
? Buffer.from([0x50, 0x4b, 0x03, 0x04])
|
|
131
|
+
: Buffer.from("<?xm");
|
|
132
|
+
|
|
133
|
+
header.copy(buffer);
|
|
134
|
+
|
|
135
|
+
return 4;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
jest.spyOn(fs, "readFileSync").mockReturnValue(content || "");
|
|
139
|
+
}
|
|
140
|
+
|
|
114
141
|
it("downloads the files with cURL, and unzips the assets", () => {
|
|
142
|
+
mockDownloadedFile({ isZip: true });
|
|
143
|
+
|
|
115
144
|
saveAssets({ destinationPath, platform }, assetsUrl);
|
|
116
145
|
|
|
117
146
|
expect(loggerSpy).toHaveBeenCalledWith(`saving assets from ${assetsUrl}`);
|
|
@@ -122,6 +151,30 @@ describe("saveAssets", () => {
|
|
|
122
151
|
filePath
|
|
123
152
|
);
|
|
124
153
|
});
|
|
154
|
+
|
|
155
|
+
it("throws a clear error and skips unzip when the bundle is not a zip", () => {
|
|
156
|
+
mockDownloadedFile({
|
|
157
|
+
isZip: false,
|
|
158
|
+
content:
|
|
159
|
+
'<?xml version="1.0" encoding="UTF-8"?><Error><Code>AccessDenied</Code></Error>',
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
expect(() => saveAssets({ destinationPath, platform }, assetsUrl)).toThrow(
|
|
163
|
+
/AccessDenied/
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
expect(shell.unzip).not.toHaveBeenCalled();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("throws a clear error when the bundle was not downloaded", () => {
|
|
170
|
+
jest.spyOn(fs, "existsSync").mockReturnValue(false);
|
|
171
|
+
|
|
172
|
+
expect(() => saveAssets({ destinationPath, platform }, assetsUrl)).toThrow(
|
|
173
|
+
/was not downloaded/
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
expect(shell.unzip).not.toHaveBeenCalled();
|
|
177
|
+
});
|
|
125
178
|
});
|
|
126
179
|
|
|
127
180
|
describe("saveFontFiles", () => {
|
package/src/download/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const R = require("ramda");
|
|
2
|
+
const fs = require("fs");
|
|
2
3
|
const axios = require("axios");
|
|
3
4
|
const { resolve } = require("path");
|
|
4
5
|
const { curlFile, curlMultipleFiles, unzip } = require("../shell");
|
|
@@ -12,6 +13,64 @@ const getFileName = R.ifElse(
|
|
|
12
13
|
R.prop("name")
|
|
13
14
|
);
|
|
14
15
|
|
|
16
|
+
// Local file signature for a zip archive: "PK\x03\x04"
|
|
17
|
+
const ZIP_SIGNATURE = "504b0304";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* checks whether a file on disk is a real zip archive by reading its magic bytes.
|
|
21
|
+
* @param {String} file path to the file to inspect
|
|
22
|
+
* @returns {Boolean} true if the file starts with the zip local file signature
|
|
23
|
+
*/
|
|
24
|
+
function isZipFile(file) {
|
|
25
|
+
const fd = fs.openSync(file, "r");
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const header = Buffer.alloc(4);
|
|
29
|
+
const bytesRead = fs.readSync(fd, header, 0, 4, 0);
|
|
30
|
+
|
|
31
|
+
return bytesRead === 4 && header.toString("hex") === ZIP_SIGNATURE;
|
|
32
|
+
} finally {
|
|
33
|
+
fs.closeSync(fd);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* verifies that the downloaded assets bundle is a real zip archive.
|
|
39
|
+
* The assets CDN responds with a small XML/HTML body (e.g. S3 "AccessDenied")
|
|
40
|
+
* when the bundle is missing or not yet published. Because the download uses
|
|
41
|
+
* `curl -O` without `-f`, that error body is saved as assets.zip and the process
|
|
42
|
+
* continues, only to crash later in webpack with a confusing parse error. This
|
|
43
|
+
* check fails fast in the prepare step with an actionable message instead.
|
|
44
|
+
* @param {String} file path to the downloaded assets bundle
|
|
45
|
+
* @param {String} assetsUrl original url, surfaced in the error message
|
|
46
|
+
*/
|
|
47
|
+
function assertValidAssetsBundle(file, assetsUrl) {
|
|
48
|
+
if (!fs.existsSync(file)) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Assets bundle was not downloaded from ${assetsUrl}. ` +
|
|
51
|
+
"Verify the app has a published build with generated assets for this platform."
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (isZipFile(file)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const preview = fs
|
|
60
|
+
.readFileSync(file, "utf8")
|
|
61
|
+
.replace(/\s+/g, " ")
|
|
62
|
+
.trim()
|
|
63
|
+
.slice(0, 300);
|
|
64
|
+
|
|
65
|
+
throw new Error(
|
|
66
|
+
`Invalid assets bundle downloaded from ${assetsUrl} - expected a zip archive ` +
|
|
67
|
+
`but received non-zip content:\n "${preview}"\n` +
|
|
68
|
+
"This usually means the assets bundle has not been generated/published for " +
|
|
69
|
+
'this platform, or the URL is not accessible (e.g. S3 "AccessDenied"). ' +
|
|
70
|
+
"Publish a build with assets for this platform before preparing the workspace."
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
15
74
|
/**
|
|
16
75
|
* saves a remote json file in the app's configuration folder.
|
|
17
76
|
* curried function of the shape saveRemoteJsonToFile(configuration)(fileUrl)
|
|
@@ -65,7 +124,12 @@ function saveAssets({ destinationPath, platform }, assetsUrl) {
|
|
|
65
124
|
});
|
|
66
125
|
|
|
67
126
|
curlFile(assetsUrl, filePath);
|
|
68
|
-
|
|
127
|
+
|
|
128
|
+
const downloadedFile = resolve(filePath, fileName);
|
|
129
|
+
|
|
130
|
+
assertValidAssetsBundle(downloadedFile, assetsUrl);
|
|
131
|
+
|
|
132
|
+
unzip(downloadedFile, filePath);
|
|
69
133
|
}
|
|
70
134
|
|
|
71
135
|
/**
|
package/src/file/index.js
CHANGED
|
@@ -61,8 +61,13 @@ function destinationFileNameMapper(destinationFileName) {
|
|
|
61
61
|
/**
|
|
62
62
|
* Copies an array of files from a folder to another
|
|
63
63
|
*
|
|
64
|
+
* Each entry can either be a string (same relative path for source and
|
|
65
|
+
* destination) or an object `{ source, destination }` when a file should be
|
|
66
|
+
* read from one relative path and written to another. The latter lets several
|
|
67
|
+
* platforms reuse a single set of bundled assets without duplicating them.
|
|
68
|
+
*
|
|
64
69
|
* @param {String} source folder of the files
|
|
65
|
-
* @param {String[]} files list of the files
|
|
70
|
+
* @param {(String|{source: String, destination: String})[]} files list of the files
|
|
66
71
|
* @param {String} destination path
|
|
67
72
|
* @returns {Promise[]} array of promises with the status of the copied files
|
|
68
73
|
*/
|
|
@@ -72,14 +77,15 @@ function copyFiles(source, filesOrFilesGetter, destination, config) {
|
|
|
72
77
|
? filesOrFilesGetter(config)
|
|
73
78
|
: filesOrFilesGetter;
|
|
74
79
|
|
|
75
|
-
return R.map(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
),
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
return R.map((file) => {
|
|
81
|
+
const sourceFile = typeof file === "string" ? file : file.source;
|
|
82
|
+
const destinationFile = typeof file === "string" ? file : file.destination;
|
|
83
|
+
|
|
84
|
+
return copyFileSync(
|
|
85
|
+
join(source, sourceFile),
|
|
86
|
+
destinationFileNameMapper(join(destination, destinationFile))
|
|
87
|
+
);
|
|
88
|
+
}, files);
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
module.exports = {
|
|
@@ -32,4 +32,4 @@ exports[`resolveAppTemplate retrieves the template from the provided path if pro
|
|
|
32
32
|
}
|
|
33
33
|
`;
|
|
34
34
|
|
|
35
|
-
exports[`resolveAppTemplate throws if resolving a template for an unknown platform 1`] = `"could not find template for foo - available templates: ios,android,samsung_tv,lg_tv,vizio,apple_tv,android_tv,amazon"`;
|
|
35
|
+
exports[`resolveAppTemplate throws if resolving a template for an unknown platform 1`] = `"could not find template for foo - available templates: ios,android,samsung_tv,lg_tv,vidaa,vizio,apple_tv,android_tv,amazon"`;
|
package/src/templates/index.js
CHANGED
|
@@ -27,6 +27,7 @@ const templatesMap = {
|
|
|
27
27
|
android: "@applicaster/zapp-react-native-cli-template",
|
|
28
28
|
samsung_tv: "@applicaster/zapp-react-dom-cli-template",
|
|
29
29
|
lg_tv: "@applicaster/zapp-react-dom-cli-template",
|
|
30
|
+
vidaa: "@applicaster/zapp-react-dom-cli-template",
|
|
30
31
|
vizio: "@applicaster/zapp-react-dom-cli-template",
|
|
31
32
|
apple_tv: "@applicaster/zapp-react-native-tvos-cli-template",
|
|
32
33
|
android_tv: "@applicaster/zapp-react-native-android-tv-cli-template",
|