Simple Build Kit is a very lightweight build toolkit for Node.js only for copying files.
It has no dependencies to other packages.
All methods are synchronous and file operations use the UTF-8 encoding.
Get it from the npm registry:
npm install --save-dev simple-build-kit
Types of arguments:
folder
- path to a folder, e.g.assets
or~/projects/first
path
- path to a file, e.g../file.js
or/project/lib/file.js
destination
- path to a folder if it ends with/
, and path to file otherwise , e.g../file.js
ordest/
Methods:
Enables or disabled silent mode. By default it's disabled. In silent mode no messages with the progress are printed to the console.
Recursively deletes a folder. There is a check if the folder exists first, so it's safe to call this method always.
First deletes the folder if it exists, then creates the folder.
Reads the file and returns its contents.
Reads all files and returns their content concatented.
Writes the contents to the file. If the destination folder doesn't exists, it will be created.
Creates all missing folders for given path. Examples:
- for
dist/assets/abc
, foldersdist
anddist/assets
will be created - for
dist/assets/abc/
, foldersdist
,dist/assets
anddist/assets/abc
will be created
Copies source file(s) to the destination.
The source
can be:
path/to/file.js
-file.js
will be copied to the destination.path/to/folder/
- all files from thefolder
will be copied to the destination.path/to/file*.png
- all files matching the pattern will be copied to the destination. Possible wildcards:*
and?
. Note: matching subfolders will also be recursively copied.
The destination
can be:
path/to/file.js
- destination file. Only valid for single source file.path/to/folder/
- destination folder. Source file(s) will be copied to the destination folder.
If the destination
folder does not exist, it will be created.
Lists files matching a pattern
The path
can be:
path/to/file.js
- Just thefile.js
will be returned.path/to/folder/
- all files from thefolder
will returned.path/to/file*.png
- all files matching the pattern will be returned. Possible wildcards:*
and?
.
Below is an example build script for a Chrome extension that concatenates files and copies assets:
const build = require('simple-build-kit');
function prepare() {
build.cleanFolder('dist');
build.createFolders('dist/assets');
}
function contentJS() {
const filesLib = [
'lib/firebase-app.js',
'lib/firebase-auth.js',
'lib/firebase-firestore.js'
];
const filesSrc = [
'src/database.js',
'src/ui.js',
'src/config.js',
'src/main.js'
];
let res = build.concat(filesLib);
// fix for https://github.com/firebase/firebase-js-sdk/issues/414
res = res.replace(/\\uffff\/\.test\("[^"]+"/, '\\uffff/.test(""');
res += build.concat(filesSrc);
build.save('dist/content.js', res);
}
function misc() {
build.copy('assets/*.png', 'dist/assets/');
build.copy('background.js', 'dist/');
build.copy('manifest.json', 'dist/');
}
prepare();
contentJS();
misc();