vroom-tool
Version: 
A robust and quick frontend tooling
66 lines (57 loc) • 1.84 kB
JavaScript
const { readFileSync, writeFileSync, mkdirSync } = require('fs')
const path = require('path')
const esbuild = require('esbuild')
const chalk = require('chalk')
function runVroom(args, argv) {
}
const tools = {
	readFile: (file, encoding) => {
		return readFileSync(file, {encoding: encoding || 'utf-8'})
	},
	writeFile: (file, data, encoding) => {
		return writeFileSync(file, data,{encoding: encoding || 'utf-8'})
	},
	mkdir: (file) => {
		return mkdirSync(file)
	},
	path: (loc) => {
		return path.join(process.cwd() + loc)
	}
}
exports.tools = tools
exports.default = runVroom
exports.bundle = {node: (infile, outfile, opts) => {
	console.log(chalk.blue('> Running build for target: [Node]...'))
	var opts = opts || {}
	outfile = outfile || '/dist/index.js'
		esbuild.build({
			entryPoints: [tools.path(infile)],
			bundle: true,
			minify: opts.minify || false,
			platform: 'node',
			target: [opts.nodeVer || 'node'+process.version.match(/^v(\d+\.\d+)/)[1]],
			outfile: tools.path(outfile)
		}).then(()=>console.log(chalk.green(`> Build complete at '${outfile || './dist/index.js'}'`)))
		
	},
	browser: (infile, outfile, opts) => {
		console.log(chalk.blue('> Running build for target: [Browser: es2020]...'))
		console.log(chalk.yellowBright('> Browser is currently in an experimental state supported at the time.'))
		var opts = opts || {}
		outfile = outfile || '/dist/index.js'
		esbuild.build({
			entryPoints: [tools.path(infile)],
			bundle: true,
			minify: opts.minify || false,
			platform: 'browser',
			target: ['es2020'],
			outfile: tools.path(outfile)
		}).then(()=>console.log(chalk.green(`> Build complete at '${outfile || './dist/index.js'}'`)))
	}
}
exports._ = {
	esbuild,
	chalk
}
if (require.main === module) {
	require('./cli.js')
}