mirror of
https://github.com/reifat/daily-notes-sorter.git
synced 2026-07-22 06:42:08 +00:00
release build script has been added
This commit is contained in:
parent
ccdc4a4883
commit
11368f1a19
3 changed files with 975 additions and 2 deletions
868
package-lock.json
generated
868
package-lock.json
generated
File diff suppressed because it is too large
Load diff
12
package.json
12
package.json
|
|
@ -5,9 +5,16 @@
|
|||
"main": "main.js",
|
||||
"scripts": {
|
||||
"dev": "node esbuild.config.mjs",
|
||||
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production"
|
||||
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
|
||||
"release": "npm run build && node scripts/release.js"
|
||||
},
|
||||
"keywords": ["obsidian", "obsidian-plugin", "daily-notes", "sorting", "file-explorer"],
|
||||
"keywords": [
|
||||
"obsidian",
|
||||
"obsidian-plugin",
|
||||
"daily-notes",
|
||||
"sorting",
|
||||
"file-explorer"
|
||||
],
|
||||
"author": "Reifat <https://github.com/Reifat>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
|
@ -17,6 +24,7 @@
|
|||
"@types/node": "^20.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
||||
"@typescript-eslint/parser": "^8.0.0",
|
||||
"archiver": "^7.0.1",
|
||||
"builtin-modules": "3.3.0",
|
||||
"esbuild": "^0.25.12",
|
||||
"eslint": "^9.0.0",
|
||||
|
|
|
|||
97
scripts/release.js
Normal file
97
scripts/release.js
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const archiver = require("archiver");
|
||||
|
||||
function ensureDir(p) {
|
||||
if (!fs.existsSync(p)) fs.mkdirSync(p, { recursive: true });
|
||||
}
|
||||
|
||||
function copyFile(src, dst) {
|
||||
fs.copyFileSync(src, dst);
|
||||
}
|
||||
|
||||
function main() {
|
||||
const cwd = process.cwd();
|
||||
const manifestPath = path.join(cwd, "manifest.json");
|
||||
|
||||
if (!fs.existsSync(manifestPath)) {
|
||||
console.error("manifest.json not found in repository root");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
const pluginId = manifest.id;
|
||||
const pluginVersion = manifest.version;
|
||||
|
||||
if (!pluginId || !pluginVersion) {
|
||||
console.error("Fields 'id' and/or 'version' are missing in manifest.json");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const releaseDir = path.join(cwd, "release");
|
||||
ensureDir(releaseDir);
|
||||
|
||||
// Files to include. styles.css is optional.
|
||||
const sourceFiles = [
|
||||
{ name: "main.js", required: true },
|
||||
{ name: "manifest.json", required: true },
|
||||
{ name: "styles.css", required: false }
|
||||
];
|
||||
|
||||
const filesToZip = [];
|
||||
for (const f of sourceFiles) {
|
||||
const src = path.join(cwd, f.name);
|
||||
if (!fs.existsSync(src)) {
|
||||
if (f.required) {
|
||||
console.error(`Required file is missing: ${f.name}`);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.warn(`Optional file is missing and will be skipped: ${f.name}`);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const dst = path.join(releaseDir, path.basename(f.name));
|
||||
copyFile(src, dst);
|
||||
filesToZip.push(dst);
|
||||
}
|
||||
|
||||
if (filesToZip.length === 0) {
|
||||
console.error("No files to pack");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Archive name: <id>-<version>.zip
|
||||
const zipName = `${pluginId}-${pluginVersion}.zip`;
|
||||
const zipPath = path.join(releaseDir, zipName);
|
||||
|
||||
// Remove existing archive if present
|
||||
if (fs.existsSync(zipPath)) {
|
||||
fs.unlinkSync(zipPath);
|
||||
}
|
||||
|
||||
const output = fs.createWriteStream(zipPath);
|
||||
const archive = archiver("zip", { zlib: { level: 9 } });
|
||||
|
||||
output.on("close", () => {
|
||||
console.log(`Archive ready: ${zipPath} (${archive.pointer()} total bytes)`);
|
||||
});
|
||||
output.on("error", (err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
archive.on("error", (err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
archive.pipe(output);
|
||||
|
||||
// Put files into the root of the archive
|
||||
for (const filePath of filesToZip) {
|
||||
archive.file(filePath, { name: path.basename(filePath) });
|
||||
}
|
||||
|
||||
archive.finalize();
|
||||
}
|
||||
|
||||
main();
|
||||
Loading…
Reference in a new issue