-
Notifications
You must be signed in to change notification settings - Fork 9
/
generate_unitypackage.js
97 lines (74 loc) · 2.74 KB
/
generate_unitypackage.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
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
//
// generate_unitypackage.js [version]
//
// This script creates .unitypackage files in the dist folder with the given version.
//
const path = require('path');
const fs = require('fs');
const os = require('os');
const execSync = require('child_process').execSync;
const args = process.argv.slice(2);
if (args.length === 0) {
console.error('No argument specified');
process.exit(1);
}
const version = args[0];
const rootFolder = path.resolve(__dirname, '..');
const samplesFolder = path.resolve(rootFolder, 'Assets', 'Samples');
const uiComponentsFolder = path.resolve(rootFolder, 'Assets', 'UIComponents');
const distFolder = path.resolve(rootFolder, 'dist');
const outputPluginsFolder = path.resolve(distFolder, 'Plugins');
const outputFolder = path.resolve(outputPluginsFolder, 'UIComponents');
const roslynPackageFolder = path.resolve(
rootFolder, 'Library', 'PackageCache',
);
const dsStoreFile = path.join(rootFolder, '.DS_Store');
if (fs.existsSync(dsStoreFile)) {
fs.rmSync(dsStoreFile);
}
try {
fs.rmSync(distFolder, { recursive: true });
} catch {
console.log('dist folder does not exist, skipping wipe');
}
fs.mkdirSync(distFolder);
fs.mkdirSync(outputPluginsFolder);
fs.mkdirSync(outputFolder);
fs.cpSync(uiComponentsFolder, outputFolder, { recursive: true });
fs.cpSync(samplesFolder, path.join(outputFolder, 'Samples'), { recursive: true });
const samplesFiles = fs.readdirSync(path.join(outputFolder, 'Samples'));
for (const file of samplesFiles)
{
if (file.endsWith('.meta')) {
fs.rmSync(path.join(outputFolder, 'Samples', file));
}
}
const files = fs.readdirSync(rootFolder);
for (const file of files) {
if (file.includes('.md')) {
fs.cpSync(file, path.join(outputFolder, file));
}
}
const unityPackerPath = path.join(rootFolder, 'Scripts', 'UnityPacker.exe');
function createUnityPackerCommand(packageName) {
let cmd = `${unityPackerPath} . ${packageName} Assets/ unitypackage`;
if (os.platform() !== 'win32') {
cmd = 'mono ' + cmd;
}
return cmd;
}
const command = createUnityPackerCommand('UIComponents_' + version);
function executeCommand(command) {
console.log(`Executing command: ${command} in ${distFolder}`);
const output = execSync(command, { cwd: distFolder });
console.log(output.toString());
}
executeCommand(command);
// Uncomment this section to include com.unity.roslyn in the package, if it exists.
// fs.mkdirSync(path.join(outputPluginsFolder, 'com.unity.roslyn'));
// s.cpSync(roslynPackageFolder, path.join(outputPluginsFolder, 'com.unity.roslyn'), { recursive: true });
//
// const secondCommand = createUnityPackerCommand('UIComponents_' + version + '_with_roslyn');;
//
// executeCommand(secondCommand);