-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
102 lines (99 loc) · 3.89 KB
/
index.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
const fs = require('fs'),
zip = new require('node-zip')(),
path = require('path'),
{ promisify } = require('util'),
readdir = promisify(fs.readdir),
stat = promisify(fs.stat),
pkg = require(path.normalize(__dirname + '/package.json')),
version = pkg.version || "",
evoname = pkg.evoname || "",
category = pkg.category || "Manager and Admin",
author = pkg.author || "",
description = pkg.description || "",
issue = pkg.bugs.url || "",
homepage = pkg.homepage || "",
licensePage = (function(){
let arr = homepage.split('#');
arr.pop();
arr.push('LICENSE');
return arr.join('/');
})(),
license = pkg.license || "",
today = new Date().toLocaleString('ru-RU', { timeZone: 'Europe/Samara' }).split(',').join(''),
DocBlock = `/**
* ${evoname}
*
* ${description}
*
* @category plugin
* @version ${version}
* @package evo
* @internal @events OnManagerMenuPrerender
* @internal @modx_category ${category}
* @internal @properties &logotip=Логотип в Админ Панели;text;assets/plugins/${evoname}/noimage-logotip.png;assets/plugins/${evoname}/noimage-logotip.png;К логотипу будет применён ресайз до размера 140x40
* @internal @installset base
* @internal @disabled 0
* @homepage ${homepage}
* @license ${licensePage} ${license} License (${license})
* @reportissues ${issue}
* @author ${author}
* @lastupdate ${today}
*/`,
tpl = `//<?php\n${DocBlock}\n\n${DocBlock}\ninclude MODX_BASE_PATH . 'assets/plugins/${evoname}/${evoname}.plugin.php';`,
readmeHeader = `| Название | Автор | Дата создания | Дата обновления |
| --- | --- | --- | --- |
| ${evoname} Evolution CMS | ${author} | 2024-01-25 | ${today} |
`;
/**
* Сборка шаблона установки
*/
let readme = fs.readFileSync(path.normalize(path.join(__dirname, '.readme')));
fs.writeFileSync(path.normalize(path.join(__dirname, 'README.md')), `${readmeHeader}\n${readme}`, {encoding: 'utf8'});
fs.writeFileSync(path.normalize(path.join(__dirname, 'install', 'assets', 'plugins', evoname + '.tpl')), tpl, {encoding: 'utf8'});
zip.folder(evoname).file('LICENSE', fs.readFileSync(path.normalize(path.join(__dirname, 'LICENSE'))));
zip.folder(evoname).file('README.md', fs.readFileSync(path.normalize(path.join(__dirname, 'README.md'))));
/**
* Сборка архива
*/
async function getFiles(dir) {
const subdirs = await readdir(dir);
const files = await Promise.all(subdirs.map(async (subdir) => {
const res = path.resolve(dir, subdir);
return (await stat(res)).isDirectory() ? getFiles(res) : res;
}));
return files.reduce((a, f) => a.concat(f), []).map((sub) => {
let file = path.normalize(sub).replace(path.normalize(__dirname), "").replace(/\\+/g, '/').replace(/^\//, "");
return file;
});
}
function normalize(arr){
let arrFile = [];
for(let a in arr){
let old = path.parse(arr[a]);
arrFile.push({
dir: old.dir,
name: old.base
});
}
return arrFile;
}
/**
* Архивируем директории assets и install
*/
getFiles(path.normalize(path.join(__dirname, 'assets'))).then(async function(result){
normalize(result).forEach(function(a, b, c){
let fl = zip.folder(`${pkg.evoname}/${a.dir}`);
fl.file(a.name, fs.readFileSync(path.normalize(path.join(__dirname, a.dir, a.name))));
});
getFiles(path.normalize(path.join(__dirname, 'install'))).then(async function(result){
normalize(result).forEach(function(a, b, c){
let fl = zip.folder(`${pkg.evoname}/${a.dir}`);
fl.file(a.name, fs.readFileSync(path.normalize(path.join(__dirname, a.dir, a.name))));
});
setTimeout(() =>{
let data = zip.generate({base64:false, compression:'DEFLATE'});
fs.writeFileSync(`${pkg.evoname}.zip`, data, 'binary');
console.log(`> SAVE ${pkg.evoname}.zip`);
}, 500);
});
});