-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenable_puerts_module.js
More file actions
103 lines (84 loc) · 2.96 KB
/
enable_puerts_module.js
File metadata and controls
103 lines (84 loc) · 2.96 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const path = require('path');
const fs = require('fs');
const execSync = require('child_process').execSync;
//console.log(__dirname)
const jsSourcePath = path.join(__dirname, 'Content/JavaScript');
const jsBasePath = path.join(__dirname, '../../Content/JavaScript');
const tsModulePath = path.join(jsBasePath, 'PuertsEditor/node_modules/typescript');
const tsconfigFilePath = path.join(__dirname, '../../tsconfig.json');
const puertsConfigPath = path.join(__dirname, '../../Config/DefaultPuerts.ini');
const tsSroucePath = path.join(__dirname, '../../TypeScript');
const jsDefaultConfig = {
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"experimentalDecorators": true,
"useDefineForClassFields": false,
"jsx": "react",
"sourceMap": true,
"typeRoots": [
"Typing",
"./node_modules/@types"
],
"outDir": "Content/JavaScript"
},
"include": [
"TypeScript/**/*"
]
}
const puertsConfig = `
[/Script/Puerts.PuertsSetting]
AutoModeEnable=True
`
function copyFileSync( source, target ) {
var targetFile = target;
//if target is a directory a new file with the same name will be created
if ( fs.existsSync( target ) ) {
if ( fs.lstatSync( target ).isDirectory() ) {
targetFile = path.join( target, path.basename( source ));
}
}
fs.writeFileSync(targetFile, fs.readFileSync(source));
}
function copyFolderRecursiveSync( source, targetFolder ) {
var files = [];
if ( !fs.existsSync( targetFolder ) ) {
fs.mkdirSync( targetFolder );
}
//copy
if ( fs.lstatSync( source ).isDirectory() ) {
files = fs.readdirSync( source );
files.forEach( function ( file ) {
var curSource = path.join( source, file );
if ( fs.lstatSync( curSource ).isDirectory() ) {
copyFolderRecursiveSync( curSource, path.join( targetFolder, file) );
} else {
copyFileSync( curSource, targetFolder );
}
} );
}
}
if (!fs.existsSync(jsBasePath)) {
console.log('copy js files');
copyFolderRecursiveSync(jsSourcePath, jsBasePath);
}
if (!fs.existsSync(tsconfigFilePath)) {
console.log('emit tsconfig.json');
fs.writeFileSync(tsconfigFilePath, JSON.stringify(jsDefaultConfig, null, 4));
} else {
console.warn('Warning: ' + tsconfigFilePath + " existed!");
}
if (!fs.existsSync(puertsConfigPath)) {
console.log('emit DefaultPuerts.ini');
fs.writeFileSync(puertsConfigPath, puertsConfig);
}
if (!fs.existsSync(tsSroucePath)) {
console.log('create TypeScript folder');
fs.mkdirSync( tsSroucePath );
}
if (!fs.existsSync(tsModulePath)) {
console.log('npm install , please wait...');
process.chdir(path.join(jsBasePath, 'PuertsEditor'));
const output = execSync('npm install .', { encoding: 'utf-8' }); // the default is 'buffer'
console.log(output);
}