Simple utils working with fs, shelljs and replace.
node 26.13.1or higher in combination withnpm 11.20.0or higher orpnpm 12.21.0or higher, used in this repository
Install pnpm by running:
npm install -g [email protected]# clone project
git clone https://github.com/inpercima/light-js.git
# navigate to project
cd light-js# test
pnpm test# add light-js to your project, mostly in package.json and install with your preferred package manager
"light-js": "inpercima/light-js#1.1.7"
# define a constant in your js file
const lightjs = require('light-js');- error(message)
- info(message)
- success(message)
- warn(message)
- yarnpm(arguments)
- exec(command [, arguments] [, fail])
- readJson(filename)
- replacement(regex, replacement, paths [, silent] [, recursive] [, exclude])
- writeJson(filename, data)
- writeFile(filename, data)
Logs an error message.
messagean error message
lightjs.error('an error message');Logs an info message.
messagean info message
lightjs.info('an info message');Logs a success message.
messagea success message
lightjs.success('a success message');Logs a warn message.
messagea warn message
lightjs.warn('a warn message');Run yarn or npm. It depends on what is installed on your system. Currently default is npm. Is it not installed, yarn will be run. If non of both is installed, an error message appears. This method will pass all arguments to the package manager and do not check if the arguments exists in the specified package manager.
argumentseverything what can run in yarn or npm
lightjs.yarnpm('-v');
lightjs.yarnpm('run build');Run a command with arguments. You can specify if the script should fail if the command does not exist.
commanda command to runargumentseverything what can run in the specify command- optional
failtrue if the scripts should fail otherwise false- optional
- default: true
lightjs.exec('docker', '-v', false);
lightjs.exec('yarn', '-v', false);
lightjs.exec('not-existing-command', 'arguments', false);
lightjs.exec('another-not-existing-command', 'arguments');Reads a json file and parse it as json.
filenamethe filename
lightjs.readJson('path/to/file.json');Replaces a string or a regex in specific files, recursive or not with silent mode if desired.
regexa simple string or regexreplacementstring for replacepathspaths as an array for replacementsilenttrue if no output should be done otherwise false- optional
- default: true
recursivetrue if the replacement should be recursive otherwise false- optional
- default: false
excludecomma separated string of excludes dirs or files- optional
- default: ''
lightjs.replacement('loginForm', `anotherForm`, ['path/to/file']);
lightjs.replacement('loginForm', `anotherForm`, ['path/to/dir'], false);
lightjs.replacement('loginForm', `anotherForm`, ['path/to/dir1', 'path/to/dir2'], false, true);
lightjs.replacement('loginForm', `anotherForm`, ['path/to/dir1', 'path/to/dir2'], false, true, 'node_modules');Writes a json file.
filenamethe filename to savedatathe object as json
lightjs.writeJson('path/to/file.json', { "key": "value" });Writes a simple file.
filenamethe filename to savedatathe data to save
lightjs.writeFile('path/to/file', 'a simple text file');