This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
sass
Archived
1
0
Fork 0
sass/update.mjs

71 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-02-21 16:38:26 +08:00
/**
* {}
* @author yutent<yutent.io@gmail.com>
* @date 2023/02/15 22:46:25
*/
import Es from 'esbuild'
import fs from 'iofs'
import { resolve } from 'path'
import { exec } from 'child_process'
import pkg from './package.json' assert { type: 'json' }
const NPM_URL = 'https://registry.npmmirror.com'
const PKG_NAME = 'sass'
function download(url) {
return fetch(url).then(r => r.arrayBuffer())
}
export function execAsync(cmd) {
return new Promise((yes, no) => {
exec(cmd, { cwd: resolve('./') }, (err, res) => {
if (err) {
no(err)
} else {
yes(res)
}
})
})
}
!(async function () {
let { version, url } = await fetch(
'https://registry.npmmirror.com/' + PKG_NAME,
{
headers: {
'content-type': 'application/json',
accept: 'application/json'
}
}
)
.then(r => r.json())
.then(r => {
let v = r['dist-tags'].latest
let url = r.versions[v].dist.tarball
return { version: v, url }
})
let ab = await download(url)
pkg.version = version
fs.echo(JSON.stringify(pkg, null, 2), './package.json')
fs.echo(Buffer.from(ab), `./${PKG_NAME}.tgz`)
await execAsync(`tar -xzf ${PKG_NAME}.tgz`)
Es.buildSync({
entryPoints: ['package/sass.default.dart.js', 'package/sass.dart.js'],
outdir: 'dist',
platform: 'node',
minify: true,
bundle: false,
target: 'node12'
})
fs.mv('dist/sass.default.dart.js', 'src/index.js')
fs.rm('./package', true)
fs.rm(`./${PKG_NAME}.tgz`)
})()