This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathgenerateBrowserVersion.js
108 lines (77 loc) · 2.62 KB
/
generateBrowserVersion.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
98
99
100
101
102
103
104
105
106
var webpack = require('webpack');
var rimraf = require("rimraf");
var childProcess = require('child_process');
var path = require("path");
var fs = require("fs");
var isNpm = process.argv[process.argv.indexOf("--type") + 1] === 'npm';
rimraf.sync(isNpm ? "browser_version_npm" : "browser_version");
var bowerJsonDist = path.resolve(__dirname, "./bower.json");
var packageJsonDist = path.resolve(__dirname, "./browser_version_npm/package.json");
childProcess.execSync(isNpm ? "mkdir browser_version_npm" : "mkdir browser_version");
function webPackForBrowserLib() {
var plugins = [];
var config = {
mode: 'production',
optimization: {
minimize: true
},
entry: path.resolve(__dirname, "./dist/index.js"),
plugins: plugins,
output: {
path: path.resolve(__dirname, isNpm ? "./browser_version_npm" : "./browser_version"),
library: ['RAML', 'Parser'],
filename: 'index.js',
libraryTarget: "umd"
},
resolve: {
alias: {
fs: path.resolve(__dirname, "./web-tools/modules/emptyFS.js")
}
},
externals: [
{
"libxml-xsd": true,
"ws": true,
"typescript": true,
"raml-xml-validation": "RAML.XmlValidation",
"raml-json-validation": "RAML.JsonValidation"
}
],
node: {
console: false,
global: true,
process: true,
Buffer: true,
__filename: true,
__dirname: true,
setImmediate: true
}
};
webpack(config, function(err, stats) {
if(err) {
console.log(err.message);
return;
}
console.log("Webpack Building Browser Bundle:");
console.log(stats.toString({reasons : true, errorDetails: true}));
updateVersion();
});
}
function updateVersion() {
var targetJsonPath = isNpm ? packageJsonDist : bowerJsonDist;
var packageJsonPath = path.resolve(__dirname, "./package.json");
var targetJson = {};
var packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
targetJson.version = packageJson.version;
targetJson.name = packageJson.name + '-browser';
targetJson.main = isNpm ? "index.js" : "browser_version/index.js";
if(!isNpm) {
targetJson.ignore = [
"*",
"!browser_version/",
"!browser_version/*"
]
}
fs.writeFileSync(targetJsonPath, JSON.stringify(targetJson, null, '\t'));
}
webPackForBrowserLib();