@player1os/javascript-support v1.3.14
Javascript Support
A set of common utilities and scripts to be used in the development of projects written in Javascript.
Assets
This project provides the following development assets:
Eslint configuration
.eslintrc.json - a common linter configuration file for eslint.
Output formatting
lib/common/format.js - a module that exports functions for outputting standardized messages:
success(taskName: string)- notifies of the success of a task with the given name.failure(taskName: string)- notifies of the failure of a task with the given name.notify(taskName: string, message: string)- outputs a custom message for the a task with the given name.
Async spawn child process
lib/common/spawn_child_process.js - a promise wrapper of the standard Node.js library for spawning a process.
The implementation is designed similarly to childProcess.spawnSync in that it does not allow any interaction with the spawned process until it has exited. The difference is that since this is an asynchronous implementation, the process does not block.
The implementation forces the process to be spawned in a separate shell (which is slower, but simplifies cross-platform usage).
The module exports functions, with the following identical parameters:
taskName: string- the name of the task that triggered the function, this is only used if the process fails and result verification is not suppressed.command: string- the command to be executed.processArguments: string[]- the arguments for the command to be executed.isResultVerificationSuppressed: boolean?- an optional flag that determines whether the result of the command is to be validated internally. If set tofalse, the functions check whether the spawned process returned with a non-zero status code. If the validation fails, an error is outputted and the current process is halted with a non-zero status code. The default value of this parameter isfalse.
The functions both return an object containing the status code and kill signal as well as any buffered stdout or stderr streams.
The exported functions differ as follows:
inherited()- the spawned process's IO streams are forwarded to the current process.piped()- the spawned process's IO streams are buffered and transformed toutf-8strings, contained in the return object.
The following is a usage example of the piped variant:
const { spawnChildProcess } = require('@player1os/javascript-support')
;async () => {
const result = await spawnChildProcess.piped('SCRIPT', 'echo', ['"Hello World!"'])
console.log(result.stdout) // outputs: Hello World!
}()Preversion task script
lib/task/preversion.js - a script that is executed before the project's version is to be updated:
Ensures the newest version of the master branch is checked out, by running:
git checkout master git pullEnsures all the dependencies are installed, by running:
npm iExecutes the test script, if it is defined, by running:
npm test
Postversion task script
lib/task/postversion.js - a script that is executed after the project's version has been updated:
Pushes any new commits and tags to the
originremote repository, by running:git push git push --tagsDetermines whether the current project is an npm package, by checking the contents of the
.npmignoreandpackage-jsonfiles.If the current project is an npm package it is published to npm, by running:
npm publishAlternatively, if the project is publicly accessible and is being published for the first time, by running:
npm publish --access=publicIf the current project isn't an npm package but a
publishscript is defined in thepackage.jsonfile, then this script is executed, by running:``` npm run publish ```
Update base create task script
lib/task/update_base/create.js - a script that creates a rebased tree of the git repository of a project derived from a template project, when the template is modified:
We assume all tags are located on the path between the
masterbranch and the repository's root. Thus we'll need to reapply these tags to newly created commits, after the rebase is finished. For each tag, store a mapping from the tag's commit message to the tag's name.Fetch the
baseremote repository's branches, by running:git fetch baseMake sure we're in the project's
masterbranch, by running:git checkout masterRebase the project's
masterbranch to thebaseremote repository'smasterbranch, by running:git rebase base/masterThe rebase may require some manual intervention. In this case the script will spawn a new nested shell instance. We are instructed to close this instance once the rebase is complete.
For each commit on the path from the newly rebased
mastercommit to the repository's root, we check if its message can be found in the mapping previously stored at the first step. If a match is found, the tag is moved to the new commit, by running:git tag -af TAG_NAME NEW_COMMIT_HASHEnsures any new dependencies are installed, by running:
npm iExecute garbage collection upon the repository, by running:
git gcPropagate the changes to the
originremote repository, by running:git push -f git push --tags -f
Update base load task script
lib/task/update_base/load.js - a script that loads the rebased tree of the git repository from the origin remote repository:
Fetch the
originremote repository's branches, by running:git fetchFetch the
baseremote repository's branches, by running:git fetch baseMake sure we are in the project's
masterbranch, by running:git checkout masterMake a hard reset of the
masterbranch to where theoriginremote repository'smasterbranch is located, by running:git reset --hard origin/masterOverwrite the local repository's tags with those found in the
originremote repository, by running:git fetch --tags -pEnsures any new dependencies are installed, by running:
npm iExecute garbage collection upon the repository, by running:
git gc
Tests
This project contains an npm test script that is triggered in the aforementioned. The script itself does the following:
Execute the eslint linter, by running:
eslint .If the current project is found to contain tests, execute the jest test runner, by running:
jest
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago