forked from krausest/js-framework-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zip.js
113 lines (101 loc) · 3.02 KB
/
zip.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
107
108
109
110
111
112
113
const fs = require("fs");
const path = require("path");
const AdmZip = require("adm-zip");
const zip = new AdmZip();
const outputFile = "build.zip";
const keyedTypes = ["keyed", "non-keyed"];
if (fs.existsSync(outputFile)) {
fs.rmSync(outputFile);
}
/**
* Adds a directory to the zip archive, if it exists.
* @param {string} sourcePath
* @param {string} zipPath
*/
function addLocalFolderIfExists(sourcePath, zipPath) {
if (fs.existsSync(sourcePath)) {
zip.addLocalFolder(sourcePath, zipPath);
}
}
/**
* Adds a file to the zip archive, if it exists.
* @param {string} sourcePath
* @param {string} zipPath
*/
function addLocalFileIfExists(sourcePath, zipPath) {
if (fs.existsSync(sourcePath)) {
zip.addLocalFile(sourcePath, zipPath);
}
}
/**
* Adds frameworks to the zip archive
* @param {string} keyedType
* @param {string} frameworkDir
* @param {string} frameworkName
*/
function addFrameworksToZip(keyedType, frameworkDir, frameworkName) {
const zipFrameworkPath = `frameworks/${keyedType}/${frameworkName}`;
addLocalFileIfExists(
`${frameworkDir}/package-lock.json`,
`${zipFrameworkPath}`
);
addLocalFolderIfExists(`${frameworkDir}/dist`, `${zipFrameworkPath}/dist`);
addLocalFolderIfExists(
`${frameworkDir}/scripts`,
`${zipFrameworkPath}/scripts`
);
addLocalFolderIfExists(
`${frameworkDir}/node_modules/slim-js/dist`,
`${zipFrameworkPath}/node_modules/slim-js/dist`
);
addLocalFolderIfExists(
`${frameworkDir}/node_modules/@neow/core/dist`,
`${zipFrameworkPath}/node_modules/@neow/core/dist`
);
addLocalFolderIfExists(
`${frameworkDir}/target/web/stage`,
`${zipFrameworkPath}/target/web/stage`
);
addLocalFolderIfExists(`${frameworkDir}/build`, `${zipFrameworkPath}/build`);
if (frameworkName !== "ember" && frameworkName !== "glimmer") {
addLocalFolderIfExists(
`${frameworkDir}/public`,
`${zipFrameworkPath}/public`
);
}
if (frameworkName === "halogen") {
addLocalFileIfExists(
`${frameworkDir}/output/bundle.js`,
`${zipFrameworkPath}/output`
);
} else if (frameworkName === "dojo") {
addLocalFolderIfExists(
`${frameworkDir}/output/dist`,
`${zipFrameworkPath}/output/dist`
);
} else if (frameworkName === "stem") {
addLocalFolderIfExists(
`${frameworkDir}/node_modules/babel-polyfill/dist`,
`${zipFrameworkPath}/node_modules/babel-polyfill/dist`
);
addLocalFileIfExists(
`${frameworkDir}/src/bundle.js`,
`${zipFrameworkPath}/src`
);
} else {
addLocalFolderIfExists(
`${frameworkDir}/output`,
`${zipFrameworkPath}/output`
);
}
}
for (const keyedType of keyedTypes) {
const frameworksDir = path.resolve("frameworks", keyedType);
const frameworkNames = fs.readdirSync(frameworksDir);
for (const frameworkName of frameworkNames) {
const frameworkDir = path.resolve(frameworksDir, frameworkName);
console.log("zipping ", frameworkDir);
addFrameworksToZip(keyedType, frameworkDir, frameworkName);
}
}
zip.writeZip(outputFile);