-
-
Notifications
You must be signed in to change notification settings - Fork 528
Expand file tree
/
Copy pathinit-helper.js
More file actions
89 lines (78 loc) · 2.23 KB
/
init-helper.js
File metadata and controls
89 lines (78 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import helpers from './index';
import path from 'path';
import fs from 'fs';
function createFolder(folderName, folder, force) {
if (force && fs.existsSync(folder) === true) {
helpers.view.log('Deleting the ' + folderName + ' folder. (--force)');
try {
fs.readdirSync(folder).forEach((filename) => {
fs.unlinkSync(path.resolve(folder, filename));
});
} catch (e) {
helpers.view.error(e);
}
try {
fs.rmdirSync(folder);
helpers.view.log('Successfully deleted the ' + folderName + ' folder.');
} catch (e) {
helpers.view.error(e);
}
}
try {
if (fs.existsSync(folder) === false) {
helpers.asset.mkdirp(folder);
helpers.view.log(
'Successfully created ' + folderName + ' folder at "' + folder + '".'
);
} else {
helpers.view.log(
folderName + ' folder at "' + folder + '" already exists.'
);
}
} catch (e) {
helpers.view.error(e);
}
}
const init = {
createMigrationsFolder: (force) => {
createFolder('migrations', helpers.path.getPath('migration'), force);
},
createSeedersFolder: (force) => {
createFolder('seeders', helpers.path.getPath('seeder'), force);
},
createModelsFolder: (force) => {
createFolder('models', helpers.path.getModelsPath(), force);
},
createConnectionFile: (force) => {
const modelsPath = helpers.path.getModelsPath();
const indexPath = path.resolve(
modelsPath,
helpers.path.addFileExtension('connection')
);
if (!helpers.path.existsSync(modelsPath)) {
helpers.view.log('Models folder not available.');
} else if (helpers.path.existsSync(indexPath) && !force) {
helpers.view.notifyAboutExistingFile(indexPath);
} else {
const relativeConfigPath = path.relative(
helpers.path.getModelsPath(),
helpers.config.getConfigFile()
);
helpers.asset.write(
indexPath,
helpers.template.render(
'models/connection.js',
{
configFile:
"__dirname + '/" + relativeConfigPath.replace(/\\/g, '/') + "'",
},
{
beautify: false,
}
)
);
}
},
};
module.exports = init;
module.exports.default = init;