-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath.js
More file actions
32 lines (30 loc) · 1.32 KB
/
path.js
File metadata and controls
32 lines (30 loc) · 1.32 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
/**
* This file will automatically set the path in the Source\Assemblies\Directories.ts, to disable this, add this to the top of the file Assemblies\Constants\Directories.ts
* '// !DISABLE-AUTO-SELECT-DIR'
* It should instert this automatically the first time.
*/
const fs = require('fs');
(function () {
try {
const dir = __dirname.split('\\').join('/');
const fileName = `${__dirname}/Source/Assemblies/Directories.ts`;
if (!fs.existsSync(fileName)) {
fs.writeFileSync(
fileName,
`// THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT\r\n// !DISABLE-AUTO-SELECT-DIR\r\nexport const __baseDirName = '${dir}';\r\nexport const __sslDirName = __baseDirName + '/SSL';\r\n`,
);
return;
}
let contents = fs.readFileSync(fileName, { encoding: 'utf-8' });
if (contents.includes('// !DISABLE-AUTO-SELECT-DIR')) {
console.log(
`The file ./Source/Assemblies/Directories.ts was forced to not select the current directory. Most likely because it's already been generated.`,
);
return;
}
const data = contents.match(/(["'])(?:(?=(\\?))\2.)*?\1/i);
contents = contents.replace(data[0], `'${dir}'`);
contents = `// THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT\r\n// !DISABLE-AUTO-SELECT-DIR\r\n${contents}`;
fs.writeFileSync(fileName, contents);
} catch (e) {}
})();