From fe048f44bba727bfd5a3d15d761e7a88a53b4440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Szak=C3=A1llas?= Date: Sun, 3 Sep 2023 19:32:50 +0200 Subject: [PATCH] add preamble to generated files --- scripts/compile-mapping.js | 21 +++++++++++++++++++-- scripts/compile-scripts.js | 32 ++++++++++++++++++++++++++++++-- scripts/template.xml.ejs | 10 ++++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/scripts/compile-mapping.js b/scripts/compile-mapping.js index f334fa1..a1efc35 100755 --- a/scripts/compile-mapping.js +++ b/scripts/compile-mapping.js @@ -1,14 +1,29 @@ #!/usr/bin/env node -import ejs from 'ejs' -import { resolve, dirname, join } from 'path' +import { resolve, dirname, join } from 'node:path' import { readFile, writeFile } from 'node:fs/promises' +import { exec } from 'node:child_process' +import { promisify } from'node:util' + +import ejs from 'ejs' import mkdirp from 'mkdirp' if (process.argv.length !== 4) { throw Error('Usage: target outFile') } +const execAsync = promisify(exec) + +const gitSHA = async () => { + const { stdout } = await execAsync('git rev-parse HEAD') + return stdout.trim() +} + +const gitTagAlwaysDirty = async () => { + const { stdout } = await execAsync('git describe --tags --always --dirty') + return stdout.trim() +} + const [tgt, outFile] = process.argv.slice(-2) const [pkg, controller] = await Promise.all([ readFile(resolve('packages', tgt, 'package.json')).then(JSON.parse), @@ -29,6 +44,8 @@ const rendered = ejs.render(template.toString(), { buttons: Object.values(controller.controls), hexFormat: hexFormat, sysex: controller.sysex, + gitTag: await gitTagAlwaysDirty(), + gitHash: await gitSHA(), }) await mkdirp(dirname(resolve(outFile))) await writeFile(resolve(outFile), rendered) diff --git a/scripts/compile-scripts.js b/scripts/compile-scripts.js index 68d9a37..44fa220 100755 --- a/scripts/compile-scripts.js +++ b/scripts/compile-scripts.js @@ -1,6 +1,10 @@ #!/usr/bin/env node -import { resolve, dirname } from 'path' +import { readFile, writeFile } from 'node:fs/promises' +import { exec } from 'node:child_process' +import { promisify } from'node:util' +import { resolve, dirname, basename } from 'node:path' + import mkdirp from 'mkdirp' import { rollup } from 'rollup' @@ -8,7 +12,8 @@ import nodeResolve from '@rollup/plugin-node-resolve' import babel from '@rollup/plugin-babel' import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' -import { readFile, writeFile } from 'node:fs/promises' + +const execAsync = promisify(exec) if (process.argv.length !== 4) { throw Error('Usage: target outFile') @@ -16,6 +21,28 @@ if (process.argv.length !== 4) { const [tgt, outFile] = process.argv.slice(-2) +const gitSHA = async () => { + const { stdout } = await execAsync('git rev-parse HEAD') + return stdout.trim() +} + +const gitTagAlwaysDirty = async () => { + const { stdout } = await execAsync('git describe --tags --always --dirty') + return stdout.trim() +} + +const getBundleHeader = async () => `/* eslint-disable */ +/* + * ${basename(outFile)} + * + * This file is generated. Do not edit directly. + * Instead, edit the source file and regenerate it. + * See https://github.com/dszakallas/mixxx-launchpad#building-from-source. + * + * Commit tag: ${await gitTagAlwaysDirty()} + * Commit hash: ${await gitSHA()} + */` + const [tgtPkg, controller, cache] = await Promise.all([ readFile(resolve('packages', tgt, 'package.json')).then(JSON.parse), readFile(resolve('packages', tgt, 'controller.json')).then(JSON.parse), @@ -57,5 +84,6 @@ await Promise.all([ format: 'iife', name: global, file: resolve(outFile), + banner: getBundleHeader(), }), ]) diff --git a/scripts/template.xml.ejs b/scripts/template.xml.ejs index 2863030..9d02a5c 100644 --- a/scripts/template.xml.ejs +++ b/scripts/template.xml.ejs @@ -1,4 +1,14 @@ + <%= manufacturer %> <%= device %>