UNPKG

@almaclaine/npm-scripts

Version:
51 lines (44 loc) 1.64 kB
import { spawn } from 'child_process'; import {existsSync} from 'fs'; import {join} from 'path'; const {env: {PWD}} = process; if (!existsSync('package.json')) { console.log('No package.json file in root directory.'); process.exit(1); } const execer = (command, args) => () => { const child = spawn(command, args); child.stdout.on('data', (data) => { console.log(`${data}`.trim()); }); child.stderr.on('data', (data) => { console.log(`${data}`.trim()); }); child.on('error', ({ message }) => { console.log(message.trim()); }); return child; } export const clean = execer('npx', ['rimraf', `${join(PWD, 'dist')}`]); export const compile = execer('tsc', ['--outDir', `${join(PWD, 'dist')}`, '--project', `${join(PWD, 'tsconfig.build.json')}`]); export const test = execer('npx', ['jest', '-u', `${PWD}`]); export const rollup = execer('rollup', ['-c', `${join(PWD, 'rollup.config.js')}`]); export const testUpdate = execer('npx', ['jest', PWD]); export const lint = execer('eslint', ['--fix', PWD]); export const start = execer('npx', ['ts-node', 'exec.ts']); export const blox = execer('npx', ['gitblox']); export const viteDev = execer('vite'); export const viteBuild = execer('vite', ['build']); export const vitePreview = execer('vite', ['preview']); export const build = () => { lint().on('close', () => { test().on('close', () => { clean().on('close', () => { compile().on('close', () => { rollup(); }); }); }); }); }; export const prepublish = () => build();