forked from kaoutarDJAOUD/xd-angular-select-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.extra.js
More file actions
124 lines (113 loc) · 3.74 KB
/
webpack.extra.js
File metadata and controls
124 lines (113 loc) · 3.74 KB
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
114
115
116
117
118
119
120
121
122
123
124
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require("path");
const fs = require("fs");
const zip = require("jszip");
module.exports = {
plugins: [
new CopyWebpackPlugin([
{
from: path.resolve(__dirname,'src/images'),
to: path.resolve(__dirname, "dist/package/images")
},
{
from: path.resolve(__dirname,'src/integration'),
to: path.resolve(__dirname, "dist/package")
}
]),
{
apply: (compiler) => {
compiler.hooks.afterEmit.tapAsync("AfterEmitPlugin", (err, cb) => {
const ensureFolder = (path) => {
const locationBlocks = path.split(/(\\|\/)/i);
const base = locationBlocks.shift();
return locationBlocks
.filter(block => !!block)
.reduce((loc, block) => {
const current = loc + "/" + block;
if (!fs.existsSync(current)) {
fs.mkdirSync(current);
}
return current;
}, base);
}
const appendToArchive = (root, currentPath, archive) => {
const files = fs.readdirSync(path.resolve(root, currentPath));
return files.reduce((prev, current) => {
return prev.then(() => {
const subPath = (currentPath ? currentPath + "/" : "") + current;
const filePath = path.resolve(root, subPath);
return new Promise((resolve, reject) => {
fs.open(filePath, "r", (err, fd) => {
if (err) {
reject(err);
return;
}
const info = fs.fstatSync(fd);
if (info.isDirectory()) {
appendToArchive(root, subPath, archive)
.then(() => resolve());
} else {
const contents = fs.readFileSync(filePath);
archive.file(subPath, contents);
resolve();
}
})
});
});
}, Promise.resolve());
}
const copyAll = (source, target, pattern) => {
let isChecked = false;
const files = fs.readdirSync(source);
files
.forEach(file => {
const fullName = path.resolve(target, file);
if (!path.extname(file)) {
copyAll(path.resolve(source, file), fullName, pattern);
} else if (!pattern || file.match(pattern)) {
if (!isChecked) {
ensureFolder(target);
isChecked = true;
}
fs.copyFileSync(source + "/" + file, fullName);
}
});
}
process.env.ENV_NAME = (process.env.ENV_NAME || "qa").trim();
process.env.BUILD_ID = (process.env.BUILD_ID || "1").trim();
const source = path.resolve(__dirname, "dist/sample-plugin");
const target = path.resolve(__dirname, "dist/package/src");
copyAll(source, target, /.+\.(js|json)$/i);
const targetArtifacts = ensureFolder(path.resolve(__dirname, "dist/artifacts"));
console.log("Creating archive");
const archiver = new zip();
appendToArchive(path.resolve(__dirname, "dist/package"), "", archiver)
.then(() => {
console.log("Compressing...");
const archiveSettings = { type: "uint8array", compression: "DEFLATE", compressionOptions: { level: 9 } };
return archiver.generateAsync(archiveSettings);
}).then(contents => {
const fileName = "sample.plugin.xdx";
console.log(`Writing to ${fileName}...`);
const filePath = path.resolve(targetArtifacts, fileName);
fs.writeFileSync(filePath, contents);
console.log("Done");
cb();
});
})
}
}
],
externals: {
scenegraph: "commonjs scenegraph",
uxp: "commonjs uxp",
application: "commonjs application",
stream: "commonjs stream",
os: "commonjs os",
viewport: "commonjs viewport",
clipboard: "commonjs clipboard",
interactions: "commonjs interactions",
assets: "commonjs assets"
}
}