From 4d062fb9f764c183c098636d4cabfe008f2b5284 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Mon, 27 Nov 2023 13:18:38 +0100 Subject: [PATCH] Add a copyright banner to built files --- package-lock.json | 13 ++++++++++--- package.json | 1 + vite.config.js | 20 ++++++++++++++------ vite.version.js | 17 +++++++++++++++++ 4 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 vite.version.js diff --git a/package-lock.json b/package-lock.json index 1cc8304b..41e42575 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "file-saver": "^2.0.5", "laravel-vite-plugin": "^0.8.0", "laravel-vue-i18n": "^2.7.1", + "php-parser": "^3.1.5", "pinia": "^2.1.6", "sass": "^1.67.0", "sortablejs": "^1.15.0", @@ -1443,6 +1444,12 @@ "vue": "^3.2.45" } }, + "node_modules/laravel-vue-i18n/node_modules/php-parser": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/php-parser/-/php-parser-3.1.3.tgz", + "integrity": "sha512-hPvBmnRYPqWEtMfIFOlyjQv1q75UUtxt4U+YscKIQViGmEE2Xa4BuS1B1/cZdjy7MVcwtnr0WkEsr915LgRKOw==", + "dev": true + }, "node_modules/local-pkg": { "version": "0.4.3", "resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-0.4.3.tgz", @@ -1571,9 +1578,9 @@ "dev": true }, "node_modules/php-parser": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/php-parser/-/php-parser-3.1.3.tgz", - "integrity": "sha512-hPvBmnRYPqWEtMfIFOlyjQv1q75UUtxt4U+YscKIQViGmEE2Xa4BuS1B1/cZdjy7MVcwtnr0WkEsr915LgRKOw==", + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/php-parser/-/php-parser-3.1.5.tgz", + "integrity": "sha512-jEY2DcbgCm5aclzBdfW86GM6VEIWcSlhTBSHN1qhJguVePlYe28GhwS0yoeLYXpM2K8y6wzLwrbq814n2PHSoQ==", "dev": true }, "node_modules/picocolors": { diff --git a/package.json b/package.json index 71276306..5bfeb0b4 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "file-saver": "^2.0.5", "laravel-vite-plugin": "^0.8.0", "laravel-vue-i18n": "^2.7.1", + "php-parser": "^3.1.5", "pinia": "^2.1.6", "sass": "^1.67.0", "sortablejs": "^1.15.0", diff --git a/vite.config.js b/vite.config.js index 1b823c30..70ed6e58 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,8 +1,9 @@ -import { defineConfig } from 'vite'; -import laravel from 'laravel-vite-plugin'; -import vue from '@vitejs/plugin-vue'; -import i18n from 'laravel-vue-i18n/vite'; -import AutoImport from 'unplugin-auto-import/vite'; +import { defineConfig } from 'vite' +import laravel from 'laravel-vite-plugin' +import vue from '@vitejs/plugin-vue' +import i18n from 'laravel-vue-i18n/vite' +import AutoImport from 'unplugin-auto-import/vite' +import version from './vite.version' export default defineConfig({ plugins: [ @@ -67,4 +68,11 @@ export default defineConfig({ '@': '/resources/js_vue3', }, }, -}); \ No newline at end of file + build: { + rollupOptions: { + output: { + banner: '/*! 2FAuth version ' + version + ' - Copyright (c) 2023 Bubka - https://github.com/Bubka/2FAuth */', + }, + }, + }, +}); diff --git a/vite.version.js b/vite.version.js new file mode 100644 index 00000000..31ccc362 --- /dev/null +++ b/vite.version.js @@ -0,0 +1,17 @@ +import * as fs from 'fs'; +import { Engine } from 'php-parser'; + +const parser = new Engine({ + parser: { + extractDoc: false, + }, + ast: { + withPositions: true, + }, +}) + +const phpFile = fs.readFileSync("./config/2fauth.php") +const phpContent = parser.parseCode(phpFile) +const version = phpContent.children[0].expr.items[0].value.value + +export default version \ No newline at end of file