@cloudcommerce/cli 0.22.0 → 0.22.2

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @cloudcommerce/cli@0.21.0 build /home/leo/code/ecomplus/cloud-commerce/packages/cli
2
+ > @cloudcommerce/cli@0.22.1 build /home/leo/code/ecomplus/cloud-commerce/packages/cli
3
3
  > bash ../../scripts/build-lib.sh
4
4
 
package/lib/build.js CHANGED
@@ -1,22 +1,33 @@
1
1
  import { join as joinPath } from 'node:path';
2
2
  import { $, fs } from 'zx';
3
3
 
4
- const copyFunctionsConfig = async () => {
4
+ const copyFunctionsConfig = async (isDev = false) => {
5
5
  const functionsDir = joinPath(process.cwd(), 'functions');
6
+ if (isDev && !fs.existsSync(joinPath(functionsDir, '.env'))) {
7
+ try {
8
+ const { storeId } = JSON.parse(fs.readFileSync(joinPath(functionsDir, 'config.json'), 'utf8'));
9
+ await fs.writeFile(joinPath(functionsDir, '.env'), `ECOM_STORE_ID=${storeId}\n`);
10
+ } catch {
11
+ //
12
+ }
13
+ }
6
14
  const filesToCopy = ['.env', 'config.json', 'ssr/content/settings.json'];
7
15
  const dirents = await fs.readdir(functionsDir, { withFileTypes: true });
16
+ /* eslint-disable no-await-in-loop */
8
17
  for (let i = 0; i < dirents.length; i++) {
9
18
  if (dirents[i].isDirectory() && dirents[i].name.charAt(0) !== '.') {
10
19
  const codebase = dirents[i].name;
11
20
  const codebaseDir = joinPath(functionsDir, codebase);
12
- // eslint-disable-next-line no-await-in-loop
21
+ const isSSR = codebase === 'ssr';
13
22
  await fs.ensureDir(joinPath(codebaseDir, 'content'));
23
+ if (isDev && isSSR && !fs.existsSync(joinPath(functionsDir, 'node_modules'))) {
24
+ await $`npm --prefix "functions/ssr" i`;
25
+ }
14
26
  for (let ii = 0; ii < filesToCopy.length; ii++) {
15
27
  const fileToCopy = filesToCopy[ii];
16
- if (codebase !== 'ssr' || !fileToCopy.includes('ssr/')) {
28
+ if (!isSSR || !fileToCopy.includes('ssr/')) {
17
29
  const srcPath = joinPath(functionsDir, fileToCopy);
18
30
  if (fs.existsSync(srcPath) && srcPath) {
19
- // eslint-disable-next-line no-await-in-loop
20
31
  await fs.copy(srcPath, joinPath(codebaseDir, fileToCopy.replace('ssr/', '')));
21
32
  }
22
33
  }
package/lib/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- import url from 'node:url';
1
+ import { fileURLToPath } from 'node:url';
2
2
  import path from 'node:path';
3
3
  import {
4
4
  $, argv, fs, echo, chalk,
@@ -11,7 +11,7 @@ import createGhSecrets from './setup-gh.js';
11
11
  const { FIREBASE_PROJECT_ID, GOOGLE_APPLICATION_CREDENTIALS, GITHUB_TOKEN } = process.env;
12
12
  // https://github.com/google/zx/issues/124
13
13
  process.env.FORCE_COLOR = '3';
14
- const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
14
+ const __dirname = fileURLToPath(new URL('.', import.meta.url));
15
15
  const pwd = process.cwd();
16
16
  let projectId = FIREBASE_PROJECT_ID;
17
17
  if (projectId) {
@@ -146,7 +146,7 @@ Finish by saving the following secrets to your GitHub repository:
146
146
  `;
147
147
  }
148
148
  if (argv._.includes('dev') || !argv._.length) {
149
- await prepareCodebases();
149
+ await prepareCodebases(true);
150
150
  return $`npm --prefix "${path.join(pwd, 'functions/ssr')}" run dev`;
151
151
  }
152
152
  return $`echo 'Hello from @cloudcommerce/cli'`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/cli",
3
3
  "type": "module",
4
- "version": "0.22.0",
4
+ "version": "0.22.2",
5
5
  "description": "E-Com Plus Cloud Commerce CLI tools",
6
6
  "bin": {
7
7
  "cloudcommerce": "./bin/run.mjs"
@@ -26,7 +26,7 @@
26
26
  "libsodium-wrappers": "^0.7.11",
27
27
  "md5": "^2.3.0",
28
28
  "zx": "^7.2.3",
29
- "@cloudcommerce/api": "0.22.0"
29
+ "@cloudcommerce/api": "0.22.2"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "bash ../../scripts/build-lib.sh"
package/src/build.ts CHANGED
@@ -1,22 +1,35 @@
1
1
  import { join as joinPath } from 'node:path';
2
2
  import { $, fs } from 'zx';
3
3
 
4
- const copyFunctionsConfig = async () => {
4
+ const copyFunctionsConfig = async (isDev = false) => {
5
5
  const functionsDir = joinPath(process.cwd(), 'functions');
6
+ if (isDev && !fs.existsSync(joinPath(functionsDir, '.env'))) {
7
+ try {
8
+ const { storeId } = JSON.parse(
9
+ fs.readFileSync(joinPath(functionsDir, 'config.json'), 'utf8'),
10
+ );
11
+ await fs.writeFile(joinPath(functionsDir, '.env'), `ECOM_STORE_ID=${storeId}\n`);
12
+ } catch {
13
+ //
14
+ }
15
+ }
6
16
  const filesToCopy = ['.env', 'config.json', 'ssr/content/settings.json'];
7
17
  const dirents = await fs.readdir(functionsDir, { withFileTypes: true });
18
+ /* eslint-disable no-await-in-loop */
8
19
  for (let i = 0; i < dirents.length; i++) {
9
20
  if (dirents[i].isDirectory() && dirents[i].name.charAt(0) !== '.') {
10
21
  const codebase = dirents[i].name;
11
22
  const codebaseDir = joinPath(functionsDir, codebase);
12
- // eslint-disable-next-line no-await-in-loop
23
+ const isSSR = codebase === 'ssr';
13
24
  await fs.ensureDir(joinPath(codebaseDir, 'content'));
25
+ if (isDev && isSSR && !fs.existsSync(joinPath(functionsDir, 'node_modules'))) {
26
+ await $`npm --prefix "functions/ssr" i`;
27
+ }
14
28
  for (let ii = 0; ii < filesToCopy.length; ii++) {
15
29
  const fileToCopy = filesToCopy[ii];
16
- if (codebase !== 'ssr' || !fileToCopy.includes('ssr/')) {
30
+ if (!isSSR || !fileToCopy.includes('ssr/')) {
17
31
  const srcPath = joinPath(functionsDir, fileToCopy);
18
32
  if (fs.existsSync(srcPath) && srcPath) {
19
- // eslint-disable-next-line no-await-in-loop
20
33
  await fs.copy(
21
34
  srcPath,
22
35
  joinPath(codebaseDir, fileToCopy.replace('ssr/', '')),
package/src/cli.ts CHANGED
@@ -1,4 +1,4 @@
1
- import url from 'node:url';
1
+ import { fileURLToPath } from 'node:url';
2
2
  import path from 'node:path';
3
3
  import {
4
4
  $,
@@ -21,7 +21,7 @@ const {
21
21
  // https://github.com/google/zx/issues/124
22
22
  process.env.FORCE_COLOR = '3';
23
23
 
24
- const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
24
+ const __dirname = fileURLToPath(new URL('.', import.meta.url));
25
25
  const pwd = process.cwd();
26
26
 
27
27
  let projectId = FIREBASE_PROJECT_ID;
@@ -179,7 +179,7 @@ Finish by saving the following secrets to your GitHub repository:
179
179
  }
180
180
 
181
181
  if (argv._.includes('dev') || !argv._.length) {
182
- await prepareCodebases();
182
+ await prepareCodebases(true);
183
183
  return $`npm --prefix "${path.join(pwd, 'functions/ssr')}" run dev`;
184
184
  }
185
185
  return $`echo 'Hello from @cloudcommerce/cli'`;