@globio/cli 0.0.1 → 0.1.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.
- package/.github/workflows/publish.yml +41 -0
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/index.js +602 -1
- package/jsr.json +6 -0
- package/package.json +28 -2
- package/src/auth/login.ts +65 -0
- package/src/auth/logout.ts +8 -0
- package/src/auth/whoami.ts +15 -0
- package/src/commands/functions.ts +191 -0
- package/src/commands/init.ts +65 -0
- package/src/commands/migrate.ts +179 -0
- package/src/commands/projects.ts +16 -0
- package/src/commands/services.ts +27 -0
- package/src/index.ts +90 -0
- package/src/lib/config.ts +47 -0
- package/src/lib/firebase.ts +19 -0
- package/src/lib/progress.ts +17 -0
- package/src/lib/sdk.ts +13 -0
- package/src/prompts/init.ts +38 -0
- package/src/prompts/migrate.ts +8 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import Conf from 'conf';
|
|
3
|
+
|
|
4
|
+
interface GlobioConfig {
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
projectId?: string;
|
|
7
|
+
projectName?: string;
|
|
8
|
+
email?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const store = new Conf<GlobioConfig>({
|
|
12
|
+
projectName: 'globio',
|
|
13
|
+
defaults: {},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const config = {
|
|
17
|
+
get: (): GlobioConfig => store.store,
|
|
18
|
+
set: (values: Partial<GlobioConfig>) => {
|
|
19
|
+
Object.entries(values).forEach(([key, value]) => {
|
|
20
|
+
if (value !== undefined) {
|
|
21
|
+
store.set(key as keyof GlobioConfig, value);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
clear: () => store.clear(),
|
|
26
|
+
getApiKey: () => store.get('apiKey'),
|
|
27
|
+
requireAuth: () => {
|
|
28
|
+
const key = store.get('apiKey');
|
|
29
|
+
if (!key) {
|
|
30
|
+
console.error(chalk.red('Not logged in. Run: npx @globio/cli login'));
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
return key;
|
|
34
|
+
},
|
|
35
|
+
requireProject: () => {
|
|
36
|
+
const projectId = store.get('projectId');
|
|
37
|
+
if (!projectId) {
|
|
38
|
+
console.error(
|
|
39
|
+
chalk.red('No active project. Run: npx @globio/cli projects use <projectId>')
|
|
40
|
+
);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
return projectId;
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type { GlobioConfig };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export async function initFirebase(serviceAccountPath: string) {
|
|
2
|
+
const admin = await import('firebase-admin');
|
|
3
|
+
const { readFileSync } = await import('fs');
|
|
4
|
+
|
|
5
|
+
const serviceAccount = JSON.parse(readFileSync(serviceAccountPath, 'utf-8'));
|
|
6
|
+
|
|
7
|
+
if (!admin.default.apps.length) {
|
|
8
|
+
admin.default.initializeApp({
|
|
9
|
+
credential: admin.default.credential.cert(serviceAccount),
|
|
10
|
+
storageBucket: serviceAccount.project_id + '.appspot.com',
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
firestore: admin.default.firestore(),
|
|
16
|
+
storage: admin.default.storage(),
|
|
17
|
+
app: admin.default.app(),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import cliProgress from 'cli-progress';
|
|
3
|
+
|
|
4
|
+
export function createProgressBar(label: string) {
|
|
5
|
+
const bar = new cliProgress.SingleBar(
|
|
6
|
+
{
|
|
7
|
+
format:
|
|
8
|
+
chalk.cyan(label) +
|
|
9
|
+
' [{bar}] {percentage}% | {value}/{total}',
|
|
10
|
+
barCompleteChar: '█',
|
|
11
|
+
barIncompleteChar: '░',
|
|
12
|
+
hideCursor: true,
|
|
13
|
+
},
|
|
14
|
+
cliProgress.Presets.shades_classic
|
|
15
|
+
);
|
|
16
|
+
return bar;
|
|
17
|
+
}
|
package/src/lib/sdk.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Globio } from '@globio/sdk';
|
|
2
|
+
import { config } from './config.js';
|
|
3
|
+
|
|
4
|
+
export function getClient(): Globio {
|
|
5
|
+
const apiKey = config.requireAuth();
|
|
6
|
+
config.requireProject();
|
|
7
|
+
return new Globio({ apiKey });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function getClientWithKey(apiKey: string, projectId: string): Globio {
|
|
11
|
+
void projectId;
|
|
12
|
+
return new Globio({ apiKey });
|
|
13
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as p from '@clack/prompts';
|
|
2
|
+
|
|
3
|
+
export async function promptInit() {
|
|
4
|
+
return p.group(
|
|
5
|
+
{
|
|
6
|
+
apiKey: () =>
|
|
7
|
+
p.text({
|
|
8
|
+
message: 'Globio API key',
|
|
9
|
+
placeholder: 'gk_live_...',
|
|
10
|
+
validate: (value) => (!value ? 'Required' : undefined),
|
|
11
|
+
}),
|
|
12
|
+
projectId: () =>
|
|
13
|
+
p.text({
|
|
14
|
+
message: 'Project ID',
|
|
15
|
+
placeholder: 'proj_...',
|
|
16
|
+
validate: (value) => (!value ? 'Required' : undefined),
|
|
17
|
+
}),
|
|
18
|
+
migrateFromFirebase: () =>
|
|
19
|
+
p.confirm({
|
|
20
|
+
message: 'Migrating from Firebase?',
|
|
21
|
+
initialValue: false,
|
|
22
|
+
}),
|
|
23
|
+
serviceAccountPath: ({ results }) =>
|
|
24
|
+
results.migrateFromFirebase
|
|
25
|
+
? p.text({
|
|
26
|
+
message: 'Path to Firebase service account JSON',
|
|
27
|
+
placeholder: './serviceAccountKey.json',
|
|
28
|
+
})
|
|
29
|
+
: Promise.resolve(undefined),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
onCancel: () => {
|
|
33
|
+
p.cancel('Cancelled.');
|
|
34
|
+
process.exit(0);
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
}
|
package/tsconfig.json
ADDED