-
Notifications
You must be signed in to change notification settings - Fork 43
/
hammer.mjs
52 lines (51 loc) · 2.54 KB
/
hammer.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import * as Fs from 'node:fs'
// -------------------------------------------------------------------------------
// Clean
// -------------------------------------------------------------------------------
export async function clean() {
await folder('target').delete()
}
// -------------------------------------------------------------------------------
// Format
// -------------------------------------------------------------------------------
export async function format() {
await shell('prettier --no-semi --single-quote --print-width 240 --trailing-comma all --write src test example')
}
// -------------------------------------------------------------------------------
// Start
// -------------------------------------------------------------------------------
export async function start(target = 'target/example') {
const start = shell(`hammer serve example/index.html --dist ${target}`)
const drift = shell(`drift wait 100 url http://localhost:5000`)
await Promise.all([start, drift])
}
// -------------------------------------------------------------------------------
// Test
// -------------------------------------------------------------------------------
export async function test(filter = '', target = 'target/test') {
await shell(`hammer build test/index.mts --dist ${target} --platform node`)
const server = require('http').createServer((_, res) => res.end('<html><head></head></html>')).listen(5010)
await shell(`drift url http://localhost:5010 wait 1000 run ./${target}/index.mjs args ${filter}`)
server.close()
}
// -------------------------------------------------------------------------------
// Build
// -------------------------------------------------------------------------------
export async function build(target = 'target/build') {
await clean()
await shell(`tsc -p src/tsconfig.json --outDir ${target} --declaration`)
await folder(target).add('package.json')
await folder(target).add('readme.md')
await folder(target).add('license')
await shell(`cd ${target} && npm pack`)
}
// -------------------------------------------------------------
// Publish
// -------------------------------------------------------------
export async function publish(otp, target = 'target/build') {
const { version } = JSON.parse(Fs.readFileSync('package.json', 'utf8'))
if(version.includes('-dev')) throw Error(`package version should not include -dev specifier`)
await shell(`cd ${target} && npm publish sinclair-smoke-${version}.tgz --access=public --otp ${otp}`)
await shell(`git tag ${version}`)
await shell(`git push origin ${version}`)
}