|
1 |
| -var _ = require('lodash'); |
2 |
| -var exec = require('child_process').execSync; |
3 |
| -var fs = require('fs'); |
4 |
| -var commandExists = require('command-exists'); |
5 |
| -const path = require('path'); |
6 |
| -const rimraf = require('rimraf'); |
| 1 | +const fs = require("fs"); |
| 2 | +const path = require("path"); |
7 | 3 | const AdmZip = require("adm-zip");
|
8 | 4 |
|
9 | 5 | const zip = new AdmZip();
|
10 | 6 | const outputFile = "build.zip";
|
| 7 | +const keyedTypes = ["keyed", "non-keyed"]; |
11 | 8 |
|
12 | 9 | if (fs.existsSync(outputFile)) {
|
13 |
| - fs.rmSync(outputFile); |
| 10 | + fs.rmSync(outputFile); |
14 | 11 | }
|
15 | 12 |
|
16 |
| -for (let keyedType of ['keyed', 'non-keyed']) { |
17 |
| - let dir = path.resolve('frameworks', keyedType); |
18 |
| - let directories = fs.readdirSync(dir); |
19 |
| - |
20 |
| - |
21 |
| - for (let name of directories) { |
22 |
| - let fd = path.resolve(dir, name); |
23 |
| - console.log('zipping ', fd); |
24 |
| - let zipPathName = "frameworks/"+"/"+keyedType+"/"+name; |
25 |
| - |
26 |
| - zip.addLocalFile(fd+"/package-lock.json", zipPathName); |
27 |
| - |
28 |
| - if (fs.existsSync(fd+"/dist")) |
29 |
| - zip.addLocalFolder(fd+"/dist", zipPathName+"/dist"); |
30 |
| - if (fs.existsSync(fd+"/scripts/")) |
31 |
| - zip.addLocalFolder(fd+"/scripts/", zipPathName+"/scripts/"); |
32 |
| - if (fs.existsSync(fd+"/node_modules/skruv/")) |
33 |
| - zip.addLocalFolder(fd+"/node_modules/skruv/", zipPathName+"/node_modules/skruv/"); |
34 |
| - if (fs.existsSync(fd+"/node_modules/slim-js/dist")) |
35 |
| - zip.addLocalFolder(fd+"/node_modules/slim-js/dist", zipPathName+"/node_modules/slim-js/dist"); |
36 |
| - if (fs.existsSync(fd+"/node_modules/@neow/core/dist")) |
37 |
| - zip.addLocalFolder(fd+"/node_modules/@neow/core/dist", zipPathName+"/node_modules/@neow/core/dist"); |
38 |
| - if (name=="stem" && fs.existsSync(fd+"/node_modules/babel-polyfill/dist/")) { |
39 |
| - zip.addLocalFolder(fd+"/node_modules/babel-polyfill/dist/", zipPathName+"/node_modules/babel-polyfill/dist/"); |
40 |
| - zip.addLocalFile(fd+"/src/bundle.js", zipPathName+"/src") |
41 |
| - } |
42 |
| - if (fs.existsSync(fd+"/public/") && ["ember","glimmer"].indexOf(name)==-1) { |
43 |
| - zip.addLocalFolder(fd+"/public/", zipPathName+"/public/"); |
44 |
| - } |
45 |
| - if (["karyon"].indexOf(name)>-1) { |
46 |
| - zip.addLocalFile(fd+"/app.bundle.js", zipPathName) |
47 |
| - } |
48 |
| - if (fs.existsSync(fd+"/target/web/stage")) |
49 |
| - zip.addLocalFolder(fd+"/target/web/stage", zipPathName+"/target/web/stage"); |
50 |
| - if (name=="halogen" && fs.existsSync(fd+"/output")) { |
51 |
| - zip.addLocalFile(fd+"/output/bundle.js", zipPathName+"/output") |
52 |
| - } else if (name=="dojo" && fs.existsSync(fd+"/output/dist")) { |
53 |
| - zip.addLocalFolder(fd+"/output/dist", zipPathName+"/output/dist", (file) => { |
54 |
| - return !file.includes("/"); |
55 |
| - }); |
56 |
| - } else if (fs.existsSync(fd+"/output")) |
57 |
| - zip.addLocalFolder(fd+"/output", zipPathName+"/output"); |
58 |
| - if (fs.existsSync(fd+"/build")) |
59 |
| - zip.addLocalFolder(fd+"/build", zipPathName+"/build"); |
60 |
| - } |
| 13 | +/** |
| 14 | + * Adds a directory to the zip archive, if it exists. |
| 15 | + * @param {string} sourcePath |
| 16 | + * @param {string} zipPath |
| 17 | + */ |
| 18 | +function addLocalFolderIfExists(sourcePath, zipPath) { |
| 19 | + if (fs.existsSync(sourcePath)) { |
| 20 | + zip.addLocalFolder(sourcePath, zipPath); |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +/** |
| 25 | + * Adds a file to the zip archive, if it exists. |
| 26 | + * @param {string} sourcePath |
| 27 | + * @param {string} zipPath |
| 28 | + */ |
| 29 | +function addLocalFileIfExists(sourcePath, zipPath) { |
| 30 | + if (fs.existsSync(sourcePath)) { |
| 31 | + zip.addLocalFile(sourcePath, zipPath); |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +/** |
| 36 | + * Adds frameworks to the zip archive |
| 37 | + * @param {string} keyedType |
| 38 | + * @param {string} frameworkDir |
| 39 | + * @param {string} frameworkName |
| 40 | + */ |
| 41 | +function addFrameworksToZip(keyedType, frameworkDir, frameworkName) { |
| 42 | + const zipFrameworkPath = `frameworks/${keyedType}/${frameworkName}`; |
| 43 | + |
| 44 | + addLocalFileIfExists( |
| 45 | + `${frameworkDir}/package-lock.json`, |
| 46 | + `${zipFrameworkPath}` |
| 47 | + ); |
| 48 | + |
| 49 | + addLocalFolderIfExists(`${frameworkDir}/dist`, `${zipFrameworkPath}/dist`); |
| 50 | + addLocalFolderIfExists( |
| 51 | + `${frameworkDir}/scripts`, |
| 52 | + `${zipFrameworkPath}/scripts` |
| 53 | + ); |
| 54 | + addLocalFolderIfExists( |
| 55 | + `${frameworkDir}/node_modules/skruv`, |
| 56 | + `${zipFrameworkPath}/node_modules/skruv` |
| 57 | + ); |
| 58 | + addLocalFolderIfExists( |
| 59 | + `${frameworkDir}/node_modules/slim-js/dist`, |
| 60 | + `${zipFrameworkPath}/node_modules/slim-js/dist` |
| 61 | + ); |
| 62 | + addLocalFolderIfExists( |
| 63 | + `${frameworkDir}/node_modules/@neow/core/dist`, |
| 64 | + `${zipFrameworkPath}/node_modules/@neow/core/dist` |
| 65 | + ); |
| 66 | + addLocalFolderIfExists( |
| 67 | + `${frameworkDir}/target/web/stage`, |
| 68 | + `${zipFrameworkPath}/target/web/stage` |
| 69 | + ); |
| 70 | + addLocalFolderIfExists(`${frameworkDir}/build`, `${zipFrameworkPath}/build`); |
| 71 | + |
| 72 | + if (frameworkName !== "ember" && frameworkName !== "glimmer") { |
| 73 | + addLocalFolderIfExists( |
| 74 | + `${frameworkDir}/public`, |
| 75 | + `${zipFrameworkPath}/public` |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + if (frameworkName === "halogen") { |
| 80 | + addLocalFileIfExists( |
| 81 | + `${frameworkDir}/output/bundle.js`, |
| 82 | + `${zipFrameworkPath}/output` |
| 83 | + ); |
| 84 | + } else if (frameworkName === "dojo") { |
| 85 | + addLocalFolderIfExists( |
| 86 | + `${frameworkDir}/output/dist`, |
| 87 | + `${zipFrameworkPath}/output/dist` |
| 88 | + ); |
| 89 | + } else if (frameworkName === "stem") { |
| 90 | + addLocalFolderIfExists( |
| 91 | + `${frameworkDir}/node_modules/babel-polyfill/dist`, |
| 92 | + `${zipFrameworkPath}/node_modules/babel-polyfill/dist` |
| 93 | + ); |
| 94 | + addLocalFileIfExists( |
| 95 | + `${frameworkDir}/src/bundle.js`, |
| 96 | + `${zipFrameworkPath}/src` |
| 97 | + ); |
| 98 | + } else if (frameworkName === "karyon") { |
| 99 | + addLocalFileIfExists(`${frameworkDir}/app.bundle.js`, zipFrameworkPath); |
| 100 | + } else { |
| 101 | + addLocalFolderIfExists( |
| 102 | + `${frameworkDir}/output`, |
| 103 | + `${zipFrameworkPath}/output` |
| 104 | + ); |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +for (const keyedType of keyedTypes) { |
| 109 | + const frameworksDir = path.resolve("frameworks", keyedType); |
| 110 | + const frameworkNames = fs.readdirSync(frameworksDir); |
| 111 | + |
| 112 | + for (const frameworkName of frameworkNames) { |
| 113 | + const frameworkDir = path.resolve(frameworksDir, frameworkName); |
| 114 | + console.log("zipping ", frameworkDir); |
| 115 | + |
| 116 | + addFrameworksToZip(keyedType, frameworkDir, frameworkName); |
| 117 | + } |
61 | 118 | }
|
62 | 119 | zip.writeZip(outputFile);
|
0 commit comments