@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.
@@ -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 = async (argv: string[]) => {
21
- const input: string | undefined = argv[0];
22
- const output: string | undefined = argv[1];
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
- else if (fs.existsSync(output)) halt("Output directory alreay exists.");
27
- else if (fs.existsSync(output + "/..") === false)
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 ((await fs.promises.stat(output + "/..")).isDirectory() === false)
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 = await (async () => {
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 = await fs.promises.stat(input);
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 = await fs.readFileSync(input, "utf-8");
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
- await app.generate({
47
- mkdir: fs.promises.mkdir,
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)).catch((exp) => {
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 = async () => {
10
- if (fs.existsSync(OUTPUT))
11
- await fs.promises.rm(OUTPUT, { recursive: true });
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[] = await fs.promises.readdir(INPUT);
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
- await fs.promises.mkdir(project);
27
- await app.generate({
28
- mkdir: fs.promises.mkdir,
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
- await SetupWizard.setup(project);
29
+ SetupWizard.setup(project);
33
30
  }
34
31
  };
35
- main().catch((exp) => {
36
- console.error(exp);
37
- process.exit(-1);
38
- });
32
+ main();