Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clean-scripts

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clean-scripts

A CLI tool to make scripts in package.json clean.

  • 1.5.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-23.08%
Maintainers
1
Weekly downloads
 
Created
Source

Dependency Status devDependency Status Build Status: Linux Build Status: Windows npm version Downloads

clean-scripts

A CLI tool to make scripts in package.json clean.

install

npm i clean-scripts -g

usage

create config file(named clean-scripts.config.js or something else) like:

module.exports = {
    build: "tsc",
    lint: "tslint index.ts"
}

run clean-scripts build, or clean-scripts lint

or clean-scripts build --config clean-scripts.config.js

features
string script
module.exports = {
    build: "tsc"
}
array script
  • executed one by one with order
  • used when later script depends on previous script's success
module.exports = {
    build: [
        "rimraf dist",
        "tsc"
    ]
}
Set or Object script
  • executed collaterally without order
  • used when the scripts are irrelated
  • they are all started at first time, when they are all done, it's a success, otherwise exit current process
module.exports = {
    build: {
        js: `tsc`,
        css: `cleancss -o index.bundle.css index.css`
    }
}
nested script
module.exports = {
    build: [
        "rimraf dist",
        {
            js: `tsc`,
            css: [
                `lessc index.less > index.css`,
                `cleancss -o index.bundle.css index.css`
            ]
        }
    ]
}
custom function script

the type of the function should be (context: { [key: string]: any }, parameters: string[]) => Promise<void>

module.exports = {
    build: () => new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve()
        }, 1000)
    }),
    test: async () => {
        // todo
    }
}

The context can be used to transfer data between different scripts.

module.exports = {
    build: [
        context => {
            context.foo = 'abc'
            return Promise.resolve()
        },
        context => {
            console.log(context.foo) // 'abc'
            return Promise.resolve()
        }
    ]
}

The parameters can be passed from CLI parameters

module.exports = {
    build: (context, parameters) => {
        console.log(parameters) // run `clean-scripts build foo bar`, got `["foo", "bar"]`
        return Promise.resolve()
    }
}
child script
module.exports = {
    build: [
        `rimraf dist/`,
        `tsc -p src/`
    ],
    lint: {
        ts: `tslint "src/**/*.ts"`,
        js: `standard "**/*.config.js"`
    }
}
  • run clean-scripts build[0] to run rimraf dist/
  • run clean-scripts lint.ts to run tslint "src/**/*.ts"
start service
const { Service } = require('clean-scripts')

module.exports = {
  build: [
    new Service('http-server -p 8000'),
    new Service('http-server', 'server2') // the child process can be accessed by `context.server2` later
  ]
}

All services will be killed(send SIGINT actually) after all scripts end, or any script errors.

short-hand methods
const { sleep, readableStreamEnd, execAsync } = require('clean-scripts')

module.exports = {
  build: [
    () => sleep(5000),
    async () => {
        const readable = getReadableStreamSomehow()
        readable.on('data', chunk => {
            console.log(`Received ${chunk.length} bytes of data.`)
        })
        await readableStreamEnd(readable)
    },
    async () => {
        const { stdout } = await execAsync('git status -s')
        if (stdout) {
            console.log(stdout)
            throw new Error(`generated files doesn't match.`)
        }
    }
  ]
}

FAQs

Package last updated on 27 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc