dbdocs 0.6.3 → 0.7.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/README.md +14 -0
- package/bin/run +3 -3
- package/oclif.manifest.json +1 -1
- package/package.json +13 -13
- package/src/commands/build.js +5 -5
- package/src/commands/login.js +1 -1
- package/src/commands/logout.js +1 -1
- package/src/commands/ls.js +3 -4
- package/src/commands/password.js +5 -5
- package/src/commands/remove.js +2 -2
- package/src/commands/rename.js +88 -0
- package/src/commands/token.js +4 -4
- package/src/commands/validate.js +2 -2
- package/src/index.js +1 -1
- package/src/validators/userName.js +6 -0
package/README.md
CHANGED
|
@@ -35,6 +35,7 @@ USAGE
|
|
|
35
35
|
* [`dbdocs ls`](#dbdocs-ls)
|
|
36
36
|
* [`dbdocs password`](#dbdocs-password)
|
|
37
37
|
* [`dbdocs remove [PROJECT_NAME]`](#dbdocs-remove-project_name)
|
|
38
|
+
* [`dbdocs rename`](#dbdocs-rename)
|
|
38
39
|
* [`dbdocs token`](#dbdocs-token)
|
|
39
40
|
* [`dbdocs validate [FILEPATH]`](#dbdocs-validate-filepath)
|
|
40
41
|
|
|
@@ -130,6 +131,19 @@ USAGE
|
|
|
130
131
|
ARGUMENTS
|
|
131
132
|
PROJECT_NAME name of the project which you want to remove
|
|
132
133
|
```
|
|
134
|
+
|
|
135
|
+
## `dbdocs rename`
|
|
136
|
+
|
|
137
|
+
change your username
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
USAGE
|
|
141
|
+
$ dbdocs rename
|
|
142
|
+
|
|
143
|
+
DESCRIPTION
|
|
144
|
+
change your username and your default organization name
|
|
145
|
+
```
|
|
146
|
+
|
|
133
147
|
## `dbdocs token`
|
|
134
148
|
|
|
135
149
|
generate or revoke your authentication token
|
package/bin/run
CHANGED
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.7.0","commands":{"build":{"id":"build","description":"build docs","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"project":{"name":"project","type":"option","description":"project name","multiple":false},"password":{"name":"password","type":"option","char":"p","description":"password for project","multiple":false}},"args":[{"name":"filepath","description":"dbml file path"}]},"login":{"id":"login","description":"login to dbdocs\nlogin with your dbdocs credentials\n","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"logout":{"id":"logout","description":"logout\nclears local login credentials\n","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"ls":{"id":"ls","description":"list projects","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"password":{"id":"password","description":"set password for your project or remove password","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"project":{"name":"project","type":"option","char":"p","description":"project name","helpValue":"project name","multiple":false},"set":{"name":"set","type":"option","char":"s","description":"password for your project","helpValue":"password","multiple":false},"remove":{"name":"remove","type":"boolean","char":"r","description":"remove password from your project","allowNo":false}},"args":[]},"remove":{"id":"remove","description":"remove docs","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"project_name","description":"name of the project which you want to remove"}]},"rename":{"id":"rename","description":"change your username","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"token":{"id":"token","description":"generate or revoke your authentication token","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"generate":{"name":"generate","type":"boolean","char":"g","description":"generate authentication token","allowNo":false},"revoke":{"name":"revoke","type":"boolean","char":"r","description":"revoke authentication token","allowNo":false}},"args":[]},"validate":{"id":"validate","description":"validate docs content","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"filepath","description":"dbml file path"}]}}}
|
package/package.json
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbdocs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"author": "@holistics",
|
|
5
5
|
"bin": {
|
|
6
6
|
"dbdocs": "./bin/run"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@dbml/core": "^2.4.2",
|
|
10
|
-
"@oclif/
|
|
11
|
-
"@oclif/
|
|
12
|
-
"
|
|
13
|
-
"axios": "^0.19.0",
|
|
10
|
+
"@oclif/core": "1.12.1",
|
|
11
|
+
"@oclif/plugin-help": "5.1.12",
|
|
12
|
+
"axios": "0.27.2",
|
|
14
13
|
"chalk": "^3.0.0",
|
|
15
|
-
"cli-ux": "^5.6.3",
|
|
16
14
|
"dotenv": "^8.2.0",
|
|
17
15
|
"inquirer": "^7.0.1",
|
|
18
16
|
"netrc-parser": "^3.1.6",
|
|
@@ -21,15 +19,15 @@
|
|
|
21
19
|
"update-notifier": "^4.1.0"
|
|
22
20
|
},
|
|
23
21
|
"devDependencies": {
|
|
24
|
-
"@oclif/
|
|
25
|
-
"@oclif/test": "^1",
|
|
22
|
+
"@oclif/test": "2.1.1",
|
|
26
23
|
"chai": "^4",
|
|
27
24
|
"globby": "^10",
|
|
28
25
|
"mocha": "^5",
|
|
29
|
-
"nyc": "^14"
|
|
26
|
+
"nyc": "^14",
|
|
27
|
+
"oclif": "^3.2.0"
|
|
30
28
|
},
|
|
31
29
|
"engines": {
|
|
32
|
-
"node": ">=
|
|
30
|
+
"node": ">=14.0.0"
|
|
33
31
|
},
|
|
34
32
|
"files": [
|
|
35
33
|
"/bin",
|
|
@@ -43,6 +41,8 @@
|
|
|
43
41
|
"license": "MIT",
|
|
44
42
|
"main": "src/index.js",
|
|
45
43
|
"oclif": {
|
|
44
|
+
"additionalHelpFlags": ["help"],
|
|
45
|
+
"additionalVersionFlags": ["version"],
|
|
46
46
|
"commands": "./src/commands",
|
|
47
47
|
"bin": "dbdocs",
|
|
48
48
|
"plugins": [
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"./src/hooks/init/checkUpdate",
|
|
54
54
|
"./src/hooks/init/loadEnv"
|
|
55
55
|
],
|
|
56
|
-
"prerun":[
|
|
56
|
+
"prerun": [
|
|
57
57
|
"./src/hooks/prerun/checkVersion"
|
|
58
58
|
]
|
|
59
59
|
}
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"repository": "holistics/dbdocs",
|
|
62
62
|
"scripts": {
|
|
63
63
|
"postpack": "rm -f oclif.manifest.json",
|
|
64
|
-
"prepack": "oclif
|
|
64
|
+
"prepack": "oclif manifest",
|
|
65
65
|
"test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
|
|
66
|
-
"version": "oclif
|
|
66
|
+
"version": "oclif readme && git add README.md"
|
|
67
67
|
}
|
|
68
68
|
}
|
package/src/commands/build.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { Command,
|
|
1
|
+
const { Command, Flags } = require('@oclif/core');
|
|
2
2
|
const axios = require('axios');
|
|
3
3
|
const inquirer = require('inquirer');
|
|
4
4
|
const fs = require('fs');
|
|
@@ -37,8 +37,8 @@ class BuildCommand extends Command {
|
|
|
37
37
|
try {
|
|
38
38
|
const authConfig = await verifyToken();
|
|
39
39
|
|
|
40
|
-
let { flags: { project, password } } = this.parse(BuildCommand);
|
|
41
|
-
const { args } = this.parse(BuildCommand);
|
|
40
|
+
let { flags: { project, password } } = await this.parse(BuildCommand);
|
|
41
|
+
const { args } = await this.parse(BuildCommand);
|
|
42
42
|
|
|
43
43
|
const { filepath } = args;
|
|
44
44
|
let content = '';
|
|
@@ -137,8 +137,8 @@ class BuildCommand extends Command {
|
|
|
137
137
|
BuildCommand.description = 'build docs';
|
|
138
138
|
|
|
139
139
|
BuildCommand.flags = {
|
|
140
|
-
project:
|
|
141
|
-
password:
|
|
140
|
+
project: Flags.string({ description: 'project name' }),
|
|
141
|
+
password: Flags.string({ char: 'p', description: 'password for project' }),
|
|
142
142
|
};
|
|
143
143
|
|
|
144
144
|
BuildCommand.args = [
|
package/src/commands/login.js
CHANGED
package/src/commands/logout.js
CHANGED
package/src/commands/ls.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
const { Command } = require('@oclif/
|
|
2
|
-
const { cli } = require('cli-ux');
|
|
1
|
+
const { Command, CliUx } = require('@oclif/core');
|
|
3
2
|
const chalk = require('chalk');
|
|
4
3
|
const { vars } = require('../vars');
|
|
5
4
|
const verifyToken = require('../utils/verifyToken');
|
|
@@ -23,7 +22,7 @@ class LsCommand extends Command {
|
|
|
23
22
|
];
|
|
24
23
|
}, [3, 12]);
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
CliUx.ux.table(projects, {
|
|
27
26
|
name: {
|
|
28
27
|
minWidth: 20,
|
|
29
28
|
},
|
|
@@ -43,7 +42,7 @@ class LsCommand extends Command {
|
|
|
43
42
|
get: (project) => (new Date(project.updatedAt)).toLocaleString(),
|
|
44
43
|
},
|
|
45
44
|
}, {
|
|
46
|
-
printLine: this.log,
|
|
45
|
+
printLine: this.log.bind(this),
|
|
47
46
|
});
|
|
48
47
|
} catch (err) {
|
|
49
48
|
this.error(err);
|
package/src/commands/password.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { Command,
|
|
1
|
+
const { Command, Flags } = require('@oclif/core');
|
|
2
2
|
const axios = require('axios');
|
|
3
3
|
const inquirer = require('inquirer');
|
|
4
4
|
const ora = require('ora');
|
|
@@ -24,7 +24,7 @@ class PasswordCommand extends Command {
|
|
|
24
24
|
async run () {
|
|
25
25
|
const spinner = ora({});
|
|
26
26
|
try {
|
|
27
|
-
let { flags: { project, set, remove } } = this.parse(PasswordCommand);
|
|
27
|
+
let { flags: { project, set, remove } } = await this.parse(PasswordCommand);
|
|
28
28
|
|
|
29
29
|
if (set && remove) {
|
|
30
30
|
throw new Error('You must choose one, set password or remove.');
|
|
@@ -102,9 +102,9 @@ class PasswordCommand extends Command {
|
|
|
102
102
|
PasswordCommand.description = 'set password for your project or remove password';
|
|
103
103
|
|
|
104
104
|
PasswordCommand.flags = {
|
|
105
|
-
project:
|
|
106
|
-
set:
|
|
107
|
-
remove:
|
|
105
|
+
project: Flags.string({ char: 'p', description: 'project name', helpValue: 'project name' }),
|
|
106
|
+
set: Flags.string({ char: 's', description: 'password for your project', helpValue: 'password' }),
|
|
107
|
+
remove: Flags.boolean({ char: 'r', description: 'remove password from your project' }),
|
|
108
108
|
};
|
|
109
109
|
|
|
110
110
|
module.exports = PasswordCommand;
|
package/src/commands/remove.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable camelcase */
|
|
2
|
-
const { Command } = require('@oclif/
|
|
2
|
+
const { Command } = require('@oclif/core');
|
|
3
3
|
const axios = require('axios');
|
|
4
4
|
const inquirer = require('inquirer');
|
|
5
5
|
const ora = require('ora');
|
|
@@ -21,7 +21,7 @@ class RemoveCommand extends Command {
|
|
|
21
21
|
const authConfig = await verifyToken();
|
|
22
22
|
const org = await getOrg(authConfig);
|
|
23
23
|
|
|
24
|
-
const { args } = this.parse(RemoveCommand);
|
|
24
|
+
const { args } = await this.parse(RemoveCommand);
|
|
25
25
|
let { project_name } = args;
|
|
26
26
|
if (!project_name) {
|
|
27
27
|
const answer = await inquirer.prompt([
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const { Command } = require('@oclif/core');
|
|
2
|
+
const inquirer = require('inquirer');
|
|
3
|
+
const axios = require('axios');
|
|
4
|
+
const ora = require('ora');
|
|
5
|
+
const { vars } = require('../vars');
|
|
6
|
+
const { isValidUserName } = require('../validators/userName');
|
|
7
|
+
const verifyToken = require('../utils/verifyToken');
|
|
8
|
+
|
|
9
|
+
async function enterUserName () {
|
|
10
|
+
const answer = await inquirer.prompt([
|
|
11
|
+
{
|
|
12
|
+
message: 'Please input your new username: ',
|
|
13
|
+
name: 'newUserName',
|
|
14
|
+
},
|
|
15
|
+
]);
|
|
16
|
+
return answer.newUserName;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function validateAndUpdateUserName (spinner, authConfig, command) {
|
|
20
|
+
let newUserName = await enterUserName();
|
|
21
|
+
|
|
22
|
+
while (!isValidUserName(newUserName)) {
|
|
23
|
+
spinner.warn('Invalid username! Username can only contain alphabets, numbers, "-" or "_" and can not be blanked!');
|
|
24
|
+
newUserName = await enterUserName();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const { data: { user, hasRevokedToken } } = await axios.put(`${vars.apiUrl}/account/rename`, { newUserName }, authConfig);
|
|
29
|
+
return { user, hasRevokedToken };
|
|
30
|
+
} catch (err) {
|
|
31
|
+
const { error } = err.response.data;
|
|
32
|
+
const warningNames = ['UserNameNotChange', 'UserNameExisted'];
|
|
33
|
+
if (warningNames.includes(error.name)) {
|
|
34
|
+
spinner.warn(error.message);
|
|
35
|
+
} else {
|
|
36
|
+
command.error(error.message);
|
|
37
|
+
}
|
|
38
|
+
return { user: null, hasRevokedToken: null };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class RenameCommand extends Command {
|
|
43
|
+
async run () {
|
|
44
|
+
const spinner = ora({});
|
|
45
|
+
try {
|
|
46
|
+
const authConfig = await verifyToken();
|
|
47
|
+
|
|
48
|
+
this.warn('After renaming, your authentication token (if exists) will be revoked. Please re-generate a new one!');
|
|
49
|
+
this.warn('You may need to re-login your account on the dbdocs web app for the best user experience.');
|
|
50
|
+
|
|
51
|
+
let { user, hasRevokedToken } = await validateAndUpdateUserName(spinner, authConfig, this);
|
|
52
|
+
while (!user) {
|
|
53
|
+
({ user, hasRevokedToken } = await validateAndUpdateUserName(spinner, authConfig, this));
|
|
54
|
+
}
|
|
55
|
+
if (hasRevokedToken) {
|
|
56
|
+
spinner.succeed('Rename successfully and your access token has been revoked, please generate a new one!');
|
|
57
|
+
} else {
|
|
58
|
+
spinner.succeed('Rename successfully!');
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
if (spinner.isSpinning) {
|
|
62
|
+
spinner.fail();
|
|
63
|
+
}
|
|
64
|
+
let message = err.message || 'Something wrong :( Please try again.';
|
|
65
|
+
if (err.response) {
|
|
66
|
+
const { error } = err.response.data;
|
|
67
|
+
switch (error.name) {
|
|
68
|
+
case 'TokenExpiredError':
|
|
69
|
+
message = 'Your token has expired. Please login again.';
|
|
70
|
+
break;
|
|
71
|
+
|
|
72
|
+
case 'InvalidAuthToken':
|
|
73
|
+
message = 'Invalid token. Please login again.';
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
default:
|
|
77
|
+
message = error.message;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
this.error(message);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
RenameCommand.description = 'change your username';
|
|
87
|
+
|
|
88
|
+
module.exports = RenameCommand;
|
package/src/commands/token.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { Command,
|
|
1
|
+
const { Command, Flags } = require('@oclif/core');
|
|
2
2
|
const ora = require('ora');
|
|
3
3
|
const axios = require('axios');
|
|
4
4
|
const { vars } = require('../vars');
|
|
@@ -7,7 +7,7 @@ const verifyToken = require('../utils/verifyToken');
|
|
|
7
7
|
class TokenCommand extends Command {
|
|
8
8
|
async run () {
|
|
9
9
|
const spinner = ora({});
|
|
10
|
-
const { flags: { generate, revoke } } = this.parse(TokenCommand);
|
|
10
|
+
const { flags: { generate, revoke } } = await this.parse(TokenCommand);
|
|
11
11
|
if (!generate && !revoke) {
|
|
12
12
|
this.error('Please specify an action, type "dbdocs token --help" to see processable actitons.');
|
|
13
13
|
}
|
|
@@ -56,12 +56,12 @@ class TokenCommand extends Command {
|
|
|
56
56
|
|
|
57
57
|
TokenCommand.description = 'generate or revoke your authentication token';
|
|
58
58
|
TokenCommand.flags = {
|
|
59
|
-
generate:
|
|
59
|
+
generate: Flags.boolean({
|
|
60
60
|
char: 'g',
|
|
61
61
|
description: 'generate authentication token',
|
|
62
62
|
default: false,
|
|
63
63
|
}),
|
|
64
|
-
revoke:
|
|
64
|
+
revoke: Flags.boolean({
|
|
65
65
|
char: 'r',
|
|
66
66
|
description: 'revoke authentication token',
|
|
67
67
|
default: false,
|
package/src/commands/validate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { Command
|
|
1
|
+
const { Command } = require('@oclif/core');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const ora = require('ora');
|
|
@@ -9,7 +9,7 @@ class ValidateCommand extends Command {
|
|
|
9
9
|
const spinner = ora({});
|
|
10
10
|
let filepath = null;
|
|
11
11
|
try {
|
|
12
|
-
const { args } = this.parse(ValidateCommand);
|
|
12
|
+
const { args } = await this.parse(ValidateCommand);
|
|
13
13
|
filepath = args.filepath;
|
|
14
14
|
let content = '';
|
|
15
15
|
content = fs.readFileSync(path.resolve(process.cwd(), filepath), 'utf-8');
|
package/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('@oclif/
|
|
1
|
+
module.exports = require('@oclif/core');
|