@nestia/migrate 0.1.3 → 0.1.5
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/lib/NestiaMigrateApplication.d.ts +3 -3
- package/lib/NestiaMigrateApplication.js +3 -15
- package/lib/NestiaMigrateApplication.js.map +1 -1
- package/lib/archivers/FileArchiver.d.ts +3 -3
- package/lib/archivers/FileArchiver.js +8 -17
- package/lib/archivers/FileArchiver.js.map +1 -1
- package/lib/bundles/TEMPLATE.js +2 -132
- package/lib/bundles/TEMPLATE.js.map +1 -1
- package/lib/executable/bundle.js +2 -1
- package/lib/executable/bundle.js.map +1 -1
- package/lib/executable/migrate.js +19 -27
- package/lib/executable/migrate.js.map +1 -1
- package/lib/test/index.js +11 -23
- package/lib/test/index.js.map +1 -1
- package/package.json +1 -1
- package/src/NestiaMigrateApplication.ts +4 -7
- package/src/archivers/FileArchiver.ts +9 -9
- package/src/bundles/TEMPLATE.ts +2 -132
- package/src/executable/bundle.ts +2 -1
- package/src/executable/migrate.ts +19 -17
- package/src/test/index.ts +10 -16
package/src/executable/bundle.ts
CHANGED
@@ -27,11 +27,12 @@ const clone = async (): Promise<void> => {
|
|
27
27
|
|
28
28
|
// REMOVE VUNLERABLE FILES
|
29
29
|
for (const path of [
|
30
|
+
`${TEMPLATE}/.git`,
|
31
|
+
`${TEMPLATE}/dist`,
|
30
32
|
`${TEMPLATE}/src/api`,
|
31
33
|
`${TEMPLATE}/src/controllers`,
|
32
34
|
`${TEMPLATE}/src/providers`,
|
33
35
|
`${TEMPLATE}/test/features`,
|
34
|
-
`${TEMPLATE}/dist`,
|
35
36
|
])
|
36
37
|
await fs.promises.rm(path, { recursive: true });
|
37
38
|
};
|
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
import fs from "fs";
|
3
|
+
import path from "path";
|
3
4
|
|
4
5
|
import { NestiaMigrateApplication } from "../NestiaMigrateApplication";
|
5
6
|
import { ISwagger } from "../structures/ISwagger";
|
@@ -17,42 +18,43 @@ function halt(desc: string): never {
|
|
17
18
|
process.exit(-1);
|
18
19
|
}
|
19
20
|
|
20
|
-
const main =
|
21
|
-
const
|
22
|
-
|
21
|
+
const main = (argv: string[]) => {
|
22
|
+
const resolve = (str: string | undefined) =>
|
23
|
+
str ? path.resolve(str).split("\\").join("/") : undefined;
|
24
|
+
const input: string | undefined = resolve(argv[0]);
|
25
|
+
const output: string | undefined = resolve(argv[1]);
|
23
26
|
|
24
27
|
// VALIDATE ARGUMENTS
|
25
28
|
if (input === undefined || output === undefined) halt(USAGE);
|
26
|
-
|
27
|
-
|
29
|
+
|
30
|
+
// VALIDATE OUTPUT DIRECTORY
|
31
|
+
const parent: string = resolve(output + "/..")!;
|
32
|
+
if (fs.existsSync(output)) halt("Output directory alreay exists.");
|
33
|
+
else if (fs.existsSync(parent) === false)
|
28
34
|
halt("Output directory's parent directory does not exist.");
|
29
|
-
else if (
|
35
|
+
else if (fs.statSync(parent).isDirectory() === false)
|
30
36
|
halt("Output directory's parent is not a directory.");
|
31
37
|
|
32
38
|
// READ SWAGGER
|
33
|
-
const swagger: ISwagger =
|
39
|
+
const swagger: ISwagger = (() => {
|
34
40
|
if (fs.existsSync(input) === false)
|
35
41
|
halt("Unable to find the input swagger.json file.");
|
36
|
-
const stats: fs.Stats =
|
42
|
+
const stats: fs.Stats = fs.statSync(input);
|
37
43
|
if (stats.isFile() === false)
|
38
44
|
halt("The input swagger.json is not a file.");
|
39
|
-
const content: string =
|
45
|
+
const content: string = fs.readFileSync(input, "utf-8");
|
40
46
|
const swagger: ISwagger = JSON.parse(content);
|
41
47
|
return swagger;
|
42
48
|
})();
|
43
49
|
|
44
50
|
// DO GENERATE
|
45
51
|
const app = new NestiaMigrateApplication(swagger);
|
46
|
-
|
47
|
-
mkdir: fs.
|
48
|
-
writeFile: (path, content) =>
|
49
|
-
fs.promises.writeFile(path, content, "utf8"),
|
52
|
+
app.generate({
|
53
|
+
mkdir: fs.mkdirSync,
|
54
|
+
writeFile: (path, content) => fs.writeFileSync(path, content, "utf8"),
|
50
55
|
})(output);
|
51
56
|
|
52
57
|
// RUN SCRIPTS
|
53
58
|
SetupWizard.setup(output);
|
54
59
|
};
|
55
|
-
main(process.argv.slice(2))
|
56
|
-
console.log(exp);
|
57
|
-
process.exit(-1);
|
58
|
-
});
|
60
|
+
main(process.argv.slice(2));
|
package/src/test/index.ts
CHANGED
@@ -6,33 +6,27 @@ import { SetupWizard } from "../utils/SetupWizard";
|
|
6
6
|
const INPUT = __dirname + "/../../assets/input";
|
7
7
|
const OUTPUT = __dirname + "/../../assets/output";
|
8
8
|
|
9
|
-
const main =
|
10
|
-
if (fs.existsSync(OUTPUT))
|
11
|
-
|
12
|
-
await fs.promises.mkdir(OUTPUT);
|
9
|
+
const main = () => {
|
10
|
+
if (fs.existsSync(OUTPUT)) fs.rmSync(OUTPUT, { recursive: true });
|
11
|
+
fs.mkdirSync(OUTPUT);
|
13
12
|
|
14
|
-
const directory: string[] =
|
13
|
+
const directory: string[] = fs.readdirSync(INPUT);
|
15
14
|
for (const file of directory) {
|
16
15
|
const location: string = `${INPUT}/${file}`;
|
17
16
|
if (!location.endsWith(".json")) continue;
|
18
17
|
|
19
|
-
const swagger: ISwagger = JSON.parse(
|
20
|
-
await fs.promises.readFile(location, "utf8"),
|
21
|
-
);
|
18
|
+
const swagger: ISwagger = JSON.parse(fs.readFileSync(location, "utf8"));
|
22
19
|
const app = new NestiaMigrateApplication(swagger);
|
23
20
|
app.analyze();
|
24
21
|
|
25
22
|
const project: string = `${OUTPUT}/${file.replace(".json", "")}`;
|
26
|
-
|
27
|
-
|
28
|
-
mkdir: fs.
|
23
|
+
fs.mkdirSync(project);
|
24
|
+
app.generate({
|
25
|
+
mkdir: fs.mkdirSync,
|
29
26
|
writeFile: (path, content) =>
|
30
27
|
fs.promises.writeFile(path, content, "utf8"),
|
31
28
|
})(project);
|
32
|
-
|
29
|
+
SetupWizard.setup(project);
|
33
30
|
}
|
34
31
|
};
|
35
|
-
main()
|
36
|
-
console.error(exp);
|
37
|
-
process.exit(-1);
|
38
|
-
});
|
32
|
+
main();
|