@applicaster/zapplicaster-cli 16.0.0-alpha.7128076344 → 16.0.0-alpha.7354639420
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/prepareWorkspace/__tests__/__snapshots__/configurator.test.js.snap +2 -0
- package/src/commands/prepareWorkspace/__tests__/buildPluginsCreator.test.js +99 -0
- package/src/commands/prepareWorkspace/appBootstrapper.js +44 -7
- package/src/commands/prepareWorkspace/buildPluginsCreator.js +61 -0
- package/src/commands/prepareWorkspace/configFilesRetriever.js +3 -0
- package/src/commands/prepareWorkspace/configurator.js +26 -1
- package/src/commands/prepareWorkspace/parseFonts.js +6 -0
- package/src/commands/publishPlugin/README.md +140 -0
- package/src/commands/publishPlugin/__tests__/commitToGit.test.js +1 -1
- package/src/commands/publishPlugin/__tests__/configurator.test.js +2 -2
- package/src/commands/publishPlugin/__tests__/manifests/android.json +3 -1
- package/src/commands/publishPlugin/__tests__/manifests/android_for_quickbrick.json +6 -0
- package/src/commands/publishPlugin/__tests__/manifests/android_tv_for_quickbrick.json +6 -0
- package/src/commands/publishPlugin/__tests__/manifests/ios.json +3 -1
- package/src/commands/publishPlugin/__tests__/manifests/ios_for_quickbrick.json +6 -0
- package/src/commands/publishPlugin/__tests__/manifests/tvos_for_quickbrick.json +6 -0
- package/src/commands/publishPlugin/__tests__/zappApi.test.js +271 -0
- package/src/commands/publishPlugin/__tests__/zappifestPublish.test.js +109 -33
- package/src/commands/publishPlugin/commitToGit.js +1 -1
- package/src/commands/publishPlugin/configurator.js +1 -1
- package/src/commands/publishPlugin/generateManifest.js +1 -0
- package/src/commands/publishPlugin/updateCorePluginsIfNeeded.js +22 -12
- package/src/commands/publishPlugin/zappApi.js +283 -0
- package/src/commands/publishPlugin/zappifestPublish.js +123 -8
- package/src/commands/reloadConfig/__tests__/__snapshots__/reloadConfig.test.js.snap +58 -0
- package/src/commands/reloadConfig/__tests__/reloadConfig.test.js +86 -0
- package/src/commands/reloadConfig/index.js +6 -6
- package/src/download/__tests__/download.test.js +53 -0
- package/src/download/index.js +65 -1
- package/src/file/__tests__/__snapshots__/file.test.js.snap +0 -19
- package/src/file/__tests__/file.test.js +16 -40
- package/src/file/index.js +16 -43
- package/src/templates/__tests__/__snapshots__/templates.test.js.snap +1 -1
- package/src/templates/index.js +1 -0
- package/test_helpers/fsMock.js +0 -10
- package/src/commands/publishPlugin/__tests__/__snapshots__/zappifestPublish.test.js.snap +0 -5
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
|
/**
|
|
@@ -5,27 +5,10 @@ exports[`copyFiles when destination path has no package.json doesn't skips the c
|
|
|
5
5
|
[
|
|
6
6
|
"some/source/path/foo.json",
|
|
7
7
|
"some/destination/Path/foo.json",
|
|
8
|
-
[Function],
|
|
9
8
|
],
|
|
10
9
|
[
|
|
11
10
|
"some/source/path/package.json",
|
|
12
11
|
"some/destination/Path/package.json",
|
|
13
|
-
[Function],
|
|
14
|
-
],
|
|
15
|
-
]
|
|
16
|
-
`;
|
|
17
|
-
|
|
18
|
-
exports[`copyFiles when there is no package.json to copy copies the dir 1`] = `
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
"some/source/path/files/file1.txt",
|
|
22
|
-
"some/destination/Path/files/file1.txt",
|
|
23
|
-
[Function],
|
|
24
|
-
],
|
|
25
|
-
[
|
|
26
|
-
"some/source/path/files/file2.txt",
|
|
27
|
-
"some/destination/Path/files/file2.txt",
|
|
28
|
-
[Function],
|
|
29
12
|
],
|
|
30
13
|
]
|
|
31
14
|
`;
|
|
@@ -35,12 +18,10 @@ exports[`copyFiles when there is no package.json to copy copies the files 1`] =
|
|
|
35
18
|
[
|
|
36
19
|
"some/source/path/foo.json",
|
|
37
20
|
"some/destination/Path/foo.json",
|
|
38
|
-
[Function],
|
|
39
21
|
],
|
|
40
22
|
[
|
|
41
23
|
"some/source/path/bar.json",
|
|
42
24
|
"some/destination/Path/bar.json",
|
|
43
|
-
[Function],
|
|
44
25
|
],
|
|
45
26
|
]
|
|
46
27
|
`;
|
|
@@ -38,27 +38,14 @@ describe("copyFiles", () => {
|
|
|
38
38
|
fs.writeFile("foo.json", { foo: "bar" }, jest.fn());
|
|
39
39
|
fs.writeFile("bar.json", { bar: "baz" }, jest.fn());
|
|
40
40
|
fs.writeFile("qux.json", { qux: 42 }, jest.fn());
|
|
41
|
-
fs.
|
|
42
|
-
fs.readdir.mockClear();
|
|
41
|
+
fs.copyFileSync.mockClear();
|
|
43
42
|
});
|
|
44
43
|
|
|
45
44
|
describe("when there is no package.json to copy", () => {
|
|
46
|
-
it("copies the files",
|
|
47
|
-
|
|
48
|
-
expect(fs.
|
|
49
|
-
expect(fs.
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("copies the dir", async () => {
|
|
53
|
-
// Mock fs.readdir to return some files when the directory is read
|
|
54
|
-
fs.readdir.mockImplementationOnce((path, callback) => {
|
|
55
|
-
callback(null, ["file1.txt", "file2.txt"]);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
await copyFiles(sourcePath, ["files/"], destinationPath);
|
|
59
|
-
|
|
60
|
-
expect(fs.copyFile).toHaveBeenCalledTimes(2);
|
|
61
|
-
expect(fs.copyFile.mock.calls).toMatchSnapshot();
|
|
45
|
+
it("copies the files", () => {
|
|
46
|
+
copyFiles(sourcePath, ["foo.json", "bar.json"], destinationPath);
|
|
47
|
+
expect(fs.copyFileSync).toHaveBeenCalledTimes(2);
|
|
48
|
+
expect(fs.copyFileSync.mock.calls).toMatchSnapshot();
|
|
62
49
|
});
|
|
63
50
|
});
|
|
64
51
|
|
|
@@ -73,40 +60,29 @@ describe("copyFiles", () => {
|
|
|
73
60
|
fs.__resetFiles();
|
|
74
61
|
});
|
|
75
62
|
|
|
76
|
-
it("overrides it",
|
|
63
|
+
it("overrides it", () => {
|
|
77
64
|
const sourcePath = "some/source/path";
|
|
78
65
|
const destinationPath = "some/destination/Path";
|
|
79
66
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
["foo.json", "package.json"],
|
|
83
|
-
destinationPath
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
expect(fs.copyFile).toHaveBeenCalledTimes(2);
|
|
67
|
+
copyFiles(sourcePath, ["foo.json", "package.json"], destinationPath);
|
|
68
|
+
expect(fs.copyFileSync).toHaveBeenCalledTimes(2);
|
|
87
69
|
|
|
88
|
-
expect(fs.
|
|
70
|
+
expect(fs.copyFileSync).toHaveBeenCalledWith(
|
|
89
71
|
`${sourcePath}/foo.json`,
|
|
90
|
-
`${destinationPath}/foo.json
|
|
91
|
-
expect.any(Function)
|
|
72
|
+
`${destinationPath}/foo.json`
|
|
92
73
|
);
|
|
93
74
|
});
|
|
94
75
|
});
|
|
95
76
|
|
|
96
77
|
describe("when destination path has no package.json", () => {
|
|
97
|
-
it("doesn't skips the copy",
|
|
78
|
+
it("doesn't skips the copy", () => {
|
|
98
79
|
const sourcePath = "some/source/path";
|
|
99
80
|
const destinationPath = "some/destination/Path";
|
|
100
81
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
["foo.json", "package.json"],
|
|
104
|
-
destinationPath
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
expect(fs.copyFile).toHaveBeenCalledTimes(2);
|
|
82
|
+
copyFiles(sourcePath, ["foo.json", "package.json"], destinationPath);
|
|
83
|
+
expect(fs.copyFileSync).toHaveBeenCalledTimes(2);
|
|
108
84
|
|
|
109
|
-
expect(fs.
|
|
85
|
+
expect(fs.copyFileSync.mock.calls).toMatchSnapshot();
|
|
110
86
|
expect(logger.warn).not.toHaveBeenCalled();
|
|
111
87
|
});
|
|
112
88
|
});
|
|
@@ -124,7 +100,7 @@ describe("copyFolder", () => {
|
|
|
124
100
|
});
|
|
125
101
|
|
|
126
102
|
beforeEach(() => {
|
|
127
|
-
fs.
|
|
103
|
+
fs.copyFileSync.mockClear();
|
|
128
104
|
});
|
|
129
105
|
|
|
130
106
|
it("copies the file in the folder", async () => {
|
|
@@ -134,7 +110,7 @@ describe("copyFolder", () => {
|
|
|
134
110
|
await copyFolder(sourcePath, destinationPath);
|
|
135
111
|
|
|
136
112
|
expect(fs.readdir).toHaveBeenCalledWith(sourcePath, expect.any(Function));
|
|
137
|
-
expect(fs.
|
|
113
|
+
expect(fs.copyFileSync).toHaveBeenCalledTimes(2);
|
|
138
114
|
});
|
|
139
115
|
|
|
140
116
|
afterAll(() => {
|
package/src/file/index.js
CHANGED
|
@@ -5,16 +5,7 @@ const R = require("ramda");
|
|
|
5
5
|
* @module @applicaster/zapplicaster-cli/util/file
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const {
|
|
9
|
-
writeFile,
|
|
10
|
-
readFile,
|
|
11
|
-
readdir,
|
|
12
|
-
copyFile,
|
|
13
|
-
lstatSync,
|
|
14
|
-
mkdirSync,
|
|
15
|
-
existsSync,
|
|
16
|
-
} = require("fs");
|
|
17
|
-
|
|
8
|
+
const { writeFile, readFile, readdir, copyFile, copyFileSync } = require("fs");
|
|
18
9
|
const { promisify } = require("util");
|
|
19
10
|
const { join } = require("path");
|
|
20
11
|
|
|
@@ -70,49 +61,31 @@ function destinationFileNameMapper(destinationFileName) {
|
|
|
70
61
|
/**
|
|
71
62
|
* Copies an array of files from a folder to another
|
|
72
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
|
+
*
|
|
73
69
|
* @param {String} source folder of the files
|
|
74
|
-
* @param {String[]} files list of the files
|
|
70
|
+
* @param {(String|{source: String, destination: String})[]} files list of the files
|
|
75
71
|
* @param {String} destination path
|
|
76
72
|
* @returns {Promise[]} array of promises with the status of the copied files
|
|
77
73
|
*/
|
|
78
|
-
|
|
74
|
+
function copyFiles(source, filesOrFilesGetter, destination, config) {
|
|
79
75
|
const files =
|
|
80
76
|
typeof filesOrFilesGetter === "function"
|
|
81
77
|
? filesOrFilesGetter(config)
|
|
82
78
|
: filesOrFilesGetter;
|
|
83
79
|
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
try {
|
|
89
|
-
if (Array.isArray(file)) {
|
|
90
|
-
sourcePath = join(source, file[0]);
|
|
91
|
-
|
|
92
|
-
destinationPath = destinationFileNameMapper(
|
|
93
|
-
join(destination, file[1])
|
|
94
|
-
);
|
|
95
|
-
} else {
|
|
96
|
-
sourcePath = join(source, file);
|
|
97
|
-
destinationPath = destinationFileNameMapper(join(destination, file));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (lstatSync(sourcePath).isDirectory()) {
|
|
101
|
-
if (!existsSync(destinationPath)) {
|
|
102
|
-
mkdirSync(destinationPath, { recursive: true });
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return await copyFolder(sourcePath, destinationPath);
|
|
106
|
-
}
|
|
80
|
+
return R.map((file) => {
|
|
81
|
+
const sourceFile = typeof file === "string" ? file : file.source;
|
|
82
|
+
const destinationFile = typeof file === "string" ? file : file.destination;
|
|
107
83
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
}, files)
|
|
115
|
-
);
|
|
84
|
+
return copyFileSync(
|
|
85
|
+
join(source, sourceFile),
|
|
86
|
+
destinationFileNameMapper(join(destination, destinationFile))
|
|
87
|
+
);
|
|
88
|
+
}, files);
|
|
116
89
|
}
|
|
117
90
|
|
|
118
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",
|
package/test_helpers/fsMock.js
CHANGED
|
@@ -2,10 +2,6 @@ const fs = jest.genMockFromModule("fs");
|
|
|
2
2
|
const _fs = jest.requireActual("fs");
|
|
3
3
|
const R = require("ramda");
|
|
4
4
|
|
|
5
|
-
function mkdirSync() {
|
|
6
|
-
return undefined;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
5
|
function readdirSync(folder) {
|
|
10
6
|
return _fs.readdirSync(folder);
|
|
11
7
|
}
|
|
@@ -81,16 +77,10 @@ function __resetFiles() {
|
|
|
81
77
|
fs.__writenFiles = [];
|
|
82
78
|
}
|
|
83
79
|
|
|
84
|
-
fs.lstatSync = (_path) => ({
|
|
85
|
-
isDirectory: () => _path.endsWith("/"),
|
|
86
|
-
isFile: () => _path.endsWith("/") === false,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
80
|
fs.__writenFiles = [];
|
|
90
81
|
fs.__resetFiles = __resetFiles;
|
|
91
82
|
fs.__addMockedFiles = __addMockedFiles;
|
|
92
83
|
fs.readdirSync = readdirSync;
|
|
93
|
-
fs.mkdirSync = mkdirSync;
|
|
94
84
|
fs.readdir = jest.fn(readdir);
|
|
95
85
|
fs.writeFile = jest.fn(writeFile);
|
|
96
86
|
fs.readFile = jest.fn(readFile);
|