create-sip 0.15.1 → 1.0.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/expressapi/op CHANGED
@@ -5,6 +5,7 @@ import { generateApiKey } from 'generate-api-key'
5
5
  import bcrypt from 'bcryptjs';
6
6
  import path from 'path';
7
7
  import { read } from 'read'
8
+ import { start } from 'repl';
8
9
 
9
10
  if(process.argv.length == 3 && process.argv[2] == 'help') {
10
11
  console.log('Usable commands:');
@@ -75,6 +76,11 @@ async function copyController(className) {
75
76
 
76
77
  const src = 'templates/controllerTemplate.js'
77
78
  const dest = `app/controllers/${lowerName}controller.js`
79
+
80
+ if(await startCheckIfFileExists(dest)) {
81
+ process.exit(1);
82
+ }
83
+
78
84
  await fse.copy(src, dest)
79
85
 
80
86
  replace({
@@ -99,6 +105,10 @@ async function copyModel(className) {
99
105
  const src = 'templates/modelTemplate.js'
100
106
  const dest = `app/models/${lowerName}.js`
101
107
 
108
+ if(await startCheckIfFileExists(dest)) {
109
+ process.exit(1);
110
+ }
111
+
102
112
  await fse.copy(src, dest)
103
113
 
104
114
  replace({
@@ -113,6 +123,25 @@ async function copyModel(className) {
113
123
  })
114
124
  }
115
125
 
126
+ async function checkIfFileExists(filePath) {
127
+ return await fsp.access(filePath)
128
+ .then(() => true)
129
+ .catch(() => false);
130
+ }
131
+
132
+ async function startCheckIfFileExists(filePath) {
133
+ return await checkIfFileExists(filePath)
134
+ .then(exists => {
135
+ if (exists) {
136
+ console.log(`The file ${filePath} exists!`);
137
+ return true;
138
+ } else {
139
+ return false;
140
+ }
141
+ })
142
+ .catch(error => console.log(error));
143
+ }
144
+
116
145
  function capitalizeFirstLetter(word) {
117
146
  return word.charAt(0).toUpperCase() + word.slice(1);
118
147
  }
package/manager.js CHANGED
@@ -1,20 +1,24 @@
1
- const { copyDir, updatePackageName } = require('./utils');
1
+ const { copyDir, updatePackageName, checkIfDirExists } = require('./utils');
2
2
  const path = require('path');
3
3
  const dir = path.join(__dirname);
4
4
 
5
5
  const genWebpage = (target) => {
6
+ checkIfDirExists(target);
6
7
  copyDir(`${dir}/webpage`, target);
7
8
  }
8
9
 
9
10
  const genBootstrap = (target) => {
11
+ checkIfDirExists(target);
10
12
  copyDir(`${dir}/webbootstrap`, target);
11
13
  }
12
14
 
13
15
  const genJavascript = (target) => {
16
+ checkIfDirExists(target);
14
17
  copyDir(`${dir}/javascript`, target);
15
18
  }
16
19
 
17
20
  const genNodejs = (target) => {
21
+ checkIfDirExists(target);
18
22
  copyDir(`${dir}/webnodejs`, target);
19
23
  updatePackageName(`${target}/package.json`, target);
20
24
  console.log('Web client created');
@@ -25,6 +29,7 @@ const genNodejs = (target) => {
25
29
  }
26
30
 
27
31
  const genWebEsbuildJs = (target) => {
32
+ checkIfDirExists(target);
28
33
  copyDir(`${dir}/webesbuildjs`, target);
29
34
  updatePackageName(`${target}/package.json`, target);
30
35
  console.log('ESBuild client created with Javascript');
@@ -38,6 +43,7 @@ const genWebEsbuildJs = (target) => {
38
43
  }
39
44
 
40
45
  const genWebEsbuildTs = (target) => {
46
+ checkIfDirExists(target);
41
47
  copyDir(`${dir}/webesbuildts`, target);
42
48
  updatePackageName(`${target}/package.json`, target);
43
49
  console.log('ESBuild client created with Typescript');
@@ -51,6 +57,7 @@ const genWebEsbuildTs = (target) => {
51
57
  }
52
58
 
53
59
  const genMockApi = (target) => {
60
+ checkIfDirExists(target);
54
61
  copyDir(`${dir}/mockapi`, target);
55
62
  updatePackageName(`${target}/package.json`, target);
56
63
  console.log('MockAPI with hai-server 0.0.4');
@@ -61,6 +68,7 @@ const genMockApi = (target) => {
61
68
  }
62
69
 
63
70
  const genExpressApi = (target) => {
71
+ checkIfDirExists(target);
64
72
  copyDir(`${dir}/expressapi`, target);
65
73
  updatePackageName(`${target}/package.json`, target);
66
74
  console.log('ExpressJS REST API skeleton created');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-sip",
3
- "version": "0.15.1",
3
+ "version": "1.0.0",
4
4
  "main": "index.js",
5
5
  "bin": {
6
6
  "create-sip": "create-sip.js"
package/utils.js CHANGED
@@ -24,7 +24,16 @@ const copyDir = (srcDir, destDir) => {
24
24
  }
25
25
  };
26
26
 
27
+ const checkIfDirExists = (dirPath) => {
28
+ if (fs.existsSync(dirPath)) {
29
+ console.error('Error!');
30
+ console.error(`Directory already exists: ${dirPath}`);
31
+ process.exit(1);
32
+ }
33
+ };
34
+
27
35
  module.exports = {
28
36
  updatePackageName,
29
37
  copyDir,
38
+ checkIfDirExists
30
39
  };