@applicaster/zapplicaster-cli 15.0.0-alpha.3564837831 → 15.0.0-alpha.3634430569

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapplicaster-cli",
3
- "version": "15.0.0-alpha.3564837831",
3
+ "version": "15.0.0-alpha.3634430569",
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.0.0-alpha.3564837831",
32
- "@applicaster/zapp-react-native-android-tv-cli-template": "15.0.0-alpha.3564837831",
33
- "@applicaster/zapp-react-native-cli-template": "15.0.0-alpha.3564837831",
34
- "@applicaster/zapp-react-native-tvos-cli-template": "15.0.0-alpha.3564837831",
31
+ "@applicaster/zapp-react-dom-cli-template": "15.0.0-alpha.3634430569",
32
+ "@applicaster/zapp-react-native-android-tv-cli-template": "15.0.0-alpha.3634430569",
33
+ "@applicaster/zapp-react-native-cli-template": "15.0.0-alpha.3634430569",
34
+ "@applicaster/zapp-react-native-tvos-cli-template": "15.0.0-alpha.3634430569",
35
35
  "axios": "^0.28.0",
36
36
  "camelize": "^1.0.0",
37
37
  "chalk": "^2.3.2",
@@ -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. Ommit to publish for all supported platforms",
120
+ "Platform to deploy. Omit 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,4 +1,7 @@
1
1
  const { appBootstrapper, isVersionSatisfies } = require("../appBootstrapper");
2
+ const { mkdtempSync, mkdirSync, writeFileSync, rmSync } = require("fs");
3
+ const os = require("os");
4
+ const path = require("path");
2
5
 
3
6
  jest.mock("path", () => ({
4
7
  ...jest.requireActual("path"),
@@ -214,6 +217,43 @@ describe("appBootstrapper", () => {
214
217
  expect(exec.mock.calls).toMatchSnapshot();
215
218
  });
216
219
 
220
+ it("applies rn-patches from development-app to root node_modules", async () => {
221
+ const quickBrickProjectPath = mkdtempSync(
222
+ path.join(os.tmpdir(), "quick-brick-workspace-")
223
+ );
224
+
225
+ mkdirSync(
226
+ path.join(quickBrickProjectPath, "node_modules", "quick-brick-app"),
227
+ {
228
+ recursive: true,
229
+ }
230
+ );
231
+
232
+ mkdirSync(
233
+ path.join(quickBrickProjectPath, "development-app", "rn-patches"),
234
+ {
235
+ recursive: true,
236
+ }
237
+ );
238
+
239
+ writeFileSync(
240
+ path.join(quickBrickProjectPath, "package.json"),
241
+ JSON.stringify({ workspaces: ["development-app"] })
242
+ );
243
+
244
+ try {
245
+ const config = configuration({ destinationPath: quickBrickProjectPath });
246
+
247
+ await appBootstrapper(config);
248
+
249
+ expect(exec).toHaveBeenLastCalledWith(
250
+ `yarn patch-package --patch-dir ${quickBrickProjectPath}/development-app/rn-patches`
251
+ );
252
+ } finally {
253
+ rmSync(quickBrickProjectPath, { recursive: true, force: true });
254
+ }
255
+ });
256
+
217
257
  it("Version satisfies", async () => {
218
258
  expect(isVersionSatisfies("6.1.7", "6.1.7")).toBe(true);
219
259
  expect(isVersionSatisfies("6.1.7", "6.1.7-rc.13")).toBe(true);
@@ -31,33 +31,96 @@ const {
31
31
 
32
32
  const { buildMobileApp } = require("./buildMobile");
33
33
 
34
- async function patchPackages() {
35
- if (existsSync(join(process.cwd(), "quick_brick", "patch_rn.js"))) {
36
- exec(`node ${process.cwd()}/quick_brick/patch_rn.js`);
37
- } else if (
38
- existsSync(join(process.cwd(), "development-app", "patch_rn.js"))
34
+ function hasQuickBrickAppWorkspace(quickBrickProjectPath) {
35
+ const packageJsonPath = join(quickBrickProjectPath, "package.json");
36
+
37
+ if (!existsSync(packageJsonPath)) {
38
+ return false;
39
+ }
40
+
41
+ try {
42
+ const { workspaces } = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
43
+
44
+ const hasWorkspacesConfigured = Boolean(workspaces);
45
+
46
+ const hasQuickBrickAppInstalled = existsSync(
47
+ join(quickBrickProjectPath, "node_modules", "quick-brick-app")
48
+ );
49
+
50
+ return hasWorkspacesConfigured && hasQuickBrickAppInstalled;
51
+ } catch (error) {
52
+ logger.warn(
53
+ "Skipping yarn workspace quick-brick-app patch:rn; unable to read workspace configuration."
54
+ );
55
+
56
+ return false;
57
+ }
58
+ }
59
+
60
+ async function patchPackages(quickBrickProjectPath = process.cwd()) {
61
+ // ./development-app/rn-patches
62
+ const rnPatchesQB = join(
63
+ quickBrickProjectPath,
64
+ join("development-app", "rn-patches")
65
+ );
66
+
67
+ logger.log(
68
+ "Applying patch-package patches from rn-patches to workspace root node_modules"
69
+ );
70
+
71
+ // Verify if the rn-patches directory exists before attempting to run patch-package, fallback to legacy patch_rn.js if it doesn't exist or if the patch-package command fails
72
+ if (
73
+ existsSync(rnPatchesQB) &&
74
+ exec(`yarn patch-package --patch-dir ${rnPatchesQB}`).code !== 0
39
75
  ) {
40
- exec(`node ${process.cwd()}/development-app/patch_rn.js`);
41
- } else if (
42
- existsSync(
76
+ logger.log(
77
+ "patch-package command failed, falling back to legacy patch_rn.js files"
78
+ );
79
+
80
+ // Legacy patching method using patch:rn and patch_rn.js files
81
+ if (hasQuickBrickAppWorkspace(quickBrickProjectPath)) {
82
+ const { code } = exec(
83
+ `cd "${quickBrickProjectPath}" && yarn workspace quick-brick-app patch:rn`
84
+ );
85
+
86
+ if (code === 0) {
87
+ return;
88
+ }
89
+
90
+ logger.log(
91
+ "patch:rn command failed or is unavailable, falling back to legacy patch_rn.js files"
92
+ );
93
+ } else {
94
+ logger.log(
95
+ "Skipping yarn workspace quick-brick-app patch:rn; quick-brick-app workspace not found."
96
+ );
97
+ }
98
+
99
+ const patchPaths = [
100
+ join(quickBrickProjectPath, "quick_brick", "patch_rn.js"),
101
+ join(quickBrickProjectPath, "development-app", "patch_rn.js"),
43
102
  join(
44
- process.cwd(),
103
+ quickBrickProjectPath,
45
104
  "packages",
46
105
  "zapp-react-dom-development-app",
47
106
  "patch_rn.js"
48
- )
49
- )
50
- ) {
51
- const pathToFile = join(
52
- process.cwd(),
53
- "packages",
54
- "zapp-react-dom-development-app",
55
- "patch_rn.js"
56
- );
107
+ ),
108
+ ];
109
+
110
+ let status = false;
57
111
 
58
- exec(`node ${pathToFile}`);
112
+ for (const patchRNPath of patchPaths) {
113
+ if (existsSync(patchRNPath) && exec(`node ${patchRNPath}`).code === 0) {
114
+ status = true;
115
+ break;
116
+ }
117
+ }
118
+
119
+ if (!status) {
120
+ logger.log("no patch_rn.js file found, skipping patching");
121
+ }
59
122
  } else {
60
- logger.log("Cannot patch packages, can't find the patch_rn.js file");
123
+ logger.log("patch-package applied successfully");
61
124
  }
62
125
  }
63
126
 
@@ -82,6 +145,10 @@ const toDayJSLocaleMap = (code) => {
82
145
  tt: null,
83
146
  "es-LA": "es",
84
147
  "en-UK": "en-gb",
148
+ "en-ZA": null,
149
+ "en-NG": null,
150
+ "en-ZW": null,
151
+ "en-ZM": null,
85
152
  };
86
153
 
87
154
  if (map[code] === null) {
@@ -212,7 +279,7 @@ async function appBootstrapper(configuration) {
212
279
  const quickBrickVersion = packageJSON.version;
213
280
  checkAllPluginsSatisfiesQuickBrickVersion({ quickBrickVersion, plugins });
214
281
 
215
- await patchPackages();
282
+ await patchPackages(quickBrickProjectPath);
216
283
 
217
284
  if (buildMobile) {
218
285
  await buildMobileApp(configuration);
@@ -22,9 +22,6 @@ exports[`publish plugin configurator returns the configuration 1`] = `
22
22
  },
23
23
  "pluginPath": "plugins/my-plugin",
24
24
  "skipGit": false,
25
- "targets": [
26
- "tv",
27
- ],
28
25
  "verbose": false,
29
26
  "version": "1.5.0",
30
27
  "yarn": false,
@@ -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
- expect(await configurator(options)).toMatchSnapshot();
105
+ const config = await configurator(options);
106
+
107
+ expect(config).toMatchSnapshot();
107
108
  expect(logger.log.mock.calls).toMatchSnapshot();
108
109
  });
109
110
 
@@ -42,9 +42,19 @@ function clearMocks() {
42
42
  describe("generate manifest", () => {
43
43
  beforeEach(clearMocks);
44
44
 
45
- it("doesn't create the manifest if there is no platform", () => {
45
+ it("throws if an invalid platform is provided", async () => {
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 () => {
46
56
  const configuration = getConfig({ platforms: undefined });
47
- expect(generateManifest(configuration)).resolves.toBe(true);
57
+ await expect(generateManifest(configuration)).resolves.toBe(true);
48
58
  expect(writeJsonToFile).not.toHaveBeenCalled();
49
59
  });
50
60
 
@@ -91,12 +101,11 @@ describe("generate manifest", () => {
91
101
 
92
102
  it("throws if the config file cannot be found", async () => {
93
103
  const configuration = getConfig({ pluginPath: "resolve_error" });
94
-
95
- expect(generateManifest(configuration)).rejects.toMatchSnapshot();
104
+ await expect(generateManifest(configuration)).rejects.toMatchSnapshot();
96
105
  });
97
106
 
98
107
  it("throws if the manifests cannot be written", async () => {
99
108
  const configuration = getConfig({ pluginPath: "write_error" });
100
- expect(generateManifest(configuration)).rejects.toMatchSnapshot();
109
+ await expect(generateManifest(configuration)).rejects.toMatchSnapshot();
101
110
  });
102
111
  });
@@ -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,4 +1,3 @@
1
- const R = require("ramda");
2
1
  const { resolve } = require("path");
3
2
  const { inspect } = require("util");
4
3
 
@@ -27,10 +26,9 @@ function renderManifest({
27
26
  pluginPath,
28
27
  version,
29
28
  dryRun,
30
- targets,
31
29
  }) {
32
30
  return async function (platform) {
33
- const manifest = manifestConfig({ platform, version, targets });
31
+ const manifest = manifestConfig({ platform, version });
34
32
 
35
33
  const enrichedManifest = enrichManifest({ manifest, packageJson });
36
34
 
@@ -49,15 +47,34 @@ function renderManifest({
49
47
  };
50
48
  }
51
49
 
50
+ const validPlatforms = [
51
+ "lg_tv",
52
+ "samsung_tv",
53
+ "vizio",
54
+ "android_tv_for_quickbrick",
55
+ "amazon_fire_tv_for_quickbrick",
56
+ "tvos_for_quickbrick",
57
+ "android_for_quickbrick",
58
+ "ios_for_quickbrick",
59
+ "ios",
60
+ "android",
61
+ ];
62
+
52
63
  async function generateManifest(configuration) {
53
- const { pluginPath, platforms, version, dryRun, targets } = configuration;
64
+ const { pluginPath, platforms, version, dryRun } = configuration;
54
65
 
55
66
  if (!platforms) {
56
- logger.log("Manifest does not exsist, Skipping generation");
67
+ logger.log("Manifest does not exist, Skipping generation");
57
68
 
58
69
  return true;
59
70
  }
60
71
 
72
+ if (!platforms.every((platform) => validPlatforms.includes(platform))) {
73
+ throw new Error(
74
+ `Invalid platform provided. Valid platforms are: ${validPlatforms.join(", ")}`
75
+ );
76
+ }
77
+
61
78
  try {
62
79
  const manifestConfig = require(
63
80
  resolve(pluginPath, "manifests/manifest.config.js")
@@ -71,10 +88,9 @@ async function generateManifest(configuration) {
71
88
  packageJson,
72
89
  version,
73
90
  dryRun,
74
- targets,
75
91
  });
76
92
 
77
- return Promise.all(R.map(manifestRenderer, platforms));
93
+ return Promise.all(platforms.map(manifestRenderer));
78
94
  } catch (e) {
79
95
  throw new Error(
80
96
  "An error occured when generating the manifest: " + e.message
@@ -37,7 +37,7 @@ async function zappifestPublish(configuration) {
37
37
  }
38
38
 
39
39
  if (!platforms || !zappOwnerAccountId) {
40
- logger.log("Manifest does not exsist, Skipping publishing");
40
+ logger.log("Manifest does not exist, Skipping publishing");
41
41
 
42
42
  return true;
43
43
  }
@@ -13,6 +13,19 @@ exports[`copyFiles when destination path has no package.json doesn't skips the c
13
13
  ]
14
14
  `;
15
15
 
16
+ exports[`copyFiles when there is no package.json to copy copies the dir 1`] = `
17
+ [
18
+ [
19
+ "some/source/path/files/file1.txt",
20
+ "some/destination/Path/files/file1.txt",
21
+ ],
22
+ [
23
+ "some/source/path/files/file2.txt",
24
+ "some/destination/Path/files/file2.txt",
25
+ ],
26
+ ]
27
+ `;
28
+
16
29
  exports[`copyFiles when there is no package.json to copy copies the files 1`] = `
17
30
  [
18
31
  [
@@ -39,6 +39,7 @@ describe("copyFiles", () => {
39
39
  fs.writeFile("bar.json", { bar: "baz" }, jest.fn());
40
40
  fs.writeFile("qux.json", { qux: 42 }, jest.fn());
41
41
  fs.copyFileSync.mockClear();
42
+ fs.readdir.mockClear();
42
43
  });
43
44
 
44
45
  describe("when there is no package.json to copy", () => {
@@ -47,6 +48,21 @@ describe("copyFiles", () => {
47
48
  expect(fs.copyFileSync).toHaveBeenCalledTimes(2);
48
49
  expect(fs.copyFileSync.mock.calls).toMatchSnapshot();
49
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
+ const results = copyFiles(sourcePath, ["files/"], destinationPath);
59
+
60
+ // Wait for the promise to resolve (the directory copy operation)
61
+ await Promise.all(results);
62
+
63
+ expect(fs.copyFileSync).toHaveBeenCalledTimes(2);
64
+ expect(fs.copyFileSync.mock.calls).toMatchSnapshot();
65
+ });
50
66
  });
51
67
 
52
68
  describe("when destination path has package.json", () => {
package/src/file/index.js CHANGED
@@ -5,7 +5,17 @@ const R = require("ramda");
5
5
  * @module @applicaster/zapplicaster-cli/util/file
6
6
  */
7
7
 
8
- const { writeFile, readFile, readdir, copyFile, copyFileSync } = require("fs");
8
+ const {
9
+ writeFile,
10
+ readFile,
11
+ readdir,
12
+ copyFile,
13
+ copyFileSync,
14
+ lstatSync,
15
+ mkdirSync,
16
+ existsSync,
17
+ } = require("fs");
18
+
9
19
  const { promisify } = require("util");
10
20
  const { join } = require("path");
11
21
 
@@ -72,14 +82,20 @@ function copyFiles(source, filesOrFilesGetter, destination, config) {
72
82
  ? filesOrFilesGetter(config)
73
83
  : filesOrFilesGetter;
74
84
 
75
- return R.map(
76
- (file) =>
77
- copyFileSync(
78
- join(source, file),
79
- destinationFileNameMapper(join(destination, file))
80
- ),
81
- files
82
- );
85
+ return R.map((file) => {
86
+ const sourcePath = join(source, file);
87
+ const destinationPath = destinationFileNameMapper(join(destination, file));
88
+
89
+ if (lstatSync(sourcePath).isDirectory()) {
90
+ if (!existsSync(destinationPath)) {
91
+ mkdirSync(destinationPath, { recursive: true });
92
+ }
93
+
94
+ return copyFolder(sourcePath, destinationPath);
95
+ }
96
+
97
+ return copyFileSync(sourcePath, destinationPath);
98
+ }, files);
83
99
  }
84
100
 
85
101
  module.exports = {
@@ -2,10 +2,18 @@ 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 {};
7
+ }
8
+
5
9
  function readdirSync(folder) {
6
10
  return _fs.readdirSync(folder);
7
11
  }
8
12
 
13
+ async function readdirAsync(folder) {
14
+ return Promise.resolve(_fs.readdirSync(folder));
15
+ }
16
+
9
17
  function readdir(folder, callback) {
10
18
  const files = R.map(R.prop("fileName"), fs.__writenFiles);
11
19
 
@@ -77,10 +85,17 @@ function __resetFiles() {
77
85
  fs.__writenFiles = [];
78
86
  }
79
87
 
88
+ fs.lstatSync = (_path) => ({
89
+ isDirectory: () => _path.endsWith("/"),
90
+ isFile: () => _path.endsWith("/") === false,
91
+ });
92
+
80
93
  fs.__writenFiles = [];
81
94
  fs.__resetFiles = __resetFiles;
82
95
  fs.__addMockedFiles = __addMockedFiles;
83
96
  fs.readdirSync = readdirSync;
97
+ fs.readdirAsync = readdirAsync;
98
+ fs.mkdirSync = mkdirSync;
84
99
  fs.readdir = jest.fn(readdir);
85
100
  fs.writeFile = jest.fn(writeFile);
86
101
  fs.readFile = jest.fn(readFile);