This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { $ } from 'bun'; | ||
import { parseArgs } from 'util'; | ||
|
||
const { values } = parseArgs({ | ||
args: Bun.argv, | ||
options: { | ||
tag: { | ||
type: 'string', | ||
default: 'SNAPSHOT' | ||
}, | ||
src: { | ||
type: 'string', | ||
default: 'src' | ||
}, | ||
dest: { | ||
type: 'string', | ||
default: 'dist' | ||
}, | ||
templates: { | ||
type: 'string', | ||
default: 'project,static,shared' | ||
} | ||
}, | ||
allowPositionals: true, | ||
}); | ||
|
||
const main = async ({ tag, src, dest, templates }) => { | ||
await log(`cleaning up ${dest}...`); | ||
|
||
await $`rm -rfv ${dest}` | ||
await $`mkdir -p ${dest}` | ||
|
||
await log(`parsing templates from ${src}...`); | ||
|
||
for (const template of templates.split(',')) { | ||
await log(`generating ${template}...`); | ||
|
||
await $`rsync -r --exclude-from=${src}/${template}/.gitignore ${src}/${template} ${dest}` | ||
await $`rsync -r ${src}/${template}/.vscode ${dest}/${template}` | ||
|
||
const lines = await generate(`${src}/${template}`) | ||
await $`echo ${lines.join('\n')} | tee ${dest}/${template}/makefile` | ||
|
||
await log(`generating release files for ${template}...`); | ||
|
||
await $`tar -czvf ${template}-${tag}.tar.gz ${template}`.cwd(dest) | ||
await $`md5sum ${template}-${tag}.tar.gz > ${template}-${tag}.tar.gz.md5`.cwd(dest) | ||
await $`sha1sum ${template}-${tag}.tar.gz > ${template}-${tag}.tar.gz.sha1`.cwd(dest) | ||
|
||
await log(`cleaning up ${template}...`); | ||
|
||
await $`rm -rfv ${template}`.cwd(dest) | ||
} | ||
} | ||
|
||
const log = async (line) => { | ||
await $`echo '\n\n'${line}'\n\n'` | ||
} | ||
|
||
const generate = async (dir) => { | ||
const lines = await $`cat ${dir}/makefile`.text() | ||
return Promise.all(lines.split('\n').map(line => parseLine(line, dir))) | ||
} | ||
|
||
const parseLine = async (line = '', dir = '.') => { | ||
if (line.startsWith('include ../')) { | ||
return await include(line, dir) | ||
} | ||
return line; | ||
} | ||
|
||
const include = async (line, dir) => { | ||
const [_, filename] = line.split(' ') | ||
return await $`cat ${dir}/${filename}`.text() | ||
} | ||
|
||
await main(values); |