@logto/cli 1.0.0-beta.16 → 1.0.0-beta.19
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/bin/logto.js +2 -0
- package/lib/commands/connector/add.js +8 -10
- package/lib/commands/connector/index.js +9 -14
- package/lib/commands/connector/list.js +10 -16
- package/lib/commands/connector/remove.js +13 -18
- package/lib/commands/connector/utils.d.ts +1 -1
- package/lib/commands/connector/utils.js +100 -86
- package/lib/commands/database/alteration/index.d.ts +1 -2
- package/lib/commands/database/alteration/index.js +36 -98
- package/lib/commands/database/alteration/index.test.js +36 -57
- package/lib/commands/database/alteration/meta-url.d.ts +1 -0
- package/lib/commands/database/alteration/meta-url.js +4 -0
- package/lib/commands/database/alteration/type.d.ts +1 -1
- package/lib/commands/database/alteration/type.js +1 -2
- package/lib/commands/database/alteration/utils.d.ts +4 -0
- package/lib/commands/database/alteration/utils.js +39 -0
- package/lib/commands/database/alteration/version.d.ts +1 -1
- package/lib/commands/database/alteration/version.js +18 -25
- package/lib/commands/database/config.js +44 -49
- package/lib/commands/database/index.js +7 -12
- package/lib/commands/database/seed/index.d.ts +1 -1
- package/lib/commands/database/seed/index.js +59 -55
- package/lib/commands/database/seed/oidc-config.js +15 -18
- package/lib/commands/database/utilities.js +6 -11
- package/lib/commands/install/index.d.ts +1 -1
- package/lib/commands/install/index.js +14 -28
- package/lib/commands/install/utils.d.ts +0 -1
- package/lib/commands/install/utils.js +59 -106
- package/lib/constants.js +1 -4
- package/lib/database.js +33 -43
- package/lib/index.js +18 -23
- package/lib/meta-url.d.ts +1 -0
- package/lib/meta-url.js +4 -0
- package/lib/package-json.d.ts +7 -3
- package/lib/package-json.js +28 -27
- package/lib/queries/logto-config.js +18 -26
- package/lib/queries/logto-config.test.js +29 -30
- package/lib/test-utilities.d.ts +2 -2
- package/lib/test-utilities.js +1 -5
- package/lib/utilities.d.ts +5 -5
- package/lib/utilities.js +49 -64
- package/package.json +27 -23
- package/bin/logto +0 -2
package/lib/utilities.js
CHANGED
|
@@ -1,53 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
16
|
-
const ora_1 = __importDefault(require("ora"));
|
|
17
|
-
const zod_1 = require("zod");
|
|
18
|
-
const safeExecSync = (command) => {
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import { createWriteStream, existsSync } from 'fs';
|
|
3
|
+
import { readdir, readFile } from 'fs/promises';
|
|
4
|
+
import { createRequire } from 'module';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { conditionalString } from '@silverhand/essentials';
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import { got } from 'got';
|
|
9
|
+
import { HttpsProxyAgent } from 'hpagent';
|
|
10
|
+
import inquirer from 'inquirer';
|
|
11
|
+
import ora from 'ora';
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { metaUrl } from './meta-url.js';
|
|
14
|
+
export const safeExecSync = (command) => {
|
|
19
15
|
try {
|
|
20
|
-
return
|
|
16
|
+
return execSync(command, { encoding: 'utf8', stdio: 'pipe' });
|
|
21
17
|
}
|
|
22
18
|
catch { }
|
|
23
19
|
};
|
|
24
|
-
|
|
25
|
-
exports.log = Object.freeze({
|
|
20
|
+
export const log = Object.freeze({
|
|
26
21
|
info: (...args) => {
|
|
27
|
-
console.log(
|
|
22
|
+
console.log(chalk.blue('[info]'), ...args);
|
|
28
23
|
},
|
|
29
24
|
succeed: (...args) => {
|
|
30
|
-
|
|
25
|
+
log.info(chalk.green('✔'), ...args);
|
|
31
26
|
},
|
|
32
27
|
warn: (...args) => {
|
|
33
|
-
console.warn(
|
|
28
|
+
console.warn(chalk.yellow('[warn]'), ...args);
|
|
34
29
|
},
|
|
35
30
|
error: (...args) => {
|
|
36
|
-
console.error(
|
|
31
|
+
console.error(chalk.red('[error]'), ...args);
|
|
37
32
|
// eslint-disable-next-line unicorn/no-process-exit
|
|
38
33
|
process.exit(1);
|
|
39
34
|
},
|
|
40
35
|
});
|
|
41
|
-
const downloadFile = async (url, destination) => {
|
|
36
|
+
export const downloadFile = async (url, destination) => {
|
|
42
37
|
const { HTTPS_PROXY, HTTP_PROXY, https_proxy, http_proxy } = process.env;
|
|
43
|
-
const file =
|
|
38
|
+
const file = createWriteStream(destination);
|
|
44
39
|
const proxy = HTTPS_PROXY ?? https_proxy ?? HTTP_PROXY ?? http_proxy;
|
|
45
|
-
const stream =
|
|
46
|
-
...(proxy && { agent: { https: new
|
|
40
|
+
const stream = got.stream(url, {
|
|
41
|
+
...(proxy && { agent: { https: new HttpsProxyAgent({ proxy }) } }),
|
|
47
42
|
});
|
|
48
|
-
const spinner = (
|
|
43
|
+
const spinner = ora({
|
|
49
44
|
text: 'Connecting',
|
|
50
|
-
prefixText:
|
|
45
|
+
prefixText: chalk.blue('[info]'),
|
|
51
46
|
}).start();
|
|
52
47
|
stream.pipe(file);
|
|
53
48
|
return new Promise((resolve, reject) => {
|
|
@@ -69,16 +64,11 @@ const downloadFile = async (url, destination) => {
|
|
|
69
64
|
});
|
|
70
65
|
});
|
|
71
66
|
};
|
|
72
|
-
|
|
73
|
-
const getPathInModule = (moduleName, relativePath = '/') =>
|
|
67
|
+
export const getPathInModule = (moduleName, relativePath = '/') =>
|
|
74
68
|
// https://stackoverflow.com/a/49455609/12514940
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
path_1.default.dirname(require.resolve(`${moduleName}/package.json`)), relativePath);
|
|
79
|
-
exports.getPathInModule = getPathInModule;
|
|
80
|
-
const oraPromise = async (promise, options, exitOnError = false) => {
|
|
81
|
-
const spinner = (0, ora_1.default)(options).start();
|
|
69
|
+
path.join(path.dirname(createRequire(metaUrl).resolve(`${moduleName}/package.json`)), relativePath);
|
|
70
|
+
export const oraPromise = async (promise, options, exitOnError = false) => {
|
|
71
|
+
const spinner = ora(options).start();
|
|
82
72
|
try {
|
|
83
73
|
const result = await promise;
|
|
84
74
|
spinner.succeed();
|
|
@@ -87,33 +77,30 @@ const oraPromise = async (promise, options, exitOnError = false) => {
|
|
|
87
77
|
catch (error) {
|
|
88
78
|
spinner.fail();
|
|
89
79
|
if (exitOnError) {
|
|
90
|
-
|
|
80
|
+
log.error(error);
|
|
91
81
|
}
|
|
92
82
|
throw error;
|
|
93
83
|
}
|
|
94
84
|
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
exports.isTty = isTty;
|
|
98
|
-
var ConfigKey;
|
|
85
|
+
export const isTty = () => process.stdin.isTTY;
|
|
86
|
+
export var ConfigKey;
|
|
99
87
|
(function (ConfigKey) {
|
|
100
88
|
ConfigKey["DatabaseUrl"] = "DB_URL";
|
|
101
|
-
})(ConfigKey
|
|
102
|
-
|
|
103
|
-
const getCliConfigWithPrompt = async ({ key, readableKey, comments, defaultValue, }) => {
|
|
104
|
-
if (
|
|
105
|
-
return
|
|
89
|
+
})(ConfigKey || (ConfigKey = {}));
|
|
90
|
+
export const cliConfig = new Map();
|
|
91
|
+
export const getCliConfigWithPrompt = async ({ key, readableKey, comments, defaultValue, }) => {
|
|
92
|
+
if (cliConfig.has(key) || !isTty()) {
|
|
93
|
+
return cliConfig.get(key);
|
|
106
94
|
}
|
|
107
|
-
const { input } = await
|
|
95
|
+
const { input } = await inquirer.prompt({
|
|
108
96
|
type: 'input',
|
|
109
97
|
name: 'input',
|
|
110
|
-
message: `Enter your ${readableKey}${
|
|
98
|
+
message: `Enter your ${readableKey}${conditionalString(comments && ' ' + comments)}`,
|
|
111
99
|
default: defaultValue,
|
|
112
100
|
});
|
|
113
|
-
|
|
101
|
+
cliConfig.set(key, input);
|
|
114
102
|
return input;
|
|
115
103
|
};
|
|
116
|
-
exports.getCliConfigWithPrompt = getCliConfigWithPrompt;
|
|
117
104
|
// https://stackoverflow.com/a/53187807/12514940
|
|
118
105
|
/**
|
|
119
106
|
* Returns the index of the last element in the array where predicate is true, and -1
|
|
@@ -123,7 +110,7 @@ exports.getCliConfigWithPrompt = getCliConfigWithPrompt;
|
|
|
123
110
|
* order, until it finds one where predicate returns true. If such an element is found,
|
|
124
111
|
* findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
|
|
125
112
|
*/
|
|
126
|
-
function findLastIndex(array, predicate) {
|
|
113
|
+
export function findLastIndex(array, predicate) {
|
|
127
114
|
// eslint-disable-next-line @silverhand/fp/no-let
|
|
128
115
|
let { length } = array;
|
|
129
116
|
// eslint-disable-next-line @silverhand/fp/no-mutation
|
|
@@ -135,24 +122,22 @@ function findLastIndex(array, predicate) {
|
|
|
135
122
|
}
|
|
136
123
|
return -1;
|
|
137
124
|
}
|
|
138
|
-
exports.findLastIndex = findLastIndex;
|
|
139
125
|
const getConnectorPackageName = async (directory) => {
|
|
140
|
-
const filePath =
|
|
141
|
-
if (!
|
|
126
|
+
const filePath = path.join(directory, 'package.json');
|
|
127
|
+
if (!existsSync(filePath)) {
|
|
142
128
|
return;
|
|
143
129
|
}
|
|
144
|
-
const json = await
|
|
145
|
-
const { name } =
|
|
130
|
+
const json = await readFile(filePath, 'utf8');
|
|
131
|
+
const { name } = z.object({ name: z.string() }).parse(JSON.parse(json));
|
|
146
132
|
if (name.startsWith('connector-') || Boolean(name.split('/')[1]?.startsWith('connector-'))) {
|
|
147
133
|
return name;
|
|
148
134
|
}
|
|
149
135
|
};
|
|
150
|
-
const getConnectorPackagesFromDirectory = async (directory) => {
|
|
151
|
-
const content = await
|
|
136
|
+
export const getConnectorPackagesFromDirectory = async (directory) => {
|
|
137
|
+
const content = await readdir(directory, 'utf8');
|
|
152
138
|
const rawPackages = await Promise.all(content.map(async (value) => {
|
|
153
|
-
const currentDirectory =
|
|
139
|
+
const currentDirectory = path.join(directory, value);
|
|
154
140
|
return { name: await getConnectorPackageName(currentDirectory), path: currentDirectory };
|
|
155
141
|
}));
|
|
156
142
|
return rawPackages.filter((packageInfo) => typeof packageInfo.name === 'string');
|
|
157
143
|
};
|
|
158
|
-
exports.getConnectorPackagesFromDirectory = getConnectorPackagesFromDirectory;
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/cli",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.19",
|
|
4
4
|
"description": "Logto CLI.",
|
|
5
5
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
6
6
|
"homepage": "https://github.com/logto-io/logto#readme",
|
|
7
7
|
"license": "MPL-2.0",
|
|
8
|
+
"type": "module",
|
|
8
9
|
"publishConfig": {
|
|
9
10
|
"access": "public"
|
|
10
11
|
},
|
|
11
12
|
"main": "lib/index.js",
|
|
12
13
|
"bin": {
|
|
13
|
-
"logto": "bin/logto"
|
|
14
|
+
"logto": "bin/logto.js"
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
16
17
|
"bin",
|
|
@@ -27,46 +28,47 @@
|
|
|
27
28
|
"url": "https://github.com/logto-io/logto/issues"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@silverhand/essentials": "
|
|
31
|
-
"chalk": "^
|
|
32
|
-
"decamelize": "^
|
|
31
|
+
"@silverhand/essentials": "2.1.0",
|
|
32
|
+
"chalk": "^5.0.0",
|
|
33
|
+
"decamelize": "^6.0.0",
|
|
33
34
|
"dotenv": "^16.0.0",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"hpagent": "^1.0.0",
|
|
35
|
+
"got": "^12.5.3",
|
|
36
|
+
"hpagent": "^1.2.0",
|
|
37
37
|
"inquirer": "^8.2.2",
|
|
38
|
-
"nanoid": "^
|
|
39
|
-
"ora": "^
|
|
40
|
-
"p-
|
|
38
|
+
"nanoid": "^4.0.0",
|
|
39
|
+
"ora": "^6.1.2",
|
|
40
|
+
"p-limit": "^4.0.0",
|
|
41
|
+
"p-retry": "^5.1.2",
|
|
41
42
|
"roarr": "^7.11.0",
|
|
42
|
-
"semver": "^7.3.
|
|
43
|
+
"semver": "^7.3.8",
|
|
43
44
|
"slonik": "^30.0.0",
|
|
44
45
|
"slonik-interceptor-preset": "^1.2.10",
|
|
45
46
|
"slonik-sql-tag-raw": "^1.1.4",
|
|
46
47
|
"tar": "^6.1.11",
|
|
47
48
|
"yargs": "^17.6.0",
|
|
48
|
-
"zod": "^3.
|
|
49
|
-
"@logto/
|
|
50
|
-
"@logto/schemas": "
|
|
49
|
+
"zod": "^3.20.2",
|
|
50
|
+
"@logto/core-kit": "1.0.0-beta.30",
|
|
51
|
+
"@logto/schemas": "1.0.0-beta.18",
|
|
52
|
+
"@logto/shared": "1.0.0-beta.18"
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
53
55
|
"@silverhand/eslint-config": "1.3.0",
|
|
54
|
-
"@silverhand/jest-config": "1.2.2",
|
|
55
56
|
"@silverhand/ts-config": "1.2.1",
|
|
56
57
|
"@types/fs-extra": "^9.0.13",
|
|
57
58
|
"@types/inquirer": "^8.2.1",
|
|
58
59
|
"@types/jest": "^29.1.2",
|
|
59
60
|
"@types/node": "^16.0.0",
|
|
60
61
|
"@types/semver": "^7.3.12",
|
|
62
|
+
"@types/sinon": "^10.0.13",
|
|
61
63
|
"@types/tar": "^6.1.2",
|
|
62
64
|
"@types/yargs": "^17.0.13",
|
|
63
65
|
"eslint": "^8.21.0",
|
|
64
|
-
"jest": "^29.1
|
|
66
|
+
"jest": "^29.3.1",
|
|
65
67
|
"lint-staged": "^13.0.0",
|
|
66
|
-
"prettier": "^2.
|
|
68
|
+
"prettier": "^2.8.1",
|
|
67
69
|
"rimraf": "^3.0.2",
|
|
68
|
-
"
|
|
69
|
-
"typescript": "^4.
|
|
70
|
+
"sinon": "^15.0.0",
|
|
71
|
+
"typescript": "^4.9.4"
|
|
70
72
|
},
|
|
71
73
|
"eslintConfig": {
|
|
72
74
|
"extends": "@silverhand",
|
|
@@ -79,12 +81,14 @@
|
|
|
79
81
|
"precommit": "lint-staged",
|
|
80
82
|
"prepare:package-json": "node -p \"'export const packageJson = ' + JSON.stringify(require('./package.json'), undefined, 2) + ';'\" > src/package-json.ts",
|
|
81
83
|
"build": "rimraf lib && pnpm prepare:package-json && tsc -p tsconfig.build.json",
|
|
84
|
+
"build:test": "rimraf lib/ && pnpm prepare:package-json && tsc -p tsconfig.test.json --sourcemap",
|
|
82
85
|
"dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput --incremental",
|
|
83
86
|
"start": "node .",
|
|
84
|
-
"start:dev": "
|
|
87
|
+
"start:dev": "pnpm build && node .",
|
|
85
88
|
"lint": "eslint --ext .ts src",
|
|
86
89
|
"lint:report": "pnpm lint --format json --output-file report.json",
|
|
87
|
-
"test": "jest",
|
|
88
|
-
"test:
|
|
90
|
+
"test:only": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
91
|
+
"test": "pnpm build:test && pnpm test:only",
|
|
92
|
+
"test:ci": "pnpm test:only"
|
|
89
93
|
}
|
|
90
94
|
}
|
package/bin/logto
DELETED