cm-utilities
v9.0.0
Published
Internal utilities for CM projects created with npm
Maintainers
Readme
CM Utilities
Internal utilities for CM projects created with npm. The package supports both ESM and CommonJS consumers from the same npm package.
You can check the npm page.
| Package |
|------------------------------------------------------------------------------------------------------------|
| |
Installation
npm install --save-dev cm-utilities
Usage
Import the functions you need from ESM modules:
import {end, readBranch, readCommit, readVersion} from 'cm-utilities';
Or require the same package from CommonJS modules:
const {end, readBranch, readCommit, readVersion} = require('cm-utilities');
Then, use them in your different scripts according to the needs of your project.
Publishing
Build and validate the package, then publish the single dual-module artifact from dist/package:
npm run build
npm run test
npm publish dist/packageFunctions
These are the different functions that you can use from this library:
| Method | Description |
|-----------------------|---------------------------------------------------------------------------------------------------------------------|
| bytesToHuman | Allows bytes to be displayed in a human readable form |
| calculateNextVersion | Allows you to calculate the next semantic version |
| calculateSHA1 | Allows you to calculate the SHA-1 value of a file |
| copyFiles | Allows you to copy the contents of one directory to another (creating the destination if needed) |
| createDirectory | Creates a directory if it does not exist |
| deleteDirectory | Deletes a directory if it exists |
| end | Allows you to calculate the time spent receiving the start |
| generatePwaAssets | Allows you to generate assets for a progressive web application |
| generateRandomText | Allows you to generate a random text string with a specified number of characters |
| generateTimestamp | Allows you to generate a timestamp from the current date |
| generateVersionCode | It allows you to generate the version code (consecutive integer) for an Android application |
| generateVersionName | Allows you to generate the version name (version text) for an Android application |
| isoToUnixTime | Allows you to convert a date in ISO format to unix time |
| joinUnix | Allows you to convert the folder separator according to the operating system |
| localHour | Allows you to get the local time in [hh:mm:ss.sss] format if you are not in a Cloudflare Pages or Vercel pipeline |
| log | Allows printing in console |
| logm | Allows printing in console a message prefixed with a module name, separated by an arrow (=>) |
| npmInstall | Installs the dependencies of a Node.js project running npm install (or npm ci) in the given directory |
| parseUnixPath | Allows you to convert path separators to Unix format |
| printFilesize | Prints the size of a file in a human readable form |
| printJSON | Formats a JSON text string in a more readable way |
| printJSONObject | Formats a JSON object in a more readable way |
| readAppChanges | Allows you to read the application changes from the environment variables that correspond to each language |
| readBranch | Allows you to read the current branch in which this method is being executed |
| readCommit | Allows you to read the SHA1 of the current commit in which this method is being executed |
| readVersion | Allows reading the VERSION file in the root of the project |
| readVersionWithSuffix | Allows you to read the VERSION file in the root of the project by adding the suffix according to the current branch |
| sendPOST | Allows you to make a POST type HTTP request |
| sendRelease | Allows you to register a new release in CM Admin |
| unixTime | Allows you to obtain the current unix time |
| validateDirectory | Allows you to validate if a directory exists and is readable |
| validateFile | Allows you to validate if a file exists and is readable |
| writeVersion | Allows writing to the VERSION file in the root of the project |
Release history and changelog
See the Releases page for a list of all releases, including changes.
Help / Support
If you run into any issues, please email me at [email protected], or you can use the contact form in my page.
For bug reports, please open an issue on GitHub.
Contributing
- Fork it.
- Create your feature branch (
git checkout -b my-new-feature). - Commit your changes (
git commit -am 'Added some feature'). - Push to the branch (
git push origin my-new-feature). - Create a new pull request to develop branch.
