@cloudcommerce/cli 0.0.23 → 0.0.24
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/.turbo/turbo-build.log +5 -5
- package/lib/index.js +27 -1
- package/package.json +1 -1
- package/src/index.ts +35 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
[
|
|
2
|
-
[
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[
|
|
1
|
+
[32m@cloudcommerce/cli:build[0m: cache hit, replaying output [2mf832de01e0f20333[0m
|
|
2
|
+
[32m@cloudcommerce/cli:build: [0m
|
|
3
|
+
[32m@cloudcommerce/cli:build: [0m> @cloudcommerce/cli@0.0.23 build /home/leo/code/ecomplus/cloud-commerce/packages/cli
|
|
4
|
+
[32m@cloudcommerce/cli:build: [0m> sh ../../scripts/build-lib.sh
|
|
5
|
+
[32m@cloudcommerce/cli:build: [0m
|
package/lib/index.js
CHANGED
|
@@ -2,8 +2,32 @@ import url from 'url';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { $, argv, fs } from 'zx';
|
|
4
4
|
|
|
5
|
+
const { FIREBASE_PROJECT_ID, GOOGLE_APPLICATION_CREDENTIALS } = process.env;
|
|
5
6
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
6
7
|
const pwd = process.cwd();
|
|
8
|
+
let projectId = FIREBASE_PROJECT_ID;
|
|
9
|
+
if (projectId) {
|
|
10
|
+
if (!fs.existsSync(path.join(pwd, '.firebaserc'))) {
|
|
11
|
+
fs.writeFileSync(path.join(pwd, '.firebaserc'), JSON.stringify({ projects: { default: projectId } }, null, 2));
|
|
12
|
+
}
|
|
13
|
+
} else {
|
|
14
|
+
if (GOOGLE_APPLICATION_CREDENTIALS) {
|
|
15
|
+
try {
|
|
16
|
+
const gac = fs.readJSONSync(path.join(pwd, GOOGLE_APPLICATION_CREDENTIALS));
|
|
17
|
+
projectId = gac.project_id;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
//
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (!projectId) {
|
|
23
|
+
try {
|
|
24
|
+
const firebaserc = fs.readJSONSync(path.join(pwd, '.firebaserc'));
|
|
25
|
+
projectId = firebaserc.projects.default;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
projectId = 'ecom2-hello';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
7
31
|
|
|
8
32
|
export default async () => {
|
|
9
33
|
fs.copySync(path.join(__dirname, '..', 'config'), pwd);
|
|
@@ -14,7 +38,9 @@ export default async () => {
|
|
|
14
38
|
}
|
|
15
39
|
return opts;
|
|
16
40
|
}, '');
|
|
17
|
-
const $firebase = async (cmd) =>
|
|
41
|
+
const $firebase = async (cmd) => {
|
|
42
|
+
return $`firebase --project=${projectId} ${cmd}${options}`;
|
|
43
|
+
};
|
|
18
44
|
if (argv._.includes('serve')) {
|
|
19
45
|
return $firebase('emulators:start');
|
|
20
46
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,9 +2,41 @@ import url from 'url';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { $, argv, fs } from 'zx';
|
|
4
4
|
|
|
5
|
+
const {
|
|
6
|
+
FIREBASE_PROJECT_ID,
|
|
7
|
+
GOOGLE_APPLICATION_CREDENTIALS,
|
|
8
|
+
} = process.env;
|
|
9
|
+
|
|
5
10
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
6
11
|
const pwd = process.cwd();
|
|
7
12
|
|
|
13
|
+
let projectId = FIREBASE_PROJECT_ID;
|
|
14
|
+
if (projectId) {
|
|
15
|
+
if (!fs.existsSync(path.join(pwd, '.firebaserc'))) {
|
|
16
|
+
fs.writeFileSync(
|
|
17
|
+
path.join(pwd, '.firebaserc'),
|
|
18
|
+
JSON.stringify({ projects: { default: projectId } }, null, 2),
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
if (GOOGLE_APPLICATION_CREDENTIALS) {
|
|
23
|
+
try {
|
|
24
|
+
const gac = fs.readJSONSync(path.join(pwd, GOOGLE_APPLICATION_CREDENTIALS));
|
|
25
|
+
projectId = gac.project_id;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
//
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!projectId) {
|
|
31
|
+
try {
|
|
32
|
+
const firebaserc = fs.readJSONSync(path.join(pwd, '.firebaserc'));
|
|
33
|
+
projectId = firebaserc.projects.default;
|
|
34
|
+
} catch (e) {
|
|
35
|
+
projectId = 'ecom2-hello';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
8
40
|
export default async () => {
|
|
9
41
|
fs.copySync(path.join(__dirname, '..', 'config'), pwd);
|
|
10
42
|
|
|
@@ -15,7 +47,9 @@ export default async () => {
|
|
|
15
47
|
}
|
|
16
48
|
return opts;
|
|
17
49
|
}, '');
|
|
18
|
-
const $firebase = async (cmd: string) =>
|
|
50
|
+
const $firebase = async (cmd: string) => {
|
|
51
|
+
return $`firebase --project=${projectId} ${cmd}${options}`;
|
|
52
|
+
};
|
|
19
53
|
|
|
20
54
|
if (argv._.includes('serve')) {
|
|
21
55
|
return $firebase('emulators:start');
|