@rws-framework/db 2.3.2 → 2.4.1
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/add-v.sh +9 -9
- package/.bin/emerge.sh +10 -10
- package/.eslintrc.json +53 -53
- package/README.md +404 -367
- package/dist/decorators/InverseRelation.d.ts +0 -0
- package/dist/decorators/InverseRelation.js +0 -0
- package/dist/decorators/InverseTimeSeries.d.ts +0 -0
- package/dist/decorators/InverseTimeSeries.js +0 -0
- package/dist/decorators/RWSCollection.d.ts +0 -0
- package/dist/decorators/RWSCollection.js +0 -0
- package/dist/decorators/Relation.d.ts +0 -0
- package/dist/decorators/Relation.js +0 -0
- package/dist/decorators/TrackType.d.ts +0 -0
- package/dist/decorators/TrackType.js +0 -0
- package/dist/decorators/index.d.ts +0 -0
- package/dist/decorators/index.js +0 -0
- package/dist/helper/DbHelper.d.ts +0 -0
- package/dist/helper/DbHelper.js +7 -7
- package/dist/helper/FieldsHelper.d.ts +0 -0
- package/dist/helper/FieldsHelper.js +0 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/models/TimeSeriesModel.d.ts +7 -7
- package/dist/models/TimeSeriesModel.js +33 -33
- package/dist/models/_model.d.ts +0 -0
- package/dist/models/_model.js +0 -0
- package/dist/models/core/RWSModel.d.ts +0 -0
- package/dist/models/core/RWSModel.js +0 -0
- package/dist/models/core/TimeSeriesModel.d.ts +0 -0
- package/dist/models/core/TimeSeriesModel.js +0 -0
- package/dist/models/index.d.ts +0 -0
- package/dist/models/index.js +0 -0
- package/dist/models/interfaces/IModel.d.ts +0 -0
- package/dist/models/interfaces/IModel.js +0 -0
- package/dist/models/interfaces/IRWSModelServices.d.ts +0 -0
- package/dist/models/interfaces/IRWSModelServices.js +0 -0
- package/dist/models/interfaces/OpModelType.d.ts +0 -0
- package/dist/models/interfaces/OpModelType.js +0 -0
- package/dist/models/types/RelationTypes.d.ts +0 -0
- package/dist/models/types/RelationTypes.js +0 -0
- package/dist/models/utils/ModelUtils.d.ts +0 -0
- package/dist/models/utils/ModelUtils.js +0 -0
- package/dist/models/utils/PaginationUtils.d.ts +0 -0
- package/dist/models/utils/PaginationUtils.js +0 -0
- package/dist/models/utils/RelationUtils.d.ts +0 -0
- package/dist/models/utils/RelationUtils.js +0 -0
- package/dist/models/utils/TimeSeriesUtils.d.ts +0 -0
- package/dist/models/utils/TimeSeriesUtils.js +0 -0
- package/dist/services/DBService.d.ts +1 -1
- package/dist/services/DBService.js +6 -6
- package/dist/types/DbConfigHandler.d.ts +3 -2
- package/dist/types/DbConfigHandler.js +0 -0
- package/dist/types/FindParams.d.ts +0 -0
- package/dist/types/FindParams.js +0 -0
- package/dist/types/IRWSModel.d.ts +0 -0
- package/dist/types/IRWSModel.js +0 -0
- package/dist/types/ITimeSeries.d.ts +0 -0
- package/dist/types/ITimeSeries.js +0 -0
- package/exec/console.js +110 -110
- package/exec/db.rws.webpack.config.js +168 -168
- package/exec/src/cli.ts +75 -73
- package/exec/tsconfig.json +32 -32
- package/exec/webpackFilters.js +17 -17
- package/package.json +36 -36
- package/src/decorators/InverseRelation.ts +36 -36
- package/src/decorators/InverseTimeSeries.ts +21 -21
- package/src/decorators/RWSCollection.ts +27 -27
- package/src/decorators/Relation.ts +47 -47
- package/src/decorators/TrackType.ts +69 -69
- package/src/decorators/index.ts +7 -7
- package/src/empty.js +0 -0
- package/src/helper/DbHelper.ts +177 -177
- package/src/helper/FieldsHelper.ts +34 -34
- package/src/index.ts +36 -36
- package/src/models/_model.ts +29 -29
- package/src/models/core/RWSModel.ts +520 -520
- package/src/models/core/TimeSeriesModel.ts +19 -19
- package/src/models/index.ts +20 -20
- package/src/models/interfaces/IModel.ts +12 -12
- package/src/models/interfaces/IRWSModelServices.ts +7 -7
- package/src/models/interfaces/OpModelType.ts +49 -49
- package/src/models/types/RelationTypes.ts +25 -25
- package/src/models/utils/ModelUtils.ts +65 -65
- package/src/models/utils/PaginationUtils.ts +42 -42
- package/src/models/utils/RelationUtils.ts +76 -76
- package/src/models/utils/TimeSeriesUtils.ts +38 -38
- package/src/services/DBService.ts +277 -277
- package/src/types/DbConfigHandler.ts +12 -11
- package/src/types/FindParams.ts +13 -13
- package/src/types/IRWSModel.ts +2 -2
- package/src/types/ITimeSeries.ts +5 -5
- package/tsconfig.json +22 -22
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/decorators/index.js
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/helper/DbHelper.js
CHANGED
|
@@ -14,14 +14,14 @@ const workspaceRoot = console_1.rwsPath.findRootWorkspacePath();
|
|
|
14
14
|
const moduleDir = path_1.default.resolve(workspaceRoot, 'node_modules', '@rws-framework', 'db');
|
|
15
15
|
class DbHelper {
|
|
16
16
|
static async installPrisma(configService, dbService, leaveFile = false) {
|
|
17
|
-
const dbUrl = configService.get('
|
|
18
|
-
const dbType = 'mongodb';
|
|
19
|
-
let template = `generator client {\n
|
|
20
|
-
provider = "prisma-client-js"\n
|
|
17
|
+
const dbUrl = configService.get('db_url');
|
|
18
|
+
const dbType = configService.get('db_type') || 'mongodb';
|
|
19
|
+
let template = `generator client {\n
|
|
20
|
+
provider = "prisma-client-js"\n
|
|
21
21
|
}\n\n`;
|
|
22
|
-
template += `\ndatasource db {\n
|
|
23
|
-
provider = "${dbType}"\n
|
|
24
|
-
url = env("
|
|
22
|
+
template += `\ndatasource db {\n
|
|
23
|
+
provider = "${dbType}"\n
|
|
24
|
+
url = env("PRISMA_DB_URL")\n
|
|
25
25
|
}\n\n`;
|
|
26
26
|
const dbModels = configService.get('db_models');
|
|
27
27
|
if (dbModels) {
|
|
File without changes
|
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
File without changes
|
package/dist/index.js
CHANGED
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { RWSModel } from './_model';
|
|
2
|
-
export default class TimeSeriesModel<ChildClass> extends RWSModel<TimeSeriesModel<ChildClass>> {
|
|
3
|
-
value: number;
|
|
4
|
-
timestamp: Date;
|
|
5
|
-
params: any;
|
|
6
|
-
constructor(data?: any);
|
|
7
|
-
}
|
|
1
|
+
import { RWSModel } from './_model';
|
|
2
|
+
export default class TimeSeriesModel<ChildClass> extends RWSModel<TimeSeriesModel<ChildClass>> {
|
|
3
|
+
value: number;
|
|
4
|
+
timestamp: Date;
|
|
5
|
+
params: any;
|
|
6
|
+
constructor(data?: any);
|
|
7
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const _model_1 = require("./_model");
|
|
13
|
-
class TimeSeriesModel extends _model_1.RWSModel {
|
|
14
|
-
constructor(data) {
|
|
15
|
-
super(data);
|
|
16
|
-
if (!this.timestamp) {
|
|
17
|
-
this.timestamp = new Date();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.default = TimeSeriesModel;
|
|
22
|
-
__decorate([
|
|
23
|
-
(0, _model_1.TrackType)(Number),
|
|
24
|
-
__metadata("design:type", Number)
|
|
25
|
-
], TimeSeriesModel.prototype, "value", void 0);
|
|
26
|
-
__decorate([
|
|
27
|
-
(0, _model_1.TrackType)(Date),
|
|
28
|
-
__metadata("design:type", Date)
|
|
29
|
-
], TimeSeriesModel.prototype, "timestamp", void 0);
|
|
30
|
-
__decorate([
|
|
31
|
-
(0, _model_1.TrackType)(Object),
|
|
32
|
-
__metadata("design:type", Object)
|
|
33
|
-
], TimeSeriesModel.prototype, "params", void 0);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const _model_1 = require("./_model");
|
|
13
|
+
class TimeSeriesModel extends _model_1.RWSModel {
|
|
14
|
+
constructor(data) {
|
|
15
|
+
super(data);
|
|
16
|
+
if (!this.timestamp) {
|
|
17
|
+
this.timestamp = new Date();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = TimeSeriesModel;
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, _model_1.TrackType)(Number),
|
|
24
|
+
__metadata("design:type", Number)
|
|
25
|
+
], TimeSeriesModel.prototype, "value", void 0);
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, _model_1.TrackType)(Date),
|
|
28
|
+
__metadata("design:type", Date)
|
|
29
|
+
], TimeSeriesModel.prototype, "timestamp", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, _model_1.TrackType)(Object),
|
|
32
|
+
__metadata("design:type", Object)
|
|
33
|
+
], TimeSeriesModel.prototype, "params", void 0);
|
package/dist/models/_model.d.ts
CHANGED
|
File without changes
|
package/dist/models/_model.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/models/index.d.ts
CHANGED
|
File without changes
|
package/dist/models/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -2,7 +2,7 @@ import { Collection, Db, MongoClient } from 'mongodb';
|
|
|
2
2
|
import { ITimeSeries } from '../types/ITimeSeries';
|
|
3
3
|
import { IModel } from '../models/interfaces/IModel';
|
|
4
4
|
import { IDbConfigHandler } from '../types/DbConfigHandler';
|
|
5
|
-
import { IPaginationParams } from '
|
|
5
|
+
import { IPaginationParams } from '../types/FindParams';
|
|
6
6
|
interface IDBClientCreate {
|
|
7
7
|
dbUrl?: string;
|
|
8
8
|
dbName?: string;
|
|
@@ -19,8 +19,8 @@ class DBService {
|
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
21
|
this.opts = {
|
|
22
|
-
dbUrl: this.configService.get('
|
|
23
|
-
dbName: this.configService.get('
|
|
22
|
+
dbUrl: this.configService.get('db_url'),
|
|
23
|
+
dbName: this.configService.get('db_name'),
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
if (!this.opts.dbUrl) {
|
|
@@ -51,14 +51,14 @@ class DBService {
|
|
|
51
51
|
}
|
|
52
52
|
async createBaseMongoClient() {
|
|
53
53
|
var _a;
|
|
54
|
-
const dbUrl = ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.dbUrl) || this.configService.get('
|
|
54
|
+
const dbUrl = ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.dbUrl) || this.configService.get('db_url');
|
|
55
55
|
const client = DBService.baseClientConstruct(dbUrl);
|
|
56
56
|
await client.connect();
|
|
57
57
|
return client;
|
|
58
58
|
}
|
|
59
59
|
async createBaseMongoClientDB() {
|
|
60
60
|
var _a;
|
|
61
|
-
const dbName = ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.dbName) || this.configService.get('
|
|
61
|
+
const dbName = ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.dbName) || this.configService.get('db_name');
|
|
62
62
|
const client = await this.createBaseMongoClient();
|
|
63
63
|
return [client, client.db(dbName)];
|
|
64
64
|
}
|
|
@@ -152,11 +152,11 @@ class DBService {
|
|
|
152
152
|
}
|
|
153
153
|
async collectionExists(collection_name) {
|
|
154
154
|
var _a;
|
|
155
|
-
const dbUrl = ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.dbUrl) || this.configService.get('
|
|
155
|
+
const dbUrl = ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.dbUrl) || this.configService.get('db_url');
|
|
156
156
|
const client = new mongodb_1.MongoClient(dbUrl);
|
|
157
157
|
try {
|
|
158
158
|
await client.connect();
|
|
159
|
-
const db = client.db(this.configService.get('
|
|
159
|
+
const db = client.db(this.configService.get('db_name'));
|
|
160
160
|
const collections = await db.listCollections().toArray();
|
|
161
161
|
const existingCollectionNames = collections.map((collection) => collection.name);
|
|
162
162
|
return existingCollectionNames.includes(collection_name);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { OpModelType } from "../models/interfaces/OpModelType";
|
|
2
2
|
export interface IDbConfigParams {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
db_url?: string;
|
|
4
|
+
db_name?: string;
|
|
5
|
+
db_type?: string;
|
|
5
6
|
db_models?: OpModelType<any>[];
|
|
6
7
|
}
|
|
7
8
|
export interface IDbConfigHandler {
|
|
File without changes
|
|
File without changes
|
package/dist/types/FindParams.js
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/types/IRWSModel.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/exec/console.js
CHANGED
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { rwsShell, rwsPath } = require('@rws-framework/console');
|
|
4
|
-
const chalk = require('chalk');
|
|
5
|
-
const crypto = require('crypto');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
|
|
9
|
-
const params = process.argv.splice(2);
|
|
10
|
-
let paramsString = params.length ? (' ' + params.join(' ')) : '';
|
|
11
|
-
|
|
12
|
-
const appRoot = process.cwd();
|
|
13
|
-
const rwsCliConfigDir = path.resolve(appRoot, 'node_modules', '.rws', 'cli');
|
|
14
|
-
const getCachedPath = (key) => path.resolve(rwsCliConfigDir, key);
|
|
15
|
-
|
|
16
|
-
const currentCwd = path.resolve(__dirname);
|
|
17
|
-
|
|
18
|
-
console.log({params})
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const commandString = `npx webpack --config db.rws.webpack.config.js --output-path ./build ${process.cwd()} ${params[2]}`;
|
|
22
|
-
function needsCacheWarming(){
|
|
23
|
-
|
|
24
|
-
if(!fs.existsSync(getCachedPath('paths')) || !fs.existsSync(getCachedPath('checksum'))){
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const fileList = fs.readFileSync(getCachedPath('paths'), 'utf-8').split('\n');
|
|
29
|
-
|
|
30
|
-
if(fileList.length){
|
|
31
|
-
const fileContents = [];
|
|
32
|
-
for(const filePath of fileList){
|
|
33
|
-
if(fs.existsSync(filePath)){
|
|
34
|
-
fileContents.push(fs.readFileSync(filePath, 'utf-8'));
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const finalMD5 = crypto.createHash('md5').update(fileContents.join('\n')).digest('hex');
|
|
38
|
-
const cachedMD5 = fs.readFileSync(getCachedPath('checksum'), 'utf-8');
|
|
39
|
-
|
|
40
|
-
if(finalMD5 === cachedMD5){
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async function main()
|
|
49
|
-
{
|
|
50
|
-
const hasRebuild = paramsString.split(' ').pop().indexOf('--rebuild') > -1;
|
|
51
|
-
const doWarmCache = needsCacheWarming() || hasRebuild;
|
|
52
|
-
|
|
53
|
-
if(!((params[0] || false) && (params[1] || false) && (params[2] || false))){
|
|
54
|
-
throw new Error(`CLI command MUST have 3 parameters: {DB_URL, DB_NAME, MODELS_DIR}`);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if(doWarmCache){
|
|
58
|
-
console.log(chalk.yellow('[RWS DB CLI] Building CLI client...'));
|
|
59
|
-
|
|
60
|
-
const cacheTypes = ['paths', 'checksum'];
|
|
61
|
-
|
|
62
|
-
for(const type of cacheTypes){
|
|
63
|
-
if(fs.existsSync(getCachedPath(type))){
|
|
64
|
-
fs.unlinkSync(getCachedPath(type));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
await tsc();
|
|
69
|
-
|
|
70
|
-
await rwsShell.runCommand(commandString, currentCwd);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}else{
|
|
74
|
-
console.log(chalk.blue('[RWS CLI CACHE] Starting command from built CLI client.'));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
let startSlice = hasRebuild ? -1 : paramsString.split(' ').length;
|
|
78
|
-
let endSlice = hasRebuild ? -1 : null ;
|
|
79
|
-
|
|
80
|
-
paramsString = [
|
|
81
|
-
...paramsString.split(' ').slice(0, startSlice),
|
|
82
|
-
currentCwd,
|
|
83
|
-
endSlice ?
|
|
84
|
-
paramsString.split(' ').at(endSlice)
|
|
85
|
-
: null
|
|
86
|
-
].filter((item) => item !== null).join(' ');
|
|
87
|
-
|
|
88
|
-
await rwsShell.runCommand(`node ${path.join(currentCwd, 'build', 'main.cli.rws.js')}${paramsString}`, process.cwd());
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async function tsc (){
|
|
92
|
-
const tempConfigContent = {
|
|
93
|
-
"extends": "./tsconfig.json",
|
|
94
|
-
"include": [
|
|
95
|
-
path.join(process.cwd(), params[2], 'index.ts')
|
|
96
|
-
],
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const tempConfigPath = path.join(currentCwd, '.tmp.gitignore.json');
|
|
100
|
-
fs.writeFileSync(tempConfigPath, JSON.stringify(tempConfigContent, null, 2));
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
await rwsShell.runCommand(`tsc -p ${tempConfigPath}`, currentCwd);
|
|
104
|
-
fs.unlinkSync(tempConfigPath);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
main().then((data) => {
|
|
108
|
-
console.log(chalk.green('[RWS DB CLI] Command complete.'));
|
|
109
|
-
}).catch((e) => {
|
|
110
|
-
console.error(e.message);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { rwsShell, rwsPath } = require('@rws-framework/console');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
const crypto = require('crypto');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
|
|
9
|
+
const params = process.argv.splice(2);
|
|
10
|
+
let paramsString = params.length ? (' ' + params.join(' ')) : '';
|
|
11
|
+
|
|
12
|
+
const appRoot = process.cwd();
|
|
13
|
+
const rwsCliConfigDir = path.resolve(appRoot, 'node_modules', '.rws', 'cli');
|
|
14
|
+
const getCachedPath = (key) => path.resolve(rwsCliConfigDir, key);
|
|
15
|
+
|
|
16
|
+
const currentCwd = path.resolve(__dirname);
|
|
17
|
+
|
|
18
|
+
console.log({params})
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const commandString = `npx webpack --config db.rws.webpack.config.js --output-path ./build ${process.cwd()} ${params[2]}`;
|
|
22
|
+
function needsCacheWarming(){
|
|
23
|
+
|
|
24
|
+
if(!fs.existsSync(getCachedPath('paths')) || !fs.existsSync(getCachedPath('checksum'))){
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const fileList = fs.readFileSync(getCachedPath('paths'), 'utf-8').split('\n');
|
|
29
|
+
|
|
30
|
+
if(fileList.length){
|
|
31
|
+
const fileContents = [];
|
|
32
|
+
for(const filePath of fileList){
|
|
33
|
+
if(fs.existsSync(filePath)){
|
|
34
|
+
fileContents.push(fs.readFileSync(filePath, 'utf-8'));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const finalMD5 = crypto.createHash('md5').update(fileContents.join('\n')).digest('hex');
|
|
38
|
+
const cachedMD5 = fs.readFileSync(getCachedPath('checksum'), 'utf-8');
|
|
39
|
+
|
|
40
|
+
if(finalMD5 === cachedMD5){
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function main()
|
|
49
|
+
{
|
|
50
|
+
const hasRebuild = paramsString.split(' ').pop().indexOf('--rebuild') > -1;
|
|
51
|
+
const doWarmCache = needsCacheWarming() || hasRebuild;
|
|
52
|
+
|
|
53
|
+
if(!((params[0] || false) && (params[1] || false) && (params[2] || false))){
|
|
54
|
+
throw new Error(`CLI command MUST have 3 parameters: {DB_URL, DB_NAME, MODELS_DIR}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if(doWarmCache){
|
|
58
|
+
console.log(chalk.yellow('[RWS DB CLI] Building CLI client...'));
|
|
59
|
+
|
|
60
|
+
const cacheTypes = ['paths', 'checksum'];
|
|
61
|
+
|
|
62
|
+
for(const type of cacheTypes){
|
|
63
|
+
if(fs.existsSync(getCachedPath(type))){
|
|
64
|
+
fs.unlinkSync(getCachedPath(type));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
await tsc();
|
|
69
|
+
|
|
70
|
+
await rwsShell.runCommand(commandString, currentCwd);
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
}else{
|
|
74
|
+
console.log(chalk.blue('[RWS CLI CACHE] Starting command from built CLI client.'));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let startSlice = hasRebuild ? -1 : paramsString.split(' ').length;
|
|
78
|
+
let endSlice = hasRebuild ? -1 : null ;
|
|
79
|
+
|
|
80
|
+
paramsString = [
|
|
81
|
+
...paramsString.split(' ').slice(0, startSlice),
|
|
82
|
+
currentCwd,
|
|
83
|
+
endSlice ?
|
|
84
|
+
paramsString.split(' ').at(endSlice)
|
|
85
|
+
: null
|
|
86
|
+
].filter((item) => item !== null).join(' ');
|
|
87
|
+
|
|
88
|
+
await rwsShell.runCommand(`node ${path.join(currentCwd, 'build', 'main.cli.rws.js')}${paramsString}`, process.cwd());
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function tsc (){
|
|
92
|
+
const tempConfigContent = {
|
|
93
|
+
"extends": "./tsconfig.json",
|
|
94
|
+
"include": [
|
|
95
|
+
path.join(process.cwd(), params[2], 'index.ts')
|
|
96
|
+
],
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const tempConfigPath = path.join(currentCwd, '.tmp.gitignore.json');
|
|
100
|
+
fs.writeFileSync(tempConfigPath, JSON.stringify(tempConfigContent, null, 2));
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
await rwsShell.runCommand(`tsc -p ${tempConfigPath}`, currentCwd);
|
|
104
|
+
fs.unlinkSync(tempConfigPath);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
main().then((data) => {
|
|
108
|
+
console.log(chalk.green('[RWS DB CLI] Command complete.'));
|
|
109
|
+
}).catch((e) => {
|
|
110
|
+
console.error(e.message);
|
|
111
111
|
});
|