-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnpm-update-libs.js
104 lines (93 loc) · 2.86 KB
/
npm-update-libs.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
const path = require('path');
const fs = require('fs').promises;
const cp = require('child_process');
const utils = require('util');
const exec = utils.promisify(cp.exec);
(async () => {
const pckJsonPath = path.join('package.json');
const tmpDir = path.join('tmp');
try {
await exec(`rm -rf ${tmpDir}`);
await exec(`mkdir -p ${tmpDir}`);
} catch (error) {
console.log(error);
return;
}
try {
const pck = await fs.readFile(pckJsonPath, {
encoding: 'utf8'
});
const pckJson = JSON.parse(pck);
for (let packageName in pckJson.dependencies) {
const version = pckJson.dependencies[packageName].replace(/~|\^/g, '');
const packageInstallation = `${packageName}@${version}`;
const packCmd = `npm pack ${packageInstallation} --pack-destination ${tmpDir}`;
const tarCmd = `tar -xzvf ${path.join(tmpDir, packageInstallation.replace('@', '-'))}.tgz --transform='s/package/${packageName}/g' -C ${tmpDir}`;
console.log('Packing library ' + packageInstallation);
await exec(packCmd);
await exec(tarCmd);
}
} catch (error) {
console.log(error);
return;
}
try {
const targetDir = path.join('src', 'main', 'resources', 'org', 'geoserver', 'wms', 'web', 'data', 'lib');
const packagesToUpdate = [
{
from: path.join(tmpDir, 'react', 'umd', 'react.production.min.js'),
to: targetDir
},
{
from: path.join(tmpDir, 'react-dom', 'umd', 'react-dom.production.min.js'),
to: targetDir
},
{
from: path.join(tmpDir, 'dayjs', 'dayjs.min.js'),
to: targetDir
},
{
from: path.join(tmpDir, 'antd', 'dist', 'antd.min.js'),
to: targetDir
},
{
from: path.join(tmpDir, 'antd', 'dist', 'reset.css'),
to: targetDir
},
{
from: path.join(tmpDir, 'ol', 'dist', 'ol.js'),
to: targetDir
},
{
from: path.join(tmpDir, 'geostyler', 'browser', 'style.css'),
to: targetDir
},
{
from: path.join(tmpDir, 'geostyler', 'browser', 'geostyler.js.iife.js'),
to: targetDir
},
{
from: path.join(tmpDir, 'geostyler-geojson-parser', 'browser', 'geoJsonDataParser.js'),
to: targetDir
},
{
from: path.join(tmpDir, 'geostyler-sld-parser', 'browser', 'sldStyleParser.iife.js'),
to: targetDir
},
{
from: path.join(tmpDir, 'geostyler-wfs-parser', 'browser', 'wfsDataParser.js'),
to: targetDir
}
];
await exec(`rm -rf ${targetDir}`);
await exec(`mkdir -p ${targetDir}`);
for (let package of packagesToUpdate) {
console.log(`Copying from ${package.from} to ${package.to}`);
const copyCmd = `cp -r ${package.from} ${package.to}`;
await exec(copyCmd);
}
} catch (error) {
console.error(error);
return;
}
})();