@cyklang/cli 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/README.md +1 -0
- package/aws-ecs.env +38 -0
- package/build/Cmd.d.ts +7 -0
- package/build/Cmd.js +35 -0
- package/build/DBClient.d.ts +10 -0
- package/build/DBClient.js +205 -0
- package/build/InitCommand.d.ts +9 -0
- package/build/InitCommand.js +122 -0
- package/build/ModuleCommand.d.ts +5 -0
- package/build/ModuleCommand.js +202 -0
- package/build/NodeCrypto.d.ts +5 -0
- package/build/NodeCrypto.js +49 -0
- package/build/QueryCommand.d.ts +5 -0
- package/build/QueryCommand.js +62 -0
- package/build/RunCommand.d.ts +5 -0
- package/build/RunCommand.js +112 -0
- package/build/TableCommand.d.ts +5 -0
- package/build/TableCommand.js +140 -0
- package/build/TestCommand copy.d.ts +5 -0
- package/build/TestCommand copy.js +111 -0
- package/build/TestCommand.d.ts +5 -0
- package/build/TestCommand.js +111 -0
- package/build/UserCommand.d.ts +5 -0
- package/build/UserCommand.js +202 -0
- package/build/console.d.ts +13 -0
- package/build/console.js +109 -0
- package/build/cykquery.d.ts +2 -0
- package/build/cykquery.js +145 -0
- package/build/cyktable.d.ts +2 -0
- package/build/cyktable.js +133 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +32 -0
- package/build/module.d.ts +2 -0
- package/build/module.js +290 -0
- package/docker-compose.ecs.yml +44 -0
- package/docker-compose.yml +43 -0
- package/docker.env +38 -0
- package/package.json +38 -0
- package/src/Cmd.ts +33 -0
- package/src/DBClient.ts +220 -0
- package/src/InitCommand.ts +107 -0
- package/src/ModuleCommand.ts +192 -0
- package/src/NodeCrypto.ts +60 -0
- package/src/QueryCommand.ts +62 -0
- package/src/RunCommand.ts +98 -0
- package/src/TableCommand.ts +127 -0
- package/src/TestCommand.ts +98 -0
- package/src/UserCommand.ts +203 -0
- package/src/console.ts +97 -0
- package/src/index.ts +30 -0
- package/tsconfig.json +12 -0
package/build/module.js
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
6
|
+
}) : (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
o[k2] = m[k];
|
|
9
|
+
}));
|
|
10
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
11
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12
|
+
}) : function(o, v) {
|
|
13
|
+
o["default"] = v;
|
|
14
|
+
});
|
|
15
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
16
|
+
if (mod && mod.__esModule) return mod;
|
|
17
|
+
var result = {};
|
|
18
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
19
|
+
__setModuleDefault(result, mod);
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const core_1 = require("@cyklang/core");
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const loglevel_1 = __importDefault(require("loglevel"));
|
|
29
|
+
const path_1 = __importDefault(require("path"));
|
|
30
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
31
|
+
const commander_1 = require("commander");
|
|
32
|
+
const NodeCrypto_1 = require("./NodeCrypto");
|
|
33
|
+
const logger = loglevel_1.default.getLogger("cykmodule.ts");
|
|
34
|
+
logger.setLevel("debug");
|
|
35
|
+
const program = new commander_1.Command();
|
|
36
|
+
program.name('cyk').description('manage modules in cyk_module table')
|
|
37
|
+
.version('0.2');
|
|
38
|
+
program.command('add').description('add modules')
|
|
39
|
+
.argument('<files...>', 'local module file(s) to upload to the server')
|
|
40
|
+
.option('-n --name <dbname>', 'module dbname')
|
|
41
|
+
.option('-d --desc <description>', 'description')
|
|
42
|
+
.option('-a --access <access>', 'access control list')
|
|
43
|
+
.option('-e --env <env>', 'path to the environment variables file')
|
|
44
|
+
.action(async (files, options) => {
|
|
45
|
+
await commandAdd(files, options);
|
|
46
|
+
});
|
|
47
|
+
program.command('update').description('update module')
|
|
48
|
+
.option('-i --id <id>', 'module ID')
|
|
49
|
+
.option('-n --name <dbname>', 'module dbname')
|
|
50
|
+
.option('-d --desc <description>', 'description')
|
|
51
|
+
.option('-a --access <access>', 'access control list')
|
|
52
|
+
.option('-e --env <env>', 'path to the environment variables file')
|
|
53
|
+
.argument('[files...]', 'local module file(s) to upload to the server')
|
|
54
|
+
.action(async (files, options) => {
|
|
55
|
+
await commandUpdate(files, options);
|
|
56
|
+
});
|
|
57
|
+
program.command('run').description('execute/run a local module file')
|
|
58
|
+
.argument('<file>', 'local module file to run')
|
|
59
|
+
.option('-e --env <env>', 'path to the environment variables file')
|
|
60
|
+
.action(async (file, options) => {
|
|
61
|
+
await commandRun(file, options);
|
|
62
|
+
});
|
|
63
|
+
const getDBManager = async () => {
|
|
64
|
+
const structure = new core_1.Structure();
|
|
65
|
+
if (process.env.DBREMOTE_URL === undefined)
|
|
66
|
+
throw 'DBREMOTE_URL undefined';
|
|
67
|
+
logger.debug('DBREMOTE_URL ' + process.env.DBREMOTE_URL);
|
|
68
|
+
const nodeCrypto = new NodeCrypto_1.NodeCrypto();
|
|
69
|
+
const dbRemote = new core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto);
|
|
70
|
+
const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
|
|
71
|
+
// logger.debug(login)
|
|
72
|
+
const dbManager = new core_1.DBManager(structure.scope, dbRemote);
|
|
73
|
+
await dbManager.initialize();
|
|
74
|
+
return dbManager;
|
|
75
|
+
};
|
|
76
|
+
const commandAdd = async (files, options) => {
|
|
77
|
+
// logger.debug('options : ', options, ', files : ', files)
|
|
78
|
+
try {
|
|
79
|
+
const dotenvOutput = dotenv_1.default.config({ path: options.env });
|
|
80
|
+
if (dotenvOutput.error !== undefined)
|
|
81
|
+
throw dotenvOutput.error;
|
|
82
|
+
const dbManager = await getDBManager();
|
|
83
|
+
if (options.id !== undefined)
|
|
84
|
+
throw '--id option is not available';
|
|
85
|
+
if (files.length === 0)
|
|
86
|
+
throw 'file(s) name(s) missing';
|
|
87
|
+
if (files.length > 1 && (options.name !== undefined))
|
|
88
|
+
throw '--name option cannot be specified with more than 1 file';
|
|
89
|
+
for (let ind = 0; ind < files.length; ind++) {
|
|
90
|
+
const file = files[ind];
|
|
91
|
+
const dbModule = new core_1.DBModule();
|
|
92
|
+
dbModule.source = fs.readFileSync(file).toString();
|
|
93
|
+
dbModule.dbname = path_1.default.basename(file, '.xml');
|
|
94
|
+
if (options.name !== undefined)
|
|
95
|
+
dbModule.dbname = options.name;
|
|
96
|
+
if (options.desc !== undefined)
|
|
97
|
+
dbModule.description = options.desc;
|
|
98
|
+
if (options.access !== undefined)
|
|
99
|
+
dbModule.access = options.access;
|
|
100
|
+
const moduleExist = await dbManager.dbModuleExist(dbModule.dbname);
|
|
101
|
+
if (moduleExist !== undefined)
|
|
102
|
+
throw 'module ' + moduleExist.dbname + ' already exists with id ' + moduleExist.id;
|
|
103
|
+
const id = await dbManager.dbModuleInsert(dbModule);
|
|
104
|
+
logger.info('module ' + dbModule.dbname + ' added with id ' + id);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
logger.error(err);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const commandUpdate = async (files, options) => {
|
|
112
|
+
// logger.debug('files : ', files, ', options : ', options)
|
|
113
|
+
try {
|
|
114
|
+
const dotenvOutput = dotenv_1.default.config({ path: options.env });
|
|
115
|
+
if (dotenvOutput.error !== undefined)
|
|
116
|
+
throw dotenvOutput.error;
|
|
117
|
+
const dbManager = await getDBManager();
|
|
118
|
+
if (options.id !== undefined) {
|
|
119
|
+
if (files.length > 1)
|
|
120
|
+
throw 'with --id option you can only specify 1 local file';
|
|
121
|
+
const dbModule = await dbManager.getModule(options.id);
|
|
122
|
+
if (options.name !== undefined)
|
|
123
|
+
dbModule.dbname = options.name;
|
|
124
|
+
if (options.desc !== undefined)
|
|
125
|
+
dbModule.description = options.desc;
|
|
126
|
+
if (options.access !== undefined)
|
|
127
|
+
dbModule.access = options.access;
|
|
128
|
+
if (files.length === 1) {
|
|
129
|
+
dbModule.source = fs.readFileSync(files[0]).toString();
|
|
130
|
+
}
|
|
131
|
+
await dbManager.dbModuleUpdate(dbModule);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
if (files.length === 0)
|
|
135
|
+
throw 'without --id option you need to specify at least 1 local file';
|
|
136
|
+
for (let ind = 0; ind < files.length; ind++) {
|
|
137
|
+
const file = files[ind];
|
|
138
|
+
const dbname = path_1.default.basename(file, '.xml');
|
|
139
|
+
const dbModule = await dbManager.dbModuleExist(dbname);
|
|
140
|
+
if (dbModule === undefined) {
|
|
141
|
+
logger.info('local file ' + file + ', module ' + dbname + ' not found');
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
dbModule.source = fs.readFileSync(file).toString();
|
|
145
|
+
logger.debug('dbModule update from ' + file);
|
|
146
|
+
if (options.desc !== undefined)
|
|
147
|
+
dbModule.description = options.desc;
|
|
148
|
+
if (options.access !== undefined)
|
|
149
|
+
dbModule.access = options.access;
|
|
150
|
+
await dbManager.dbModuleUpdate(dbModule);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
logger.error(err);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const commandRun = async (file, options) => {
|
|
159
|
+
try {
|
|
160
|
+
logger.debug('options', options);
|
|
161
|
+
const dotenvOutput = dotenv_1.default.config({ path: options.env });
|
|
162
|
+
if (dotenvOutput.error !== undefined)
|
|
163
|
+
throw dotenvOutput.error;
|
|
164
|
+
const dbManager = await getDBManager();
|
|
165
|
+
const source = fs.readFileSync(file).toString();
|
|
166
|
+
const tag = (0, core_1.parseXML)(file, source);
|
|
167
|
+
const moduleInstruction = new core_1.ModuleInstruction(tag, dbManager);
|
|
168
|
+
const scopeRun = new core_1.Scope(dbManager.scope.structure, dbManager.scope, undefined);
|
|
169
|
+
await moduleInstruction.parseInstructions(tag, scopeRun);
|
|
170
|
+
await moduleInstruction.execute(scopeRun);
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
logger.error(err);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
program.parse();
|
|
177
|
+
// const main = async () => {
|
|
178
|
+
// const { command, filepath, basename } = parseCommandLine()
|
|
179
|
+
// const xmlSource = fs.readFileSync(filepath).toString()
|
|
180
|
+
// let dbModule: DBModule | undefined
|
|
181
|
+
// let tag = parseXmlFile(filepath, basename, xmlSource)
|
|
182
|
+
// if (command === Command.Test || command === Command.TestSave) {
|
|
183
|
+
// dbModule = await testXml(structure, tag)
|
|
184
|
+
// }
|
|
185
|
+
// else if (command === Command.Save) {
|
|
186
|
+
// dbModule = await dbManager.dbModuleExist(tag.attributes.DBNAME)
|
|
187
|
+
// if (dbModule === undefined) {
|
|
188
|
+
// dbModule = new DBModule(tag.attributes.DBNAME)
|
|
189
|
+
// }
|
|
190
|
+
// }
|
|
191
|
+
// if (dbModule !== undefined && (command === Command.Save || command === Command.TestSave)) {
|
|
192
|
+
// dbModule.source = xmlSource
|
|
193
|
+
// await saveModule(dbManager, dbModule)
|
|
194
|
+
// }
|
|
195
|
+
// }
|
|
196
|
+
// main().then(() => logger.debug('finished'))
|
|
197
|
+
// enum Command {
|
|
198
|
+
// Test = 'test',
|
|
199
|
+
// Save = 'save',
|
|
200
|
+
// TestSave = 'testsave'
|
|
201
|
+
// }
|
|
202
|
+
// function syntax() {
|
|
203
|
+
// console.log(`
|
|
204
|
+
// ----------------------------------------------------------------------------------
|
|
205
|
+
// cykmodule writes a module file to the server (DBREMOTE_URL environment variable)
|
|
206
|
+
// syntax :
|
|
207
|
+
// cykmodule [ save | test | testsave ] filename
|
|
208
|
+
// cykmodule filename ( option testsave if omitted )
|
|
209
|
+
// ----------------------------------------------------------------------------------
|
|
210
|
+
// `)
|
|
211
|
+
// }
|
|
212
|
+
// function parseCommandLine(): { command: Command, filepath: string, basename: string } {
|
|
213
|
+
// let command = Command.TestSave
|
|
214
|
+
// let filepath
|
|
215
|
+
// if (process.argv.length < 3 || process.argv.length > 4) {
|
|
216
|
+
// syntax()
|
|
217
|
+
// throw Error('nb of command line arguments : ' + process.argv.length)
|
|
218
|
+
// }
|
|
219
|
+
// if (process.argv.length === 3) {
|
|
220
|
+
// filepath = process.argv[2]
|
|
221
|
+
// command = Command.TestSave
|
|
222
|
+
// }
|
|
223
|
+
// else {
|
|
224
|
+
// const option = process.argv[2].toLowerCase()
|
|
225
|
+
// if ( option === 'test' || option === 'save' || option === 'testsave') {
|
|
226
|
+
// command = <Command> option
|
|
227
|
+
// }
|
|
228
|
+
// else {
|
|
229
|
+
// syntax()
|
|
230
|
+
// throw Error('command unknown ' + process.argv[2])
|
|
231
|
+
// }
|
|
232
|
+
// filepath = process.argv[3]
|
|
233
|
+
// }
|
|
234
|
+
// logger.trace('dbmodule filepath : ' + filepath)
|
|
235
|
+
// const basename = path.basename(filepath)
|
|
236
|
+
// const extname = path.extname(filepath)
|
|
237
|
+
// logger.trace('basename ' + basename + ', extname ' + extname)
|
|
238
|
+
// if (extname.toLowerCase() !== '.xml') {
|
|
239
|
+
// throw Error('filepath argument ' + filepath + ' should have xml extension')
|
|
240
|
+
// }
|
|
241
|
+
// return { command, filepath, basename }
|
|
242
|
+
// }
|
|
243
|
+
function parseXmlFile(filepath, basename, xmlSource) {
|
|
244
|
+
const tag = (0, core_1.parseXML)(filepath, xmlSource);
|
|
245
|
+
if (tag.name !== 'MODULE') {
|
|
246
|
+
throw Error('tag ' + tag.name + ', should be <module>');
|
|
247
|
+
}
|
|
248
|
+
const dbname = tag.attributes.DBNAME;
|
|
249
|
+
// if (dbname === undefined) {
|
|
250
|
+
// throw Error('dbname attribute is missing')
|
|
251
|
+
// }
|
|
252
|
+
if (dbname !== undefined && basename !== dbname + '.xml') {
|
|
253
|
+
throw Error('filename ' + filepath + ' and dbname ' + dbname + ' do not correspond');
|
|
254
|
+
}
|
|
255
|
+
return tag;
|
|
256
|
+
}
|
|
257
|
+
async function testXml(structure, tag) {
|
|
258
|
+
let result;
|
|
259
|
+
try {
|
|
260
|
+
logger.debug('testXml dbname : ' + tag.attributes.DBNAME);
|
|
261
|
+
// structure.setInstructionType("print", new PrintInstructionType(logfilename))
|
|
262
|
+
const moduleInstructionType = structure.scope.getInstructionType('module');
|
|
263
|
+
if (moduleInstructionType === undefined) {
|
|
264
|
+
throw Error('moduleInstructionType not found');
|
|
265
|
+
}
|
|
266
|
+
const scopeParse = new core_1.Scope(structure, structure.scope, undefined);
|
|
267
|
+
const moduleInst = await moduleInstructionType.parseInstruction(tag, scopeParse);
|
|
268
|
+
const scopeExecute = new core_1.Scope(structure, structure.scope, undefined);
|
|
269
|
+
await moduleInst.execute(scopeExecute);
|
|
270
|
+
result = moduleInst.dbModule;
|
|
271
|
+
// if (result === undefined) {
|
|
272
|
+
// throw Error('moduleInst.dbModule undefined')
|
|
273
|
+
// }
|
|
274
|
+
}
|
|
275
|
+
catch (err) {
|
|
276
|
+
logger.error(err);
|
|
277
|
+
}
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
280
|
+
async function saveModule(dbManager, dbModule) {
|
|
281
|
+
logger.debug('saveModule ' + dbModule.dbname + ', description ; ' + dbModule.description);
|
|
282
|
+
if (dbModule.id === undefined) {
|
|
283
|
+
// dbModuleInsert
|
|
284
|
+
await dbManager.dbModuleInsert(dbModule);
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
// dbModuleUpdate
|
|
288
|
+
await dbManager.dbModuleUpdate(dbModule);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
version: "3.9"
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
|
|
5
|
+
postgres:
|
|
6
|
+
image: postgres
|
|
7
|
+
environment:
|
|
8
|
+
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
|
9
|
+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
|
10
|
+
ports:
|
|
11
|
+
- "${PGPORT}:5432"
|
|
12
|
+
volumes:
|
|
13
|
+
- db:/var/lib/postgresql/data
|
|
14
|
+
|
|
15
|
+
nodejs:
|
|
16
|
+
image: pchaneyo/cyk-nodejs
|
|
17
|
+
environment:
|
|
18
|
+
ADMIN_NAME: ${ADMIN_NAME}
|
|
19
|
+
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
|
|
20
|
+
ADMIN_EMAIL: ${ADMIN_EMAIL}
|
|
21
|
+
# DATABASE_URL: "postgres://postgres:postgres@postgres:5432/postgres?sslmode=disable"
|
|
22
|
+
PGHOST: "postgres"
|
|
23
|
+
PGPORT: "5432"
|
|
24
|
+
PGUSER: ${POSTGRES_USER:-postgres}
|
|
25
|
+
PGPASSWORD: ${POSTGRES_PASSWORD}
|
|
26
|
+
SECRET_TOKEN: ${SECRET_TOKEN? SECRET_TOKEN environment variable is missing}
|
|
27
|
+
SECRET_RTOKEN: ${SECRET_RTOKEN? SECRET_RTOKEN environment variable is missing}
|
|
28
|
+
# Login Page Config
|
|
29
|
+
LOGIN_IMAGE: ${LOGIN_IMAGE}
|
|
30
|
+
LOGIN_TITLE: ${LOGIN_TITLE}
|
|
31
|
+
LOGIN_SUBTITLE: ${LOGIN_SUBTITLE}
|
|
32
|
+
LOGIN_APPLI: ${LOGIN_APPLI}
|
|
33
|
+
# PGSSLMODE: "disable"
|
|
34
|
+
depends_on:
|
|
35
|
+
- postgres
|
|
36
|
+
ports:
|
|
37
|
+
- "${CYK_PORT}:3000"
|
|
38
|
+
|
|
39
|
+
volumes:
|
|
40
|
+
db:
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
version: "3.9"
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
|
|
5
|
+
postgres:
|
|
6
|
+
image: postgres
|
|
7
|
+
environment:
|
|
8
|
+
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
|
9
|
+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
|
10
|
+
ports:
|
|
11
|
+
- "${PGPORT}:5432"
|
|
12
|
+
volumes:
|
|
13
|
+
- db:/var/lib/postgre
|
|
14
|
+
nodejs:
|
|
15
|
+
image: pchaneyo/cyk-nodejs
|
|
16
|
+
environment:
|
|
17
|
+
ADMIN_NAME: ${ADMIN_NAME}
|
|
18
|
+
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
|
|
19
|
+
ADMIN_EMAIL: ${ADMIN_EMAIL}
|
|
20
|
+
# DATABASE_URL: "postgres://postgres:postgres@postgres:5432/postgres?sslmode=disable"
|
|
21
|
+
PGHOST: "postgres"
|
|
22
|
+
PGPORT: "5432"
|
|
23
|
+
PGUSER: ${POSTGRES_USER:-postgres}
|
|
24
|
+
PGPASSWORD: ${POSTGRES_PASSWORD}
|
|
25
|
+
SECRET_TOKEN: ${SECRET_TOKEN? SECRET_TOKEN environment variable is missing}
|
|
26
|
+
SECRET_RTOKEN: ${SECRET_RTOKEN? SECRET_RTOKEN environment variable is missing}
|
|
27
|
+
# Login Page Config
|
|
28
|
+
LOGIN_IMAGE: ${LOGIN_IMAGE}
|
|
29
|
+
LOGIN_TITLE: ${LOGIN_TITLE}
|
|
30
|
+
LOGIN_SUBTITLE: ${LOGIN_SUBTITLE}
|
|
31
|
+
LOGIN_APPLI: ${LOGIN_APPLI}
|
|
32
|
+
# PGSSLMODE: "disable"
|
|
33
|
+
depends_on:
|
|
34
|
+
- postgres
|
|
35
|
+
ports:
|
|
36
|
+
- "${CYK_PORT}:3000"
|
|
37
|
+
|
|
38
|
+
volumes:
|
|
39
|
+
db:
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
package/docker.env
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# PostgreSql connection
|
|
2
|
+
# used by psql command line utility
|
|
3
|
+
PGHOST="localhost"
|
|
4
|
+
PGPORT="4321"
|
|
5
|
+
PGUSER="postgres"
|
|
6
|
+
PGPASSWORD="postgres"
|
|
7
|
+
|
|
8
|
+
# at postgresql database initialization
|
|
9
|
+
|
|
10
|
+
# POSTGRES_USER="postgres"
|
|
11
|
+
POSTGRES_PASSWORD="postgres"
|
|
12
|
+
|
|
13
|
+
# admin user
|
|
14
|
+
# created at database initialization
|
|
15
|
+
ADMIN_NAME=cyk
|
|
16
|
+
ADMIN_PASSWORD=cyk
|
|
17
|
+
ADMIN_EMAIL=my-email@my-domain
|
|
18
|
+
|
|
19
|
+
# JWT token generation
|
|
20
|
+
# https://www.allkeysgenerator.com
|
|
21
|
+
# 128 bits Hex
|
|
22
|
+
|
|
23
|
+
SECRET_TOKEN="423F4428472B4B6250655368566D5971"
|
|
24
|
+
SECRET_RTOKEN="743777217A25432A46294A404E635266"
|
|
25
|
+
|
|
26
|
+
# Login Page Config
|
|
27
|
+
LOGIN_IMAGE="https://media.smartbox.com/pim/1000001967971201770883.jpg?thumbor=800x0/filters:quality(90)"
|
|
28
|
+
LOGIN_TITLE="CYK Framework"
|
|
29
|
+
LOGIN_SUBTITLE="Une application pilote du framework CYK"
|
|
30
|
+
LOGIN_APPLI="accounting"
|
|
31
|
+
|
|
32
|
+
# credential used by cyk CLI
|
|
33
|
+
|
|
34
|
+
USER_NAME=cyk
|
|
35
|
+
USER_PASSWORD=cyk
|
|
36
|
+
CYK_PORT="3000"
|
|
37
|
+
DBREMOTE_URL="http://localhost:3000"
|
|
38
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cyklang/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "cyklang CLI",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"global": "npm run build && npm i -g",
|
|
9
|
+
"local": "sudo npm uninstall -g && sudo npm install -g && cyk",
|
|
10
|
+
"npm:format": "npx prettier-package-json --write package.json",
|
|
11
|
+
"npm:upgrade": "npx npm-check-updates -iu",
|
|
12
|
+
"refresh": "rm -rf ./node_modules ./package-lock.json && npm install",
|
|
13
|
+
"dev": "nodemon -e ts --ignore build --exec \"npm run global\" ",
|
|
14
|
+
"test": "sudo npm i -g && cyk"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"author": "",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@cyklang/core": "^0.3.4",
|
|
21
|
+
"commander": "^9.4.0",
|
|
22
|
+
"dotenv": "^16.0.1",
|
|
23
|
+
"loglevel": "^1.8.0",
|
|
24
|
+
"pako": "^2.0.4",
|
|
25
|
+
"xml": "^1.0.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/pako": "^2.0.0",
|
|
29
|
+
"@types/sax": "^1.2.4",
|
|
30
|
+
"@types/xml": "^1.0.8",
|
|
31
|
+
"nodemon": "^2.0.16",
|
|
32
|
+
"ts-node": "^10.7.0",
|
|
33
|
+
"typescript": "4.5.2"
|
|
34
|
+
},
|
|
35
|
+
"bin": {
|
|
36
|
+
"cyk": "build/index.js"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/Cmd.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { DBManager, DBRemote, Structure } from "@cyklang/core";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import dotenv from 'dotenv'
|
|
4
|
+
import loglevel from 'loglevel'
|
|
5
|
+
import { NodeCrypto } from "./NodeCrypto";
|
|
6
|
+
const logger = loglevel.getLogger('Cmd.ts')
|
|
7
|
+
logger.setLevel('debug')
|
|
8
|
+
|
|
9
|
+
export class Cmd extends Command {
|
|
10
|
+
dbManager: DBManager | undefined
|
|
11
|
+
|
|
12
|
+
constructor(name: string) {
|
|
13
|
+
super(name);
|
|
14
|
+
this.option('--env <env>', 'path to the environment variables file')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async prologue(options: any) {
|
|
18
|
+
|
|
19
|
+
const dotenvOutput = dotenv.config({path: options.env})
|
|
20
|
+
if (dotenvOutput.error !== undefined) throw dotenvOutput.error
|
|
21
|
+
|
|
22
|
+
const structure = new Structure()
|
|
23
|
+
if (process.env.DBREMOTE_URL === undefined) throw 'DBREMOTE_URL undefined'
|
|
24
|
+
logger.debug('DBREMOTE_URL ' + process.env.DBREMOTE_URL)
|
|
25
|
+
const nodeCrypto = new NodeCrypto()
|
|
26
|
+
const dbRemote = new DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto)
|
|
27
|
+
const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD)
|
|
28
|
+
// logger.debug(login)
|
|
29
|
+
|
|
30
|
+
this.dbManager = new DBManager(structure.scope, dbRemote)
|
|
31
|
+
await this.dbManager.initialize()
|
|
32
|
+
}
|
|
33
|
+
}
|