✨ Generate a zip archive with all buttons
This commit is contained in:
parent
1496614da1
commit
fdf5808029
3 changed files with 76 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
output
|
||||
tmp
|
||||
build
|
||||
node_modules
|
||||
package-lock.json
|
82
main.js
82
main.js
|
@ -1,10 +1,15 @@
|
|||
import data from './data.json' with { type: "json" };
|
||||
import gm from "gm";
|
||||
import * as fs from "fs";
|
||||
|
||||
import archiver from 'archiver';
|
||||
import * as path from "path";
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const myGm = gm.subClass({imageMagick: true});
|
||||
|
||||
const VERSION = process.env.npm_package_version;
|
||||
const zipname = `pride-button-${VERSION}.zip`;
|
||||
|
||||
const position = {x: 4, y: 2, gravity: "NorthEast"}
|
||||
const metadatas = []
|
||||
|
||||
|
@ -51,6 +56,39 @@ function createMetadatas(prideflag, text, now = false) {
|
|||
return {file:filename, alt:alt, localizedAlt:{en: alten, fr: alt}, text:textForAlt};
|
||||
}
|
||||
|
||||
// Prepare folders
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
fs.mkdir(path.join(__dirname, 'build'),
|
||||
{ recursive: true },
|
||||
(err) => {
|
||||
if (err) {
|
||||
return console.error(err);
|
||||
}
|
||||
console.log('Build directory created successfully!');
|
||||
});
|
||||
fs.mkdir(path.join(__dirname, 'output'),
|
||||
{ recursive: true },
|
||||
(err) => {
|
||||
if (err) {
|
||||
return console.error(err);
|
||||
}
|
||||
console.log('Output directory created successfully!');
|
||||
});
|
||||
fs.mkdir(path.join(__dirname, 'tmp'),
|
||||
{ recursive: true },
|
||||
(err) => {
|
||||
if (err) {
|
||||
return console.error(err);
|
||||
}
|
||||
console.log('Tmp directory created successfully!');
|
||||
});
|
||||
|
||||
|
||||
// Start generating
|
||||
|
||||
let count = 0;
|
||||
let flagCount = 0;
|
||||
const start = Date.now();
|
||||
|
@ -105,16 +143,42 @@ data.forEach(prideflag => {
|
|||
metadatas.push(imageMetadata);
|
||||
});
|
||||
|
||||
const millis = Date.now() - start;
|
||||
console.log("");
|
||||
console.log("-----------------------")
|
||||
console.log(`Generation finished in ${millis / 1000}s`);
|
||||
console.log(`${flagCount} flags processed`);
|
||||
console.log(`${count} files generated`);
|
||||
|
||||
fs.writeFile("./output/pridebuttons.json", JSON.stringify(metadatas), (err) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Zip the folder
|
||||
|
||||
var output = fs.createWriteStream(`build/${zipname}`);
|
||||
var archive = archiver('zip');
|
||||
|
||||
output.on('close', function () {
|
||||
console.log(archive.pointer() + ' total bytes');
|
||||
console.log('archiver has been finalized and the output file descriptor has closed.');
|
||||
});
|
||||
|
||||
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('output/', false);
|
||||
|
||||
archive.finalize();
|
||||
|
||||
// Show final result
|
||||
|
||||
const millis = Date.now() - start;
|
||||
setTimeout(() => {
|
||||
console.log("");
|
||||
console.log("-----------------------")
|
||||
console.log(`Pride Button version ${VERSION}`);
|
||||
console.log(`Generation finished in ${millis / 1000}s`);
|
||||
console.log(`${flagCount} flags processed`);
|
||||
console.log(`${count} files generated`);
|
||||
}, 500);
|
|
@ -1,11 +1,12 @@
|
|||
{
|
||||
"name": "pride-button",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.1",
|
||||
"description": "A set of pride buttons",
|
||||
"scripts": {
|
||||
"build": "node main.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"archiver": "^7.0.1",
|
||||
"gm": "^1.25.0"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue