PackageSmith is a library to help you make tools which can intelligently generate & maintain (or provision, or scaffold) projects quickly and easily.
If you typically create & use "boilerplate" repositories and modify them, or if you have a project where you copy folders/files into new destinations, just so you can re-use the boilerplate code from them; then this tool may be able to help you - rather than making a boilerplate, you can make an intelligent provisioning tool which can generate & maintain a package.
This is a utility library, to use on top of your own tools. To get it working, simply run:
$ npm install --save packagesmith@latest
However, PackageSmith comes with a handy provisioning tool, to provision your own PackageSmith tools! Simply run:
# Locally
$ npm install --save packagesmith@latest
$ ./node_modules/.bin/provision-packagesmith .
# Globally
$ npm install --global packagesmith@latest
$ provision-packagesmith my-new-provisioning-tool
PackageSmith's main export is a function: runProvisionerSet
. This takes an Object - which declares a set of files to create, and instructions on how to create them.
runProvisionerSet
which will take an Object describing a set of provisioner files, and run them. It determines the old contents of the file to give to the provisioner which calculates the new contents, works out a diff - and if there is a difference it will ask the user if they like and want to write the differences.
Here's a slightly more extended sequence of events on how runProvisionerSet works:
- Ensures the given project directory exists
- For every file in the provisioner set:
- Gather the list of questions that need answering before this file can be provisioned
- De-duplicate this list
- Ask all of the gathered questions, formulating an
answers
object. - For every file in the provisioner set:
- Determine if an existing file exists, and read its contents
- Run the file provisioner, determining the new contents of the file.
- Work out a diff between the old and new contents
- If the file has changed, present the diff to the user and ask the user wants to write the file
- If the user says yes: 1. If the file provisioner had a beforeStep, run it 2. If the user wants to write the file, then do so 3. If the file provisioner had an afterStep, run it
- Finish
Here is a simple example demonstrating basic functionality;
import { runProvisionerSet } from 'packagesmith';
runProvisionerSet('/path/to/the/dir/i/want/to/provision', {
'file': {
contents(oldContents) {
return oldContents || 'This is a file!';
}
}
});