This repository has been archived by the owner on Apr 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
copy-custom.js
54 lines (37 loc) · 1.75 KB
/
copy-custom.js
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
const fs = require('fs-extra');
const unzipper = require('unzipper');
const mv = require('mv');
const cp = require('child_process');
var request = require('request');
const helpers = require('./helpers.js');
const extensionParams = require('./extension.json');
const config = helpers.loadConfig();
copyCustom();
function copyCustom () {
var moduleName = extensionParams.module;
var sourcePath = './site/custom/Espo/Custom/';
var distPath = './src/files/application/Espo/Modules/' + moduleName;
fs.copySync(sourcePath, distPath);
var entityTypeList = [];
if (fs.existsSync(distPath + '/Entities')) {
fs.readdirSync(distPath + '/Entities').forEach(file => {
entityTypeList.push(file.substr(0, file.length - 4));
});
}
entityTypeList.forEach(function (eType) {
var scopeDefsFile = distPath + '/Resources/metadata/scopes/' + eType + '.json';
var defs = require(scopeDefsFile);
defs['module'] = moduleName;
fs.writeFileSync(scopeDefsFile, JSON.stringify(defs, null, ' '));
var controllerFile = distPath + '/Controller/' + eType + '.php';
['Controllers', 'Entities', 'Repositories', 'SelectManagers', 'Services'].forEach(function (item) {
var file = distPath + '/'+item+'/' + eType + '.php';
if (!fs.existsSync(file)) return;
var contents = fs.readFileSync(file).toString();
contents = contents.replace(new RegExp('namespace Espo\\\\Custom', 'g'), 'namespace Espo\\Modules\\' + moduleName);
fs.writeFileSync(file, contents);
}, this);
}, this);
console.log(
"Done.\nCustom files were copied from 'site' to 'src'. Now you can remove files from 'site/custom' and commit changes.");
}