From c4d8cbf19b0b82d80b7735b1e3313d8fc1251f49 Mon Sep 17 00:00:00 2001 From: monochromer Date: Mon, 29 Apr 2024 17:39:32 +0500 Subject: [PATCH 1/7] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D1=91=D1=82?= =?UTF-8?q?=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B2=D1=8B=D1=87=D0=B8=D1=81=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=80=D0=B0=20=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BB=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B8=20=20mp3-=D1=84=D0=B0=D0=B9=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 7 ++++++ package.json | 4 +++- src/scripts/file-size.js | 47 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/scripts/file-size.js diff --git a/package-lock.json b/package-lock.json index 6ba37eb6..3bece781 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "devDependencies": { "@11ty/eleventy": "^3.0.0-alpha.6", "editorconfig-checker": "^5.1.1", + "get-mp3-duration": "^1.0.0", "html-minifier-terser": "^7.1.0", "js-yaml": "^4.1.0", "minify-xml": "^4.4.1" @@ -1007,6 +1008,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-mp3-duration": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/get-mp3-duration/-/get-mp3-duration-1.0.0.tgz", + "integrity": "sha512-SiTppS0shvqCJ8rky8E1Yi9thLoTTGq3Tjc4n4pmjo8BMuiQFN3cCfiaWmRFk/8TjhOQhPwrpJZJDvOcbPVwrw==", + "dev": true + }, "node_modules/glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", diff --git a/package.json b/package.json index 252d8b3f..c38e3bd2 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "cover": "cd src && rsync --archive --compress cover.png wst@web-standards.ru:/var/www/web-standards.ru/podcast/", "feed": "cd dist && rsync --archive --compress index.xml wst@web-standards.ru:/var/www/web-standards.ru/podcast/feed/", "deploy": "npm run mp3 && npm run cover && npm run feed", - "new": "cp -r src/template src/episodes/$npm_config_episode" + "new": "cp -r src/template src/episodes/$npm_config_episode", + "file-size": "node src/scripts/file-size.js" }, "engines": { "node": ">=16", @@ -18,6 +19,7 @@ "devDependencies": { "@11ty/eleventy": "^3.0.0-alpha.6", "editorconfig-checker": "^5.1.1", + "get-mp3-duration": "^1.0.0", "html-minifier-terser": "^7.1.0", "js-yaml": "^4.1.0", "minify-xml": "^4.4.1" diff --git a/src/scripts/file-size.js b/src/scripts/file-size.js new file mode 100644 index 00000000..ffba61c3 --- /dev/null +++ b/src/scripts/file-size.js @@ -0,0 +1,47 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import getMP3Duration from 'get-mp3-duration'; + +function isFileExist(filePath) { + try { + fs.statSync(filePath); + return true; + } catch { + return false; + } +} + +const folderDataPath = path.join('src', 'episodes'); +const folderMediaPath = path.join('src', 'mp3'); + +const dir = fs.opendirSync(folderDataPath, { + encoding: 'utf-8', + withFileTypes: true +}); + +try { + let item = null; + + while (item = dir.readSync()) { + if (!item.isDirectory()) { + continue; + } + + const episodeFolder = path.join(item.path, item.name); + const dataFilePath = path.join(episodeFolder, 'index.json'); + + if (isFileExist(dataFilePath)) { + continue; + } + + const mediaFilePath = path.join(folderMediaPath, item.name + '.mp3'); + const fileBuffer = fs.readFileSync(mediaFilePath); + const fileSize = fileBuffer.byteLength; + const duration = getMP3Duration(fileBuffer); + + const dataToSave = JSON.stringify({ fileSize, duration }, null, 2); + fs.writeFileSync(dataFilePath, dataToSave, 'utf-8'); + } +} finally { + dir.closeSync(); +} From 5d3cd1496799593d4eee0813e8bfa0efe7ce3d6e Mon Sep 17 00:00:00 2001 From: monochromer Date: Tue, 30 Apr 2024 18:20:14 +0500 Subject: [PATCH 2/7] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D0=B8=D1=82=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20=D0=B2=20?= =?UTF-8?q?=D0=B4=D1=80=D1=83=D0=B3=D1=83=D1=8E=20=D0=BF=D0=B0=D0=BF=D0=BA?= =?UTF-8?q?=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- {src/scripts => scripts}/file-size.js | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename {src/scripts => scripts}/file-size.js (100%) diff --git a/package.json b/package.json index c38e3bd2..6ee9b8f7 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "feed": "cd dist && rsync --archive --compress index.xml wst@web-standards.ru:/var/www/web-standards.ru/podcast/feed/", "deploy": "npm run mp3 && npm run cover && npm run feed", "new": "cp -r src/template src/episodes/$npm_config_episode", - "file-size": "node src/scripts/file-size.js" + "file-size": "node scripts/file-size.js" }, "engines": { "node": ">=16", diff --git a/src/scripts/file-size.js b/scripts/file-size.js similarity index 100% rename from src/scripts/file-size.js rename to scripts/file-size.js From 639b70c47dd2728151b373a6813bb1b9db5cdb5d Mon Sep 17 00:00:00 2001 From: monochromer Date: Wed, 1 May 2024 02:16:32 +0500 Subject: [PATCH 3/7] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=B8=D1=82=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=B4=20=D0=B4=D0=BB=D1=8F=20eslint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/file-size.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/file-size.js b/scripts/file-size.js index ffba61c3..45c6092a 100644 --- a/scripts/file-size.js +++ b/scripts/file-size.js @@ -16,13 +16,13 @@ const folderMediaPath = path.join('src', 'mp3'); const dir = fs.opendirSync(folderDataPath, { encoding: 'utf-8', - withFileTypes: true + withFileTypes: true, }); try { let item = null; - while (item = dir.readSync()) { + while ((item = dir.readSync())) { if (!item.isDirectory()) { continue; } From 6cfdcb936283633fc0872089e312ca42fd207755 Mon Sep 17 00:00:00 2001 From: monochromer Date: Wed, 1 May 2024 11:38:57 +0500 Subject: [PATCH 4/7] =?UTF-8?q?=D0=A4=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D1=83=D0=B5=D1=82=20json=20=D0=BA=D0=B0=D0=BA=20=D1=82?= =?UTF-8?q?=D0=B0=D0=B1=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Vadim Makeev --- scripts/file-size.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/file-size.js b/scripts/file-size.js index 45c6092a..c44f7549 100644 --- a/scripts/file-size.js +++ b/scripts/file-size.js @@ -39,7 +39,7 @@ try { const fileSize = fileBuffer.byteLength; const duration = getMP3Duration(fileBuffer); - const dataToSave = JSON.stringify({ fileSize, duration }, null, 2); + const dataToSave = JSON.stringify({ fileSize, duration }, null, '\t'); fs.writeFileSync(dataFilePath, dataToSave, 'utf-8'); } } finally { From fc4809957657fa12e8c8f4f3ab128ab03e90c602 Mon Sep 17 00:00:00 2001 From: monochromer Date: Wed, 1 May 2024 11:43:27 +0500 Subject: [PATCH 5/7] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D1=83?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=BB=D0=B8=D1=87=D0=B8=D1=8F=20mp3-=D1=84?= =?UTF-8?q?=D0=B0=D0=B9=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/file-size.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/file-size.js b/scripts/file-size.js index c44f7549..2248cc00 100644 --- a/scripts/file-size.js +++ b/scripts/file-size.js @@ -35,6 +35,12 @@ try { } const mediaFilePath = path.join(folderMediaPath, item.name + '.mp3'); + + if (!isFileExist(mediaFilePath)) { + console.log(`В папке '${folderMediaPath}' не найден mp3-файл`); + continue; + } + const fileBuffer = fs.readFileSync(mediaFilePath); const fileSize = fileBuffer.byteLength; const duration = getMP3Duration(fileBuffer); From 2b1fcb1e1e2b47aa815b03c7a6fa246c2b49f71d Mon Sep 17 00:00:00 2001 From: monochromer Date: Wed, 1 May 2024 18:11:02 +0500 Subject: [PATCH 6/7] =?UTF-8?q?=D0=A3=D1=82=D0=BE=D1=87=D0=BD=D1=8F=D0=B5?= =?UTF-8?q?=D1=82=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BE=D0=B1=20=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D1=83=D1=8E=D1=89=D0=B5=D0=BC=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Vadim Makeev --- scripts/file-size.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/file-size.js b/scripts/file-size.js index 2248cc00..30fc8c4b 100644 --- a/scripts/file-size.js +++ b/scripts/file-size.js @@ -37,7 +37,7 @@ try { const mediaFilePath = path.join(folderMediaPath, item.name + '.mp3'); if (!isFileExist(mediaFilePath)) { - console.log(`В папке '${folderMediaPath}' не найден mp3-файл`); + console.log(`Файл '${mediaFilePath}' не найден`); continue; } From f5f1fd237720626ae4978118af76536e654a64ca Mon Sep 17 00:00:00 2001 From: monochromer Date: Thu, 2 May 2024 09:57:42 +0500 Subject: [PATCH 7/7] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=20git=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .husky/pre-commit | 3 +++ package-lock.json | 20 ++++++++++++++++++-- package.json | 4 +++- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 00000000..f8ad42c0 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,3 @@ +npm run test && \ +npm run file-size && \ +git add . diff --git a/package-lock.json b/package-lock.json index 04634cbd..ab9d9fbd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,12 +13,13 @@ "get-mp3-duration": "^1.0.0", "globals": "^15.1.0", "html-minifier-terser": "^7.1.0", + "husky": "^9.0.11", "js-yaml": "^4.1.0", "minify-xml": "^4.4.1" }, "engines": { - "node": ">=20", - "npm": ">=10" + "node": "20", + "npm": "10" } }, "node_modules/@11ty/dependency-tree": { @@ -1820,6 +1821,21 @@ "node": ">= 6" } }, + "node_modules/husky": { + "version": "9.0.11", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.0.11.tgz", + "integrity": "sha512-AB6lFlbwwyIqMdHYhwPe+kjOC3Oc5P3nThEoW/AaO2BX3vJDjWPFxYLxokUZOo6RNX20He3AaT8sESs9NJcmEw==", + "dev": true, + "bin": { + "husky": "bin.mjs" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/ignore": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", diff --git a/package.json b/package.json index 0e7a41c0..a85384da 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "feed": "cd dist && rsync --archive --compress index.xml wst@web-standards.ru:/var/www/web-standards.ru/podcast/feed/", "deploy": "npm run mp3 && npm run cover && npm run feed", "new": "node scripts/new.js", - "file-size": "node scripts/file-size.js" + "file-size": "node scripts/file-size.js", + "prepare": "husky || true" }, "engines": { "node": "20", @@ -24,6 +25,7 @@ "get-mp3-duration": "^1.0.0", "globals": "^15.1.0", "html-minifier-terser": "^7.1.0", + "husky": "^9.0.11", "js-yaml": "^4.1.0", "minify-xml": "^4.4.1" }