@cyklang/cli 0.2.1 → 0.2.2
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/build/InitCommand.d.ts +6 -0
- package/build/InitCommand.js +36 -8
- package/package.json +3 -1
- package/src/InitCommand.ts +39 -8
package/build/InitCommand.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
export declare class InitCommand extends Command {
|
|
3
|
+
PGPORT: string;
|
|
4
|
+
USER_NAME: string;
|
|
5
|
+
USER_PASSWORD: string;
|
|
6
|
+
USER_EMAIL: string;
|
|
7
|
+
CYK_PORT: string;
|
|
3
8
|
constructor(name: string);
|
|
4
9
|
commandInit(options: any): Promise<void>;
|
|
10
|
+
promptParameters(): Promise<void>;
|
|
5
11
|
getRandomInt(min: number, max: number): number;
|
|
6
12
|
generateToken(): string;
|
|
7
13
|
writeEnvFile(): Promise<void>;
|
package/build/InitCommand.js
CHANGED
|
@@ -18,16 +18,25 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
18
|
__setModuleDefault(result, mod);
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
21
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
25
|
exports.InitCommand = void 0;
|
|
23
26
|
const commander_1 = require("commander");
|
|
24
27
|
const fs = __importStar(require("fs"));
|
|
28
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
25
29
|
const loglevel_1 = require("loglevel");
|
|
26
30
|
const logger = (0, loglevel_1.getLogger)('InitCommand.ts');
|
|
27
31
|
logger.setLevel('debug');
|
|
28
32
|
class InitCommand extends commander_1.Command {
|
|
29
33
|
constructor(name) {
|
|
30
34
|
super(name);
|
|
35
|
+
this.PGPORT = "5432";
|
|
36
|
+
this.USER_NAME = "cyk";
|
|
37
|
+
this.USER_PASSWORD = "cyk";
|
|
38
|
+
this.USER_EMAIL = "my-email@my-domain";
|
|
39
|
+
this.CYK_PORT = "3000";
|
|
31
40
|
this.description('initialize a folder with files necessary for a cyklang project')
|
|
32
41
|
.action(async (options) => {
|
|
33
42
|
await this.commandInit(options);
|
|
@@ -35,6 +44,7 @@ class InitCommand extends commander_1.Command {
|
|
|
35
44
|
}
|
|
36
45
|
async commandInit(options) {
|
|
37
46
|
try {
|
|
47
|
+
await this.promptParameters();
|
|
38
48
|
await this.writeEnvFile();
|
|
39
49
|
await this.writeDockerComposeFile();
|
|
40
50
|
}
|
|
@@ -42,6 +52,24 @@ class InitCommand extends commander_1.Command {
|
|
|
42
52
|
logger.error(err);
|
|
43
53
|
}
|
|
44
54
|
}
|
|
55
|
+
async promptParameters() {
|
|
56
|
+
const reply = await inquirer_1.default.prompt([
|
|
57
|
+
{ type: "number", name: 'PGPORT', default: this.PGPORT, message: 'Postgresql Port' },
|
|
58
|
+
{ type: 'number', name: 'CYK_PORT', default: this.CYK_PORT, message: 'NodeJS Port' },
|
|
59
|
+
{ type: 'input', name: 'USER_NAME', default: this.USER_NAME, message: 'Admin User Login' },
|
|
60
|
+
{ type: 'input', name: 'USER_PASSWORD', default: this.USER_PASSWORD, message: 'Admin User Password' },
|
|
61
|
+
{ type: 'input', name: 'USER_EMAIL', default: this.USER_EMAIL, message: 'Admin Use Email' },
|
|
62
|
+
{ type: "confirm", name: 'confirm' }
|
|
63
|
+
]);
|
|
64
|
+
// logger.debug(reply)
|
|
65
|
+
if (reply.confirm === false)
|
|
66
|
+
throw 'Command cancelled';
|
|
67
|
+
this.PGPORT = reply.PGPORT;
|
|
68
|
+
this.CYK_PORT = reply.CYK_PORT;
|
|
69
|
+
this.USER_NAME = reply.USER_NAME;
|
|
70
|
+
this.USER_PASSWORD = reply.USER_PASSWORD;
|
|
71
|
+
this.USER_EMAIL = reply.USER_EMAIL;
|
|
72
|
+
}
|
|
45
73
|
// developer.mozilla.org Math.random()
|
|
46
74
|
// On renvoie un entier aléatoire entre une valeur min (incluse)
|
|
47
75
|
// et une valeur max (exclue).
|
|
@@ -69,7 +97,7 @@ class InitCommand extends commander_1.Command {
|
|
|
69
97
|
const content = `# PostgreSql connection
|
|
70
98
|
# used by psql command line utility
|
|
71
99
|
PGHOST="localhost"
|
|
72
|
-
PGPORT="
|
|
100
|
+
PGPORT="${this.PGPORT}"
|
|
73
101
|
PGUSER="postgres"
|
|
74
102
|
PGPASSWORD="postgres"
|
|
75
103
|
|
|
@@ -80,9 +108,9 @@ POSTGRES_PASSWORD="postgres"
|
|
|
80
108
|
|
|
81
109
|
# admin user
|
|
82
110
|
# created at database initialization
|
|
83
|
-
ADMIN_NAME
|
|
84
|
-
ADMIN_PASSWORD
|
|
85
|
-
ADMIN_EMAIL
|
|
111
|
+
ADMIN_NAME=${this.USER_NAME}
|
|
112
|
+
ADMIN_PASSWORD=${this.USER_PASSWORD}
|
|
113
|
+
ADMIN_EMAIL=${this.USER_EMAIL}
|
|
86
114
|
|
|
87
115
|
# JWT token generation
|
|
88
116
|
# e.g. https://www.allkeysgenerator.com
|
|
@@ -99,10 +127,10 @@ LOGIN_APPLI="index"
|
|
|
99
127
|
|
|
100
128
|
# credential used by cyk CLI
|
|
101
129
|
|
|
102
|
-
USER_NAME
|
|
103
|
-
USER_PASSWORD
|
|
104
|
-
CYK_PORT="
|
|
105
|
-
DBREMOTE_URL="http://localhost
|
|
130
|
+
USER_NAME=${this.USER_NAME}
|
|
131
|
+
USER_PASSWORD=${this.USER_PASSWORD}
|
|
132
|
+
CYK_PORT="${this.CYK_PORT}"
|
|
133
|
+
DBREMOTE_URL="http://localhost:${this.CYK_PORT}"
|
|
106
134
|
`;
|
|
107
135
|
fs.writeFileSync(envFilename, content);
|
|
108
136
|
logger.debug('created ' + envFilename);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyklang/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "cyklang CLI",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,12 +21,14 @@
|
|
|
21
21
|
"commander": "^9.4.0",
|
|
22
22
|
"dotenv": "^16.0.1",
|
|
23
23
|
"form-data": "^4.0.0",
|
|
24
|
+
"inquirer": "^8.2.5",
|
|
24
25
|
"loglevel": "^1.8.0",
|
|
25
26
|
"mime-types": "^2.1.35",
|
|
26
27
|
"pako": "^2.0.4",
|
|
27
28
|
"xml": "^1.0.1"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
31
|
+
"@types/inquirer": "^8.2.4",
|
|
30
32
|
"@types/mime-types": "^2.1.1",
|
|
31
33
|
"@types/pako": "^2.0.0",
|
|
32
34
|
"@types/sax": "^1.2.4",
|
package/src/InitCommand.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import * as fs from 'fs'
|
|
3
|
+
import inquirer from "inquirer";
|
|
3
4
|
import { getLogger } from "loglevel";
|
|
5
|
+
|
|
4
6
|
const logger = getLogger('InitCommand.ts')
|
|
5
7
|
|
|
6
8
|
logger.setLevel('debug')
|
|
7
9
|
|
|
8
10
|
export class InitCommand extends Command {
|
|
11
|
+
|
|
12
|
+
PGPORT="5432"
|
|
13
|
+
USER_NAME="cyk"
|
|
14
|
+
USER_PASSWORD="cyk"
|
|
15
|
+
USER_EMAIL="my-email@my-domain"
|
|
16
|
+
CYK_PORT="3000"
|
|
17
|
+
|
|
9
18
|
constructor(name: string) {
|
|
10
19
|
super(name)
|
|
11
20
|
this.description('initialize a folder with files necessary for a cyklang project')
|
|
@@ -15,6 +24,7 @@ export class InitCommand extends Command {
|
|
|
15
24
|
}
|
|
16
25
|
async commandInit(options: any) {
|
|
17
26
|
try {
|
|
27
|
+
await this.promptParameters()
|
|
18
28
|
await this.writeEnvFile()
|
|
19
29
|
await this.writeDockerComposeFile()
|
|
20
30
|
}
|
|
@@ -23,6 +33,26 @@ export class InitCommand extends Command {
|
|
|
23
33
|
}
|
|
24
34
|
}
|
|
25
35
|
|
|
36
|
+
async promptParameters() {
|
|
37
|
+
|
|
38
|
+
const reply = await inquirer.prompt([
|
|
39
|
+
|
|
40
|
+
{type: "number", name: 'PGPORT', default: this.PGPORT, message: 'Postgresql Port' },
|
|
41
|
+
{type: 'number', name: 'CYK_PORT', default: this.CYK_PORT, message: 'NodeJS Port'},
|
|
42
|
+
{type: 'input', name: 'USER_NAME', default: this.USER_NAME, message: 'Admin User Login'},
|
|
43
|
+
{type: 'input', name: 'USER_PASSWORD', default: this.USER_PASSWORD, message: 'Admin User Password'},
|
|
44
|
+
{type: 'input', name: 'USER_EMAIL', default: this.USER_EMAIL, message: 'Admin Use Email'},
|
|
45
|
+
{type: "confirm", name: 'confirm'}
|
|
46
|
+
])
|
|
47
|
+
// logger.debug(reply)
|
|
48
|
+
if (reply.confirm === false) throw 'Command cancelled'
|
|
49
|
+
this.PGPORT = reply.PGPORT
|
|
50
|
+
this.CYK_PORT = reply.CYK_PORT
|
|
51
|
+
this.USER_NAME = reply.USER_NAME
|
|
52
|
+
this.USER_PASSWORD = reply.USER_PASSWORD
|
|
53
|
+
this.USER_EMAIL = reply.USER_EMAIL
|
|
54
|
+
}
|
|
55
|
+
|
|
26
56
|
// developer.mozilla.org Math.random()
|
|
27
57
|
// On renvoie un entier aléatoire entre une valeur min (incluse)
|
|
28
58
|
// et une valeur max (exclue).
|
|
@@ -49,11 +79,12 @@ export class InitCommand extends Command {
|
|
|
49
79
|
logger.info(envFilename + ' file already exists. Remove it before launching init command')
|
|
50
80
|
return
|
|
51
81
|
}
|
|
82
|
+
|
|
52
83
|
Math.random()
|
|
53
84
|
const content = `# PostgreSql connection
|
|
54
85
|
# used by psql command line utility
|
|
55
86
|
PGHOST="localhost"
|
|
56
|
-
PGPORT="
|
|
87
|
+
PGPORT="${this.PGPORT}"
|
|
57
88
|
PGUSER="postgres"
|
|
58
89
|
PGPASSWORD="postgres"
|
|
59
90
|
|
|
@@ -64,9 +95,9 @@ POSTGRES_PASSWORD="postgres"
|
|
|
64
95
|
|
|
65
96
|
# admin user
|
|
66
97
|
# created at database initialization
|
|
67
|
-
ADMIN_NAME
|
|
68
|
-
ADMIN_PASSWORD
|
|
69
|
-
ADMIN_EMAIL
|
|
98
|
+
ADMIN_NAME=${this.USER_NAME}
|
|
99
|
+
ADMIN_PASSWORD=${this.USER_PASSWORD}
|
|
100
|
+
ADMIN_EMAIL=${this.USER_EMAIL}
|
|
70
101
|
|
|
71
102
|
# JWT token generation
|
|
72
103
|
# e.g. https://www.allkeysgenerator.com
|
|
@@ -83,10 +114,10 @@ LOGIN_APPLI="index"
|
|
|
83
114
|
|
|
84
115
|
# credential used by cyk CLI
|
|
85
116
|
|
|
86
|
-
USER_NAME
|
|
87
|
-
USER_PASSWORD
|
|
88
|
-
CYK_PORT="
|
|
89
|
-
DBREMOTE_URL="http://localhost
|
|
117
|
+
USER_NAME=${this.USER_NAME}
|
|
118
|
+
USER_PASSWORD=${this.USER_PASSWORD}
|
|
119
|
+
CYK_PORT="${this.CYK_PORT}"
|
|
120
|
+
DBREMOTE_URL="http://localhost:${this.CYK_PORT}"
|
|
90
121
|
`
|
|
91
122
|
fs.writeFileSync(envFilename, content)
|
|
92
123
|
logger.debug('created ' + envFilename)
|