@cloudcommerce/cli 0.37.1 → 0.39.0

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.37.0 build /home/leo/code/ecomplus/cloud-commerce/packages/cli
2
+ > @cloudcommerce/cli@0.38.0 build /home/leo/code/ecomplus/cloud-commerce/packages/cli
3
3
  > bash ../../scripts/build-lib.sh
4
4
 
@@ -1,8 +1,11 @@
1
1
  rules_version = '2';
2
2
  service cloud.firestore {
3
3
  match /databases/{database}/documents {
4
+ match /forms/p/{form}/{document=*} {
5
+ allow create;
6
+ }
4
7
  match /{document=**} {
5
8
  allow read, write: if false;
6
9
  }
7
10
  }
8
- }
11
+ }
package/lib/cli.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { fileURLToPath } from 'node:url';
2
- import path from 'node:path';
2
+ import { join as joinPath } from 'node:path';
3
3
  import {
4
4
  $, argv, fs, echo, chalk,
5
5
  } from 'zx';
6
+ import Deepmerge from '@fastify/deepmerge';
6
7
  import login from './login.js';
7
8
  import build, { prepareCodebases } from './build.js';
8
9
  import { siginGcloudAndSetIAM, createServiceAccountKey } from './setup-gcloud.js';
@@ -15,13 +16,13 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url));
15
16
  const pwd = process.cwd();
16
17
  let projectId = FIREBASE_PROJECT_ID;
17
18
  if (projectId) {
18
- if (!fs.existsSync(path.join(pwd, '.firebaserc'))) {
19
- fs.writeFileSync(path.join(pwd, '.firebaserc'), JSON.stringify({ projects: { default: projectId } }, null, 2));
19
+ if (!fs.existsSync(joinPath(pwd, '.firebaserc'))) {
20
+ fs.writeFileSync(joinPath(pwd, '.firebaserc'), JSON.stringify({ projects: { default: projectId } }, null, 2));
20
21
  }
21
22
  } else {
22
23
  if (GOOGLE_APPLICATION_CREDENTIALS) {
23
24
  try {
24
- const gac = fs.readJSONSync(path.join(pwd, GOOGLE_APPLICATION_CREDENTIALS));
25
+ const gac = fs.readJSONSync(joinPath(pwd, GOOGLE_APPLICATION_CREDENTIALS));
25
26
  projectId = gac.project_id;
26
27
  } catch (e) {
27
28
  //
@@ -29,7 +30,7 @@ if (projectId) {
29
30
  }
30
31
  if (!projectId) {
31
32
  try {
32
- const firebaserc = fs.readJSONSync(path.join(pwd, '.firebaserc'));
33
+ const firebaserc = fs.readJSONSync(joinPath(pwd, '.firebaserc'));
33
34
  projectId = firebaserc.projects.default;
34
35
  } catch (e) {
35
36
  projectId = 'ecom2-demo';
@@ -38,7 +39,27 @@ if (projectId) {
38
39
  }
39
40
 
40
41
  export default async () => {
41
- await fs.copy(path.join(__dirname, '..', 'config'), pwd);
42
+ const baseConfigDir = joinPath(__dirname, '..', 'config');
43
+ await fs.copy(baseConfigDir, pwd);
44
+ const userConfigDir = joinPath(pwd, 'conf');
45
+ if (fs.existsSync(userConfigDir) && fs.lstatSync(userConfigDir).isDirectory()) {
46
+ await fs.copy(userConfigDir, pwd);
47
+ const userFirebaseJsonPath = joinPath(userConfigDir, 'firebase.json');
48
+ if (fs.existsSync(userFirebaseJsonPath)) {
49
+ let userFirebaseConfig;
50
+ try {
51
+ userFirebaseConfig = JSON.parse(fs.readFileSync(userFirebaseJsonPath, 'utf8'));
52
+ } catch {
53
+ //
54
+ }
55
+ if (userFirebaseConfig) {
56
+ const deepmerge = Deepmerge();
57
+ const baseFirebaseConfig = JSON.parse(fs.readFileSync(joinPath(baseConfigDir, 'firebase.json'), 'utf8'));
58
+ const mergedConfig = deepmerge(baseFirebaseConfig, userFirebaseConfig);
59
+ fs.writeFileSync(joinPath(pwd, 'firebase.json'), JSON.stringify(mergedConfig, null, 2));
60
+ }
61
+ }
62
+ }
42
63
  const options = [];
43
64
  Object.keys(argv).forEach((key) => {
44
65
  if (key !== '_' && argv[key] !== false) {
@@ -86,7 +107,7 @@ ${chalk.bold('npx kill-port 4000 9099 5001 8080 5000 8085 9199 4400 4500')}
86
107
  }
87
108
  if (argv._.includes('setup')) {
88
109
  const { storeId, authenticationId, apiKey } = await login();
89
- await fs.writeFile(path.join(pwd, 'functions', '.env'), `ECOM_AUTHENTICATION_ID=${authenticationId}
110
+ await fs.writeFile(joinPath(pwd, 'functions', '.env'), `ECOM_AUTHENTICATION_ID=${authenticationId}
90
111
  ECOM_API_KEY=${apiKey}
91
112
  ECOM_STORE_ID=${storeId}
92
113
  `);
@@ -94,7 +115,7 @@ ECOM_STORE_ID=${storeId}
94
115
  await $firebase('deploy');
95
116
  }
96
117
  if (argv.commit !== false) {
97
- await fs.writeFile(path.join(pwd, 'functions', 'config.json'), JSON.stringify({ storeId }, null, 2));
118
+ await fs.writeFile(joinPath(pwd, 'functions', 'config.json'), JSON.stringify({ storeId }, null, 2));
98
119
  await build(argv.codebase);
99
120
  try {
100
121
  await $`git add .firebaserc functions/config.json`;
@@ -150,7 +171,7 @@ Finish by saving the following secrets to your GitHub repository:
150
171
  }
151
172
  if (argv._.includes('dev') || !argv._.length) {
152
173
  await prepareCodebases(true);
153
- const prefix = path.join(pwd, 'functions/ssr');
174
+ const prefix = joinPath(pwd, 'functions/ssr');
154
175
  // https://docs.astro.build/en/reference/cli-reference/#astro-dev
155
176
  const host = typeof argv.host === 'string' ? argv.host : '';
156
177
  const port = typeof argv.port === 'string' || typeof argv.port === 'number' ? argv.port : '';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/cli",
3
3
  "type": "module",
4
- "version": "0.37.1",
4
+ "version": "0.39.0",
5
5
  "description": "E-Com Plus Cloud Commerce CLI tools",
6
6
  "bin": {
7
7
  "cloudcommerce": "./bin/run.mjs"
@@ -23,11 +23,12 @@
23
23
  },
24
24
  "homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/cli#readme",
25
25
  "dependencies": {
26
+ "@fastify/deepmerge": "^1.3.0",
26
27
  "libsodium-wrappers": "^0.7.13",
27
28
  "md5": "^2.3.0",
28
29
  "typescript": "~5.2.2",
29
30
  "zx": "^7.2.3",
30
- "@cloudcommerce/api": "0.37.1"
31
+ "@cloudcommerce/api": "0.39.0"
31
32
  },
32
33
  "scripts": {
33
34
  "build": "bash ../../scripts/build-lib.sh"
package/src/cli.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { fileURLToPath } from 'node:url';
2
- import path from 'node:path';
2
+ import { join as joinPath } from 'node:path';
3
3
  import {
4
4
  $,
5
5
  argv,
@@ -7,6 +7,7 @@ import {
7
7
  echo,
8
8
  chalk,
9
9
  } from 'zx';
10
+ import Deepmerge from '@fastify/deepmerge';
10
11
  import login from './login';
11
12
  import build, { prepareCodebases } from './build';
12
13
  import { siginGcloudAndSetIAM, createServiceAccountKey } from './setup-gcloud';
@@ -26,16 +27,16 @@ const pwd = process.cwd();
26
27
 
27
28
  let projectId = FIREBASE_PROJECT_ID;
28
29
  if (projectId) {
29
- if (!fs.existsSync(path.join(pwd, '.firebaserc'))) {
30
+ if (!fs.existsSync(joinPath(pwd, '.firebaserc'))) {
30
31
  fs.writeFileSync(
31
- path.join(pwd, '.firebaserc'),
32
+ joinPath(pwd, '.firebaserc'),
32
33
  JSON.stringify({ projects: { default: projectId } }, null, 2),
33
34
  );
34
35
  }
35
36
  } else {
36
37
  if (GOOGLE_APPLICATION_CREDENTIALS) {
37
38
  try {
38
- const gac = fs.readJSONSync(path.join(pwd, GOOGLE_APPLICATION_CREDENTIALS));
39
+ const gac = fs.readJSONSync(joinPath(pwd, GOOGLE_APPLICATION_CREDENTIALS));
39
40
  projectId = gac.project_id;
40
41
  } catch (e) {
41
42
  //
@@ -43,7 +44,7 @@ if (projectId) {
43
44
  }
44
45
  if (!projectId) {
45
46
  try {
46
- const firebaserc = fs.readJSONSync(path.join(pwd, '.firebaserc'));
47
+ const firebaserc = fs.readJSONSync(joinPath(pwd, '.firebaserc'));
47
48
  projectId = firebaserc.projects.default;
48
49
  } catch (e) {
49
50
  projectId = 'ecom2-demo';
@@ -52,7 +53,34 @@ if (projectId) {
52
53
  }
53
54
 
54
55
  export default async () => {
55
- await fs.copy(path.join(__dirname, '..', 'config'), pwd);
56
+ const baseConfigDir = joinPath(__dirname, '..', 'config');
57
+ await fs.copy(baseConfigDir, pwd);
58
+ const userConfigDir = joinPath(pwd, 'conf');
59
+ if (fs.existsSync(userConfigDir) && fs.lstatSync(userConfigDir).isDirectory()) {
60
+ await fs.copy(userConfigDir, pwd);
61
+ const userFirebaseJsonPath = joinPath(userConfigDir, 'firebase.json');
62
+ if (fs.existsSync(userFirebaseJsonPath)) {
63
+ let userFirebaseConfig: Record<string, any> | undefined;
64
+ try {
65
+ userFirebaseConfig = JSON.parse(
66
+ fs.readFileSync(userFirebaseJsonPath, 'utf8'),
67
+ );
68
+ } catch {
69
+ //
70
+ }
71
+ if (userFirebaseConfig) {
72
+ const deepmerge = Deepmerge();
73
+ const baseFirebaseConfig = JSON.parse(
74
+ fs.readFileSync(joinPath(baseConfigDir, 'firebase.json'), 'utf8'),
75
+ );
76
+ const mergedConfig = deepmerge(baseFirebaseConfig, userFirebaseConfig);
77
+ fs.writeFileSync(
78
+ joinPath(pwd, 'firebase.json'),
79
+ JSON.stringify(mergedConfig, null, 2),
80
+ );
81
+ }
82
+ }
83
+ }
56
84
 
57
85
  const options: string[] = [];
58
86
  Object.keys(argv).forEach((key) => {
@@ -105,7 +133,7 @@ ${chalk.bold('npx kill-port 4000 9099 5001 8080 5000 8085 9199 4400 4500')}
105
133
  if (argv._.includes('setup')) {
106
134
  const { storeId, authenticationId, apiKey } = await login();
107
135
  await fs.writeFile(
108
- path.join(pwd, 'functions', '.env'),
136
+ joinPath(pwd, 'functions', '.env'),
109
137
  `ECOM_AUTHENTICATION_ID=${authenticationId}
110
138
  ECOM_API_KEY=${apiKey}
111
139
  ECOM_STORE_ID=${storeId}
@@ -117,7 +145,7 @@ ECOM_STORE_ID=${storeId}
117
145
  }
118
146
  if (argv.commit !== false) {
119
147
  await fs.writeFile(
120
- path.join(pwd, 'functions', 'config.json'),
148
+ joinPath(pwd, 'functions', 'config.json'),
121
149
  JSON.stringify({ storeId }, null, 2),
122
150
  );
123
151
 
@@ -184,7 +212,7 @@ Finish by saving the following secrets to your GitHub repository:
184
212
 
185
213
  if (argv._.includes('dev') || !argv._.length) {
186
214
  await prepareCodebases(true);
187
- const prefix = path.join(pwd, 'functions/ssr');
215
+ const prefix = joinPath(pwd, 'functions/ssr');
188
216
  // https://docs.astro.build/en/reference/cli-reference/#astro-dev
189
217
  const host = typeof argv.host === 'string' ? argv.host : '';
190
218
  const port = typeof argv.port === 'string' || typeof argv.port === 'number' ? argv.port : '';