Repository navigation
Expand file tree
/
Copy pathzipper.js
More file actions
55 lines (47 loc) · 2.32 KB
/
Copy pathzipper.js
File metadata and controls
55 lines (47 loc) · 2.32 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
import { zip } from 'zip-a-folder';
import color from "picocolors"
import pkg from "./package.json" with { type: "json" };
import * as fs from 'fs';
// REMOVE PREVIOUS ZIP FILES
// Doesn't care what zip it is. Any zip is removed (from the root).
const root = fs.readdirSync('./');
const files = root.filter( ( elm ) => elm.match(/.*\.(zip?)/ig));
files.forEach(function( file ) {
fs.rmSync('./'+ file, { force: true });
});
// // Fish
// const files = root.filter( ( elm ) => elm.match(/.*\.(zip?)/ig));
// files.forEach(function( file ) {
// fs.rmSync('./'+ file, { force: true });
// });
// MAKE A NEW ZIP FILE FROM './dist'
var version = pkg.version ? '-'+pkg.version : '';
var draft = pkg.draft ? '-draft' : '';
var filename = `${pkg.name}${version}${draft}.zip`;
var padding = 3;
var repeatString = (str, num) => {
return num > 0 ? Array(num+1).join(str) : "";
};
var horizontalLineLength = Math.ceil((filename.length/2) + (padding*2));
var horizontalLine = ' ' + repeatString('— ', horizontalLineLength );
horizontalLineLength = horizontalLine.length;
var msg = ["Extension zipped","successfully!"];
var msgLength = msg.join(" ").length;
var msgDiff = Math.ceil((horizontalLineLength - msgLength) / 2);
var msgPadding = repeatString(' ', msgDiff);
var msgPaddingMinus = (msgLength + (msgDiff*2)) > horizontalLineLength ? 1 : 0;
var filenameLength = filename.length;
var filenameDiff = Math.ceil((horizontalLineLength - filenameLength) / 2);
var filenamePadding = repeatString(' ', filenameDiff);
var filenamePaddingMinus = (filenameLength + (filenameDiff*2)) > horizontalLineLength ? 1 : 0;
//zip a folder and change folder destination name
zip('./dist', './'+ filename).then(() => {
console.log(' ');
console.log( color.gray(`+${horizontalLine}+`) );
console.log( color.gray('|') + repeatString(' ', horizontalLineLength) + color.gray('|') );
console.log( color.gray('|') + color.green(`${msgPadding}${msg[0]} ${color.bold(msg[1])}${msgPadding.substring(msgPaddingMinus)}`) + color.gray('|') );
console.log( color.gray('|') + color.yellow( filenamePadding + color.bold(filename) + filenamePadding.substring(filenamePaddingMinus) ) + color.gray('|') );
console.log( color.gray('|') + repeatString(' ', horizontalLineLength) + color.gray('|') );
console.log( color.gray(`+${horizontalLine}+`) );
console.log(' ');
});