-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract-plugin.js
157 lines (135 loc) · 3.16 KB
/
extract-plugin.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const fs = require("fs");
const fse = require("fs-extra");
const archiver = require("archiver");
const CURRENT_DIRECTORY = __dirname;
const colors = {
reset: "\x1b[0m",
fg: {
black: "\x1b[30m",
},
bg: {
green: "\x1b[42m",
red: "\x1b[41m",
yellow: "\x1b[43m",
blue: "\x1b[44m",
},
};
/**
* Print message to console
* @param {string} text console text
* @param {string} type - success [success, warning, error]
*/
function print(text, type = "success") {
let bg = colors.bg.green;
let fg = colors.fg.black;
if (type === "info") bg = colors.bg.blue;
if (type === "warning") bg = colors.bg.yellow;
if (type === "error") bg = colors.bg.red;
console.log(bg, fg, text, colors.reset);
console.log("");
}
print("extracting plugin ...", "info");
/**
* Get build folder dashboard
*/
if (!fs.existsSync(CURRENT_DIRECTORY + "/dashboard")) {
print(
"/dashboard directory not found. First build with npm run build, then run this command",
"error"
);
process.exit(1);
}
// Create a new folder
fs.mkdirSync(CURRENT_DIRECTORY + "/plugin");
print("created new folder '/plugin'");
/**
* Copy xynity-blocks.php
*/
fse.copySync(
CURRENT_DIRECTORY + "/xynity-blocks.php",
CURRENT_DIRECTORY + "/plugin/xynity-blocks.php",
{
overwrite: true,
}
);
print("copied xynity-blocks.php");
/**
* Copy uninstall.php
*/
fse.copySync(
CURRENT_DIRECTORY + "/uninstall.php",
CURRENT_DIRECTORY + "/plugin/uninstall.php",
{
overwrite: true,
}
);
print("copied uninstall.php");
/**
* Copy LICENSE
*/
fse.copySync(
CURRENT_DIRECTORY + "/LICENSE",
CURRENT_DIRECTORY + "/plugin/LICENSE",
{
overwrite: true,
}
);
print("copied LICENSE");
/**
* Copy README.md
*/
fse.copySync(
CURRENT_DIRECTORY + "/README.md",
CURRENT_DIRECTORY + "/plugin/README.md",
{
overwrite: true,
}
);
print("copied README.md");
/**
* Copy includes folder
*/
fse.copySync(
CURRENT_DIRECTORY + "/includes/",
CURRENT_DIRECTORY + "/plugin/includes/",
{
overwrite: true,
}
);
print("copying files in /plugin/includes/ from /includes done");
/**
* Copy blocks folder
*/
fse.copySync(
CURRENT_DIRECTORY + "/blocks/build/",
CURRENT_DIRECTORY + "/plugin/blocks/build/",
{
overwrite: true,
}
);
print("copying files in /plugin/blocks/build from /plugin/blocks/build done");
/**
* Copy dashboard folder
*/
fse.copySync(
CURRENT_DIRECTORY + "/dashboard/",
CURRENT_DIRECTORY + "/plugin/dashboard/",
{
overwrite: true,
}
);
print("copying files in /plugin/dashboard/ from /dashboard done");
print("creating xynity-blocks.zip", "info");
let output = fs.createWriteStream("xynity-blocks.zip");
let archive = archiver("zip");
output.on("close", function () {
print(archive.pointer() + " total bytes", "info");
print("Creating xynity-blocks.zip done");
});
archive.on("error", function (err) {
throw err;
});
archive.pipe(output);
// append files from a sub-directory, putting its contents at the root of archive
archive.directory(CURRENT_DIRECTORY + "/plugin/", false);
archive.finalize();