Skip to content

Commit

Permalink
Merge pull request #74 from dszakallas/add-preamble
Browse files Browse the repository at this point in the history
Add preamble to generated files
  • Loading branch information
dszakallas authored Sep 7, 2023
2 parents 4acd883 + 5ca974d commit 43c3654
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
21 changes: 19 additions & 2 deletions scripts/compile-mapping.js
Original file line number Diff line number Diff line change
@@ -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),
Expand All @@ -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)
32 changes: 30 additions & 2 deletions scripts/compile-scripts.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
#!/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'
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')
}

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),
Expand Down Expand Up @@ -57,5 +84,6 @@ await Promise.all([
format: 'iife',
name: global,
file: resolve(outFile),
banner: getBundleHeader(),
}),
])
10 changes: 10 additions & 0 deletions scripts/template.xml.ejs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?xml version='1.0' encoding='utf-8'?>
<!--
<%= manufacturer %> <%= device %> MIDI mapping for Mixxx
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: <%= gitTag %>
Commit hash: <%= gitHash %>
-->
<MixxxControllerPreset mixxxVersion="1.11+" schemaVersion="1">
<info>
<name><%= manufacturer %> <%= device %></name>
Expand Down

0 comments on commit 43c3654

Please sign in to comment.