sonamu 0.0.7 → 0.0.9
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/.pnp.cjs +13 -0
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/init.d.ts +35 -5
- package/dist/api/init.d.ts.map +1 -1
- package/dist/api/init.js +142 -79
- package/dist/api/init.js.map +1 -1
- package/dist/api/sonamu.d.ts +42 -0
- package/dist/api/sonamu.d.ts.map +1 -0
- package/dist/api/sonamu.js +175 -0
- package/dist/api/sonamu.js.map +1 -0
- package/dist/bin/cli.js +152 -67
- package/dist/bin/cli.js.map +1 -1
- package/dist/database/db.d.ts +1 -3
- package/dist/database/db.d.ts.map +1 -1
- package/dist/database/db.js +12 -23
- package/dist/database/db.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/smd/migrator.d.ts +0 -5
- package/dist/smd/migrator.d.ts.map +1 -1
- package/dist/smd/migrator.js +18 -19
- package/dist/smd/migrator.js.map +1 -1
- package/dist/smd/smd-manager.js +2 -2
- package/dist/smd/smd-manager.js.map +1 -1
- package/dist/smd/smd.d.ts.map +1 -1
- package/dist/smd/smd.js +4 -5
- package/dist/smd/smd.js.map +1 -1
- package/dist/syncer/syncer.d.ts +8 -12
- package/dist/syncer/syncer.d.ts.map +1 -1
- package/dist/syncer/syncer.js +43 -43
- package/dist/syncer/syncer.js.map +1 -1
- package/dist/templates/generated_http.template.js +2 -2
- package/dist/templates/generated_http.template.js.map +1 -1
- package/dist/templates/init_enums.template.js +1 -1
- package/dist/templates/init_generated.template.d.ts.map +1 -1
- package/dist/templates/init_generated.template.js +8 -1
- package/dist/templates/init_generated.template.js.map +1 -1
- package/dist/templates/service.template.d.ts +1 -1
- package/dist/templates/service.template.d.ts.map +1 -1
- package/dist/templates/service.template.js +3 -2
- package/dist/templates/service.template.js.map +1 -1
- package/dist/templates/smd.template.js +2 -2
- package/dist/templates/smd.template.js.map +1 -1
- package/dist/templates/view_form.template.d.ts +2 -2
- package/dist/templates/view_list.template.d.ts +2 -2
- package/dist/testing/fixture-manager.d.ts +6 -7
- package/dist/testing/fixture-manager.d.ts.map +1 -1
- package/dist/testing/fixture-manager.js +35 -41
- package/dist/testing/fixture-manager.js.map +1 -1
- package/dist/utils/utils.d.ts +1 -0
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +13 -3
- package/dist/utils/utils.js.map +1 -1
- package/package.json +8 -4
- package/src/api/index.ts +1 -1
- package/src/api/sonamu.ts +212 -0
- package/src/bin/cli.ts +159 -70
- package/src/database/db.ts +15 -27
- package/src/index.ts +1 -1
- package/src/smd/migrator.ts +18 -31
- package/src/smd/smd-manager.ts +3 -3
- package/src/smd/smd.ts +10 -9
- package/src/syncer/syncer.ts +49 -68
- package/src/templates/generated_http.template.ts +2 -2
- package/src/templates/init_enums.template.ts +1 -1
- package/src/templates/init_generated.template.ts +8 -1
- package/src/templates/service.template.ts +6 -5
- package/src/templates/smd.template.ts +2 -2
- package/src/testing/fixture-manager.ts +44 -53
- package/src/utils/utils.ts +9 -1
- package/src/api/init.ts +0 -129
package/src/bin/cli.ts
CHANGED
|
@@ -12,29 +12,60 @@ import { SMDManager } from "../smd/smd-manager";
|
|
|
12
12
|
import { Migrator } from "../smd/migrator";
|
|
13
13
|
import { Syncer } from "../syncer/syncer";
|
|
14
14
|
import { FixtureManager } from "../testing/fixture-manager";
|
|
15
|
+
import { tsicli } from "tsicli";
|
|
16
|
+
import { execSync } from "child_process";
|
|
17
|
+
import { existsSync, mkdirSync, readdirSync, writeFileSync } from "fs";
|
|
18
|
+
import { Sonamu } from "../api";
|
|
15
19
|
|
|
16
20
|
let migrator: Migrator;
|
|
17
21
|
let fixtureManager: FixtureManager;
|
|
18
22
|
|
|
19
23
|
async function bootstrap() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
await Sonamu.init();
|
|
25
|
+
|
|
26
|
+
await tsicli(process.argv, {
|
|
27
|
+
types: {
|
|
28
|
+
"#smdId": {
|
|
29
|
+
type: "autocomplete",
|
|
30
|
+
name: "#smdId",
|
|
31
|
+
message: "Please input #smdId",
|
|
32
|
+
choices: SMDManager.getAllParentIds().map((smdId) => ({
|
|
33
|
+
title: smdId,
|
|
34
|
+
value: smdId,
|
|
35
|
+
})),
|
|
36
|
+
},
|
|
37
|
+
"#recordIds": "number[]",
|
|
38
|
+
"#name": "string",
|
|
39
|
+
},
|
|
40
|
+
args: [
|
|
41
|
+
["fixture", "import", "#smdId", "#recordIds"],
|
|
42
|
+
["fixture", "sync"],
|
|
43
|
+
["migrate", "run"],
|
|
44
|
+
["migrate", "rollback"],
|
|
45
|
+
["migrate", "reset"],
|
|
46
|
+
["migrate", "clear"],
|
|
47
|
+
["stub", "practice", "#name"],
|
|
48
|
+
["stub", "smd", "#name"],
|
|
49
|
+
["scaffold", "model", "#smdId"],
|
|
50
|
+
["scaffold", "model_test", "#smdId"],
|
|
51
|
+
["scaffold", "view_list", "#smdId"],
|
|
52
|
+
["scaffold", "view_form", "#smdId"],
|
|
53
|
+
],
|
|
54
|
+
runners: {
|
|
55
|
+
migrate_run,
|
|
56
|
+
migrate_rollback,
|
|
57
|
+
migrate_clear,
|
|
58
|
+
migrate_reset,
|
|
59
|
+
fixture_import,
|
|
60
|
+
fixture_sync,
|
|
61
|
+
stub_practice,
|
|
62
|
+
stub_smd,
|
|
63
|
+
scaffold_model,
|
|
64
|
+
scaffold_model_test,
|
|
65
|
+
// scaffold_view_list,
|
|
66
|
+
// scaffold_view_form,
|
|
67
|
+
},
|
|
24
68
|
});
|
|
25
|
-
await DB.readKnexfile(appRootPath);
|
|
26
|
-
|
|
27
|
-
const [_0, _1, action, ...args] = process.argv;
|
|
28
|
-
switch (action) {
|
|
29
|
-
case "migrate":
|
|
30
|
-
await migrate(args[0] as MigrateSubAction);
|
|
31
|
-
break;
|
|
32
|
-
case "fixture":
|
|
33
|
-
await fixture(args[0] as FixtureSubAction, args.slice(1));
|
|
34
|
-
break;
|
|
35
|
-
default:
|
|
36
|
-
throw new Error(`Unknown action ${action}`);
|
|
37
|
-
}
|
|
38
69
|
}
|
|
39
70
|
bootstrap().finally(async () => {
|
|
40
71
|
if (migrator) {
|
|
@@ -49,67 +80,125 @@ bootstrap().finally(async () => {
|
|
|
49
80
|
console.log(chalk.bgBlue(`END ${new Date()}\n`));
|
|
50
81
|
});
|
|
51
82
|
|
|
52
|
-
|
|
53
|
-
async function migrate(subAction: MigrateSubAction) {
|
|
54
|
-
await SMDManager.autoload();
|
|
55
|
-
|
|
83
|
+
async function setupMigrator() {
|
|
56
84
|
// migrator
|
|
57
85
|
migrator = new Migrator({
|
|
58
|
-
appRootPath: Syncer.getInstance().config.appRootPath,
|
|
59
86
|
knexfile: DB.getKnexfile(),
|
|
60
87
|
mode: "dev",
|
|
61
88
|
});
|
|
89
|
+
}
|
|
62
90
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
await migrator.cleanUpDist();
|
|
66
|
-
await migrator.run();
|
|
67
|
-
break;
|
|
68
|
-
case "rollback":
|
|
69
|
-
await migrator.rollback();
|
|
70
|
-
break;
|
|
71
|
-
case "clear":
|
|
72
|
-
await migrator.clearPendingList();
|
|
73
|
-
break;
|
|
74
|
-
case "reset":
|
|
75
|
-
await migrator.resetAll();
|
|
76
|
-
break;
|
|
77
|
-
default:
|
|
78
|
-
throw new Error(`Unknown subAction - ${subAction}`);
|
|
79
|
-
}
|
|
91
|
+
async function setupFixtureManager() {
|
|
92
|
+
fixtureManager = new FixtureManager();
|
|
80
93
|
}
|
|
81
94
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
await SMDManager.autoload();
|
|
95
|
+
async function migrate_run() {
|
|
96
|
+
await setupMigrator();
|
|
85
97
|
|
|
86
|
-
|
|
98
|
+
await migrator.cleanUpDist();
|
|
99
|
+
await migrator.run();
|
|
100
|
+
}
|
|
87
101
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
102
|
+
async function migrate_rollback() {
|
|
103
|
+
await setupMigrator();
|
|
104
|
+
|
|
105
|
+
await migrator.rollback();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function migrate_clear() {
|
|
109
|
+
await setupMigrator();
|
|
110
|
+
|
|
111
|
+
await migrator.clearPendingList();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function migrate_reset() {
|
|
115
|
+
await setupMigrator();
|
|
116
|
+
|
|
117
|
+
await migrator.resetAll();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function fixture_import(smdId: string, recordIds: number[]) {
|
|
121
|
+
await setupFixtureManager();
|
|
122
|
+
|
|
123
|
+
await fixtureManager.importFixture(smdId, recordIds);
|
|
124
|
+
await fixtureManager.sync();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function fixture_sync() {
|
|
128
|
+
await setupFixtureManager();
|
|
129
|
+
|
|
130
|
+
await fixtureManager.sync();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function stub_practice(name: string) {
|
|
134
|
+
const practiceDir = path.join(Sonamu.apiRootPath, "src", "practices");
|
|
135
|
+
const fileNames = readdirSync(practiceDir);
|
|
136
|
+
|
|
137
|
+
const maxSeqNo = (() => {
|
|
138
|
+
if (existsSync(practiceDir) === false) {
|
|
139
|
+
mkdirSync(practiceDir, { recursive: true });
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const filteredSeqs = fileNames
|
|
143
|
+
.filter(
|
|
144
|
+
(fileName) => fileName.startsWith("p") && fileName.endsWith(".ts")
|
|
145
|
+
)
|
|
146
|
+
.map((fileName) => {
|
|
147
|
+
const [, seqNo] = fileName.match(/^p([0-9]+)\-/) ?? ["0", "0"];
|
|
148
|
+
return parseInt(seqNo);
|
|
149
|
+
})
|
|
150
|
+
.sort((a, b) => b - a);
|
|
151
|
+
|
|
152
|
+
if (filteredSeqs.length > 0) {
|
|
153
|
+
return filteredSeqs[0];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return 0;
|
|
157
|
+
})();
|
|
158
|
+
|
|
159
|
+
const currentSeqNo = maxSeqNo + 1;
|
|
160
|
+
const fileName = `p${currentSeqNo}-${name}.ts`;
|
|
161
|
+
const dstPath = path.join(practiceDir, fileName);
|
|
162
|
+
|
|
163
|
+
const code = [
|
|
164
|
+
`import { BaseModel } from "sonamu";`,
|
|
165
|
+
"",
|
|
166
|
+
`console.clear();`,
|
|
167
|
+
`console.log("${fileName}");`,
|
|
168
|
+
"",
|
|
169
|
+
`async function bootstrap() {`,
|
|
170
|
+
` // TODO`,
|
|
171
|
+
`}`,
|
|
172
|
+
`bootstrap().finally(async () => {`,
|
|
173
|
+
`await BaseModel.destroy();`,
|
|
174
|
+
`});`,
|
|
175
|
+
].join("\n");
|
|
176
|
+
writeFileSync(dstPath, code);
|
|
177
|
+
|
|
178
|
+
execSync(`code ${dstPath}`);
|
|
179
|
+
|
|
180
|
+
const runCode = `yarn node -r source-map-support/register dist/practices/${fileName.replace(
|
|
181
|
+
".ts",
|
|
182
|
+
".js"
|
|
183
|
+
)}`;
|
|
184
|
+
console.log(`${chalk.blue(runCode)} copied to clipboard.`);
|
|
185
|
+
execSync(`echo "${runCode}" | pbcopy`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function stub_smd(name: string) {
|
|
189
|
+
await Sonamu.syncer.generateTemplate("smd", {
|
|
190
|
+
smdId: name,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async function scaffold_model(smdId: string) {
|
|
195
|
+
await Sonamu.syncer.generateTemplate("model", {
|
|
196
|
+
smdId,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function scaffold_model_test(smdId: string) {
|
|
201
|
+
await Sonamu.syncer.generateTemplate("model_test", {
|
|
202
|
+
smdId,
|
|
203
|
+
});
|
|
115
204
|
}
|
package/src/database/db.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export type DBPreset = "w" | "r";
|
|
2
2
|
import knex, { Knex } from "knex";
|
|
3
3
|
import path from "path";
|
|
4
|
+
import { Sonamu } from "../api";
|
|
4
5
|
import { ServiceUnavailableException } from "../exceptions/so-exceptions";
|
|
5
|
-
import { findAppRootPath } from "../utils/utils";
|
|
6
6
|
|
|
7
7
|
export type SonamuDBConfig = {
|
|
8
8
|
development_master: Knex.Config;
|
|
@@ -17,36 +17,24 @@ export type SonamuDBConfig = {
|
|
|
17
17
|
class DBClass {
|
|
18
18
|
private wdb?: Knex;
|
|
19
19
|
private rdb?: Knex;
|
|
20
|
-
private knexfile?: SonamuDBConfig;
|
|
21
20
|
|
|
22
|
-
async readKnexfile(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const appRootPath = _appRootPath ?? (await findAppRootPath());
|
|
28
|
-
const configPath: string = path.join(appRootPath, "/api/dist/configs/db");
|
|
21
|
+
async readKnexfile(): Promise<SonamuDBConfig> {
|
|
22
|
+
const dbConfigPath: string = path.join(
|
|
23
|
+
Sonamu.apiRootPath,
|
|
24
|
+
"/dist/configs/db"
|
|
25
|
+
);
|
|
29
26
|
try {
|
|
30
|
-
const knexfileModule = await import(
|
|
31
|
-
|
|
32
|
-
return this.knexfile;
|
|
27
|
+
const knexfileModule = await import(dbConfigPath);
|
|
28
|
+
return knexfileModule.default as SonamuDBConfig;
|
|
33
29
|
} catch {}
|
|
34
30
|
|
|
35
31
|
throw new ServiceUnavailableException(
|
|
36
|
-
`DB설정 파일을 찾을 수 없습니다. ${
|
|
32
|
+
`DB설정 파일을 찾을 수 없습니다. ${dbConfigPath}`
|
|
37
33
|
);
|
|
38
34
|
}
|
|
39
35
|
|
|
40
|
-
getKnexfile(): SonamuDBConfig {
|
|
41
|
-
if (this.knexfile) {
|
|
42
|
-
return this.knexfile;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
throw new ServiceUnavailableException("DB설정이 로드되지 않았습니다.");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
36
|
getDB(which: DBPreset): Knex {
|
|
49
|
-
const
|
|
37
|
+
const dbConfig = Sonamu.dbConfig;
|
|
50
38
|
|
|
51
39
|
const instanceName = which === "w" ? "wdb" : "rdb";
|
|
52
40
|
|
|
@@ -57,17 +45,17 @@ class DBClass {
|
|
|
57
45
|
case "staging":
|
|
58
46
|
config =
|
|
59
47
|
which === "w"
|
|
60
|
-
?
|
|
61
|
-
:
|
|
48
|
+
? dbConfig["development_master"]
|
|
49
|
+
: dbConfig["development_slave"] ?? dbConfig["development_master"];
|
|
62
50
|
break;
|
|
63
51
|
case "production":
|
|
64
52
|
config =
|
|
65
53
|
which === "w"
|
|
66
|
-
?
|
|
67
|
-
:
|
|
54
|
+
? dbConfig["production_master"]
|
|
55
|
+
: dbConfig["production_slave"] ?? dbConfig["production_master"];
|
|
68
56
|
break;
|
|
69
57
|
case "test":
|
|
70
|
-
config =
|
|
58
|
+
config = dbConfig["test"];
|
|
71
59
|
break;
|
|
72
60
|
default:
|
|
73
61
|
throw new Error(
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./api/code-converters";
|
|
2
2
|
export * from "./api/context";
|
|
3
3
|
export * from "./api/decorators";
|
|
4
|
-
export * from "./api/
|
|
4
|
+
export * from "./api/sonamu";
|
|
5
5
|
export * from "./database/base-model";
|
|
6
6
|
export * from "./database/db";
|
|
7
7
|
export * from "./database/upsert-builder";
|
package/src/smd/migrator.ts
CHANGED
|
@@ -49,17 +49,13 @@ import {
|
|
|
49
49
|
import { propIf } from "../utils/lodash-able";
|
|
50
50
|
import { SMDManager } from "./smd-manager";
|
|
51
51
|
import { SMD } from "./smd";
|
|
52
|
-
import {
|
|
52
|
+
import { Sonamu } from "../api";
|
|
53
53
|
|
|
54
54
|
type MigratorMode = "dev" | "deploy";
|
|
55
55
|
export type MigratorOptions = {
|
|
56
|
-
appRootPath: string;
|
|
57
|
-
knexfile: SonamuDBConfig;
|
|
58
56
|
readonly mode: MigratorMode;
|
|
59
57
|
};
|
|
60
58
|
export class Migrator {
|
|
61
|
-
appRootPath: string;
|
|
62
|
-
knexfile: SonamuDBConfig;
|
|
63
59
|
readonly mode: MigratorMode;
|
|
64
60
|
|
|
65
61
|
targets: {
|
|
@@ -70,23 +66,21 @@ export class Migrator {
|
|
|
70
66
|
};
|
|
71
67
|
|
|
72
68
|
constructor(options: MigratorOptions) {
|
|
73
|
-
this.appRootPath = options.appRootPath;
|
|
74
|
-
this.knexfile = options.knexfile;
|
|
75
69
|
this.mode = options.mode;
|
|
70
|
+
const { dbConfig } = Sonamu;
|
|
76
71
|
|
|
77
72
|
if (this.mode === "dev") {
|
|
78
|
-
const devDB = knex(
|
|
79
|
-
const testDB = knex(
|
|
80
|
-
const fixtureLocalDB = knex(
|
|
73
|
+
const devDB = knex(dbConfig.development_master);
|
|
74
|
+
const testDB = knex(dbConfig.test);
|
|
75
|
+
const fixtureLocalDB = knex(dbConfig.fixture_local);
|
|
81
76
|
|
|
82
77
|
const applyDBs = [devDB, testDB, fixtureLocalDB];
|
|
83
78
|
if (
|
|
84
|
-
(
|
|
79
|
+
(dbConfig.fixture_local.connection as Knex.MySql2ConnectionConfig)
|
|
85
80
|
.host !==
|
|
86
|
-
(
|
|
87
|
-
.host
|
|
81
|
+
(dbConfig.fixture_remote.connection as Knex.MySql2ConnectionConfig).host
|
|
88
82
|
) {
|
|
89
|
-
const fixtureRemoteDB = knex(
|
|
83
|
+
const fixtureRemoteDB = knex(dbConfig.fixture_remote);
|
|
90
84
|
applyDBs.push(fixtureRemoteDB);
|
|
91
85
|
}
|
|
92
86
|
|
|
@@ -97,8 +91,8 @@ export class Migrator {
|
|
|
97
91
|
apply: applyDBs,
|
|
98
92
|
};
|
|
99
93
|
} else if (this.mode === "deploy") {
|
|
100
|
-
const productionDB = knex(
|
|
101
|
-
const testDB = knex(
|
|
94
|
+
const productionDB = knex(Sonamu.dbConfig.production_master);
|
|
95
|
+
const testDB = knex(Sonamu.dbConfig.test);
|
|
102
96
|
|
|
103
97
|
this.targets = {
|
|
104
98
|
pending: productionDB,
|
|
@@ -118,7 +112,7 @@ export class Migrator {
|
|
|
118
112
|
directory: string;
|
|
119
113
|
}[]
|
|
120
114
|
];
|
|
121
|
-
const migrationsDir = `${
|
|
115
|
+
const migrationsDir = `${Sonamu.apiRootPath}/src/migrations`;
|
|
122
116
|
const delList = pendingList.map((df) => {
|
|
123
117
|
return path.join(migrationsDir, df.file).replace(".js", ".ts");
|
|
124
118
|
});
|
|
@@ -197,7 +191,7 @@ export class Migrator {
|
|
|
197
191
|
}
|
|
198
192
|
|
|
199
193
|
// 실제 코드 생성
|
|
200
|
-
const migrationsDir = `${
|
|
194
|
+
const migrationsDir = `${Sonamu.apiRootPath}/src/migrations`;
|
|
201
195
|
codes
|
|
202
196
|
.filter((code) => code.formatted)
|
|
203
197
|
.map((code, index) => {
|
|
@@ -226,8 +220,7 @@ export class Migrator {
|
|
|
226
220
|
const files = (["src", "dist"] as const).reduce(
|
|
227
221
|
(r, which) => {
|
|
228
222
|
const migrationPath = path.join(
|
|
229
|
-
|
|
230
|
-
"api",
|
|
223
|
+
Sonamu.apiRootPath,
|
|
231
224
|
which,
|
|
232
225
|
"migrations"
|
|
233
226
|
);
|
|
@@ -281,13 +274,7 @@ export class Migrator {
|
|
|
281
274
|
}
|
|
282
275
|
|
|
283
276
|
const filesToRm = diffOnDist.map((filename) => {
|
|
284
|
-
return path.join(
|
|
285
|
-
this.appRootPath,
|
|
286
|
-
"api",
|
|
287
|
-
"dist",
|
|
288
|
-
"migrations",
|
|
289
|
-
filename
|
|
290
|
-
);
|
|
277
|
+
return path.join(Sonamu.apiRootPath, "dist", "migrations", filename);
|
|
291
278
|
});
|
|
292
279
|
filesToRm.map((filePath) => {
|
|
293
280
|
unlinkSync(filePath);
|
|
@@ -298,8 +285,8 @@ export class Migrator {
|
|
|
298
285
|
|
|
299
286
|
async runShadowTest(): Promise<boolean> {
|
|
300
287
|
// ShadowDB 생성 후 테스트 진행
|
|
301
|
-
const tdb = knex(
|
|
302
|
-
const tdbConn =
|
|
288
|
+
const tdb = knex(Sonamu.dbConfig.test);
|
|
289
|
+
const tdbConn = Sonamu.dbConfig.test.connection as Knex.ConnectionConfig;
|
|
303
290
|
const shadowDatabase = tdbConn.database + "__migration_shadow";
|
|
304
291
|
const tmpSqlPath = `/tmp/${shadowDatabase}.sql`;
|
|
305
292
|
|
|
@@ -330,7 +317,7 @@ export class Migrator {
|
|
|
330
317
|
|
|
331
318
|
// shadow db 테스트 진행
|
|
332
319
|
const sdb = knex({
|
|
333
|
-
...
|
|
320
|
+
...Sonamu.dbConfig.test,
|
|
334
321
|
connection: {
|
|
335
322
|
...tdbConn,
|
|
336
323
|
database: shadowDatabase,
|
|
@@ -378,7 +365,7 @@ export class Migrator {
|
|
|
378
365
|
console.log({ rollbackAllResult });
|
|
379
366
|
console.timeEnd(chalk.red("rollback-all:"));
|
|
380
367
|
|
|
381
|
-
const migrationsDir = `${
|
|
368
|
+
const migrationsDir = `${Sonamu.apiRootPath}/src/migrations`;
|
|
382
369
|
console.time(chalk.red("delete migration files"));
|
|
383
370
|
execSync(`rm -f ${migrationsDir}/*`);
|
|
384
371
|
execSync(`rm -f ${migrationsDir.replace("/src/", "/dist/")}/*`);
|
package/src/smd/smd-manager.ts
CHANGED
|
@@ -5,7 +5,7 @@ import _ from "lodash";
|
|
|
5
5
|
import path from "path";
|
|
6
6
|
import { SMD } from "./smd";
|
|
7
7
|
import { SMDInput } from "../types/types";
|
|
8
|
-
import {
|
|
8
|
+
import { Sonamu } from "../api/sonamu";
|
|
9
9
|
|
|
10
10
|
export type SMDNamesRecord = Record<
|
|
11
11
|
| "fs"
|
|
@@ -34,8 +34,8 @@ class SMDManagerClass {
|
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
const pathPattern = path.join(
|
|
37
|
-
|
|
38
|
-
"/
|
|
37
|
+
Sonamu.apiRootPath,
|
|
38
|
+
"/dist/application/**/*.smd.js"
|
|
39
39
|
);
|
|
40
40
|
!doSilent && console.log(chalk.yellow(`autoload ${pathPattern}`));
|
|
41
41
|
|
package/src/smd/smd.ts
CHANGED
|
@@ -21,7 +21,7 @@ import path from "path";
|
|
|
21
21
|
import { existsSync } from "fs";
|
|
22
22
|
import { z } from "zod";
|
|
23
23
|
import { EnumsLabelKo } from "../types/types";
|
|
24
|
-
import {
|
|
24
|
+
import { Sonamu } from "../api/sonamu";
|
|
25
25
|
|
|
26
26
|
export class SMD {
|
|
27
27
|
id: string;
|
|
@@ -214,7 +214,9 @@ export class SMD {
|
|
|
214
214
|
to = `${joinAs}.id`;
|
|
215
215
|
} else {
|
|
216
216
|
from = `${fromTable}.id`;
|
|
217
|
-
to = `${joinAs}.${
|
|
217
|
+
to = `${joinAs}.${underscore(
|
|
218
|
+
this.names.fs.replace(/\-/g, "_")
|
|
219
|
+
)}_id`;
|
|
218
220
|
}
|
|
219
221
|
} else {
|
|
220
222
|
from = `${fromTable}.${relation.name}_id`;
|
|
@@ -435,7 +437,6 @@ export class SMD {
|
|
|
435
437
|
|
|
436
438
|
registerModulePaths() {
|
|
437
439
|
const basePath = `${this.names.fs}`;
|
|
438
|
-
const appRootPath = Syncer.getInstance().config.appRootPath;
|
|
439
440
|
|
|
440
441
|
// base-scheme
|
|
441
442
|
SMDManager.setModulePath(
|
|
@@ -463,9 +464,9 @@ export class SMD {
|
|
|
463
464
|
|
|
464
465
|
// types
|
|
465
466
|
const typesModulePath = `${basePath}/${this.names.fs}.types`;
|
|
466
|
-
const typesFileDistPath = path.
|
|
467
|
-
|
|
468
|
-
`
|
|
467
|
+
const typesFileDistPath = path.join(
|
|
468
|
+
Sonamu.apiRootPath,
|
|
469
|
+
`dist/application/${typesModulePath}.js`
|
|
469
470
|
);
|
|
470
471
|
|
|
471
472
|
if (existsSync(typesFileDistPath)) {
|
|
@@ -483,9 +484,9 @@ export class SMD {
|
|
|
483
484
|
|
|
484
485
|
// enums
|
|
485
486
|
const enumsModulePath = `${basePath}/${this.names.fs}.enums`;
|
|
486
|
-
const enumsFileDistPath = path.
|
|
487
|
-
|
|
488
|
-
|
|
487
|
+
const enumsFileDistPath = path.join(
|
|
488
|
+
Sonamu.apiRootPath,
|
|
489
|
+
`/dist/application/${enumsModulePath}.js`
|
|
489
490
|
);
|
|
490
491
|
if (existsSync(enumsFileDistPath)) {
|
|
491
492
|
const importPath = path.relative(__dirname, enumsFileDistPath);
|