ts-cleanup
A tool for cleaning up files built by typeScript
Last updated 5 months ago by erayhanoglu .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ts-cleanup 
SYNC missed versions from official npm registry.

ts-cleanup

NPM Version NPM Downloads Build Status Test Coverage DevDependencies

A helper script that can be used to cleanup previously transpiled typescript files. When typescript is setup to transpile files from a source to distribution folder, it won't automatically remove distribution files when their source file is deleted. ts-cleanup can take care of this task for you, both in single time build mode, or in watch mode.

Installation

$ npm install ts-cleanup --save

How to use it

Usage: ts-cleanup options

A tool for cleaning up files built by typeScript

Options:
  -s, --src <srcDir>    sets the source folder with ts files (required if -d not defined)
  -d, --dist <distDir>  sets the distribution folder with js files  (required if -s not defined)
  -v, --verbose         whether to show messages for files being deleted (disabled by default)
  -w, --watch           whether to watch for files being deleted (disabled by default)
  -a, --all             whether to remove all .js files
  -rd, --remove-dirs    whether to remove empty directories (default: true)
  -V, --version         output the current version
  -h, --help            output usage information
ts-cleanup -s src -d dist -v -rd

Node usage

ts-cleanup also provides two simple functions for usage from within a node script:

Basic usage

cleanup(src: string, dist: string, options?: ICleanSrcOptions);

  • src: the source folder with ts files (required if -d not defined)
  • dist: the distribution folder with js files (required if -s not defined)
  • options
    • root?: string: root directory
    • exclude?: string | string[]: pattern to exclude file matching
    • removeEmptyDirs?: boolean: whether to remove empty directories
    • verbose?: boolean: whether to show messages for files being deleted
const {cleanup} = require("ts-cleanup");

cleanup('./src', "./dis", {
  root: __dirname, // default process.cwd()
  removeAllJsFiles: true, // default false
  removeEmptyDirs: true, // default false
  verbose: true // default false
});
const {watch} = require("ts-cleanup");

watch('./src', "./dis", {
  root: __dirname, // default process.cwd()
  verbose: true // default false
});

watch(src: string, dist: string, options?: IWatchOptions);

  • src: the source folder with ts files (required if -d not defined)
  • dist: the distribution folder with js files (required if -s not defined)
  • options
    • root?: string: root directory
    • verbose?: boolean: whether to show messages for files being deleted

Advances usage

cleanSrc()

Cleans previously transpiled typescript files in a source directory.

cleanSrc(options?: ICleanSrcOptions, callback?: (filename: string) => boolean);

  • options
    • root?: string: root directory
    • exclude?: string | string[]: pattern to exclude file matching
    • removeAllJsFiles?: boolean: whether to remove all .js
    • removeEmptyDirs?: boolean: whether to remove empty directories
    • verbose?: boolean: whether to show messages for files being deleted
  • callback: executes this callback for each file, and removes only files wich callback returns true.
const {cleanSrc} = require("ts-cleanup");

cleanSrc({
  root: __dirname, // default process.cwd()
  removeAllJsFiles: true, // default false
  removeEmptyDirs: true, // default false
  verbose: true // default false
},  (f)=> f.includes('.spec.ts'));

cleanMatch()

Cleans any files that matches glob pattern.

cleanMatch(pattern: string | string[], options?: ICleanSrcOptions, callback?: (filename: string) => boolean);

  • pattern: Glob pattern to match files
  • options
    • root?: string: root directory
    • exclude?: string | string[]: pattern to exclude file matching
    • removeEmptyDirs?: boolean: whether to remove empty directories
    • verbose?: boolean: whether to show messages for files being deleted
  • callback: executes this callback for each file, and removes only files wich callback returns true.
const {cleanMatch} = require("ts-cleanup");

cleanMatch('src/**/*.spec.{js,js.map,d.ts}', {
  root: __dirname, // default process.cwd()
  removeEmptyDirs: true, // default false
  verbose: true // default false
},  (f)=> !f.includes('.dont-remove'));

Node Compatibility

  • node >= 8.0;

License

MIT

Current Tags

  • 0.2.1                                ...           latest (5 months ago)

13 Versions

  • 0.2.1                                ...           5 months ago
  • 0.2.0                                ...           5 months ago
  • 0.1.8                                ...           5 months ago
  • 0.1.7                                ...           5 months ago
  • 0.1.6                                ...           5 months ago
  • 0.1.5                                ...           5 months ago
  • 0.1.4                                ...           5 months ago
  • 0.1.3                                ...           5 months ago
  • 0.1.2                                ...           5 months ago
  • 0.1.1                                ...           5 months ago
  • 0.1.0                                ...           5 months ago
  • 0.0.2                                ...           5 months ago
  • 0.0.1                                ...           5 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (12)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |