Skip to content

Commit

Permalink
feat: add Promake.make method, make rules run again if necessary when…
Browse files Browse the repository at this point in the history
… called via Node API
  • Loading branch information
jedwards1211 committed Oct 13, 2020
1 parent 98dc738 commit a3211d3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Promise-based JS make clone that can target anything, not just files
+ [`rule(targets, [prerequisites], [recipe], [options])`](#ruletargets-prerequisites-recipe-options)
+ [`hashRule(algorithm, target, prerequisites, [recipe], [options])`](#hashrulealgorithm-target-prerequisites-recipe-options)
+ [`task(name, [prerequisites], [recipe])`](#taskname-prerequisites-recipe)
+ [`make(target)`](#target)
+ [`exec(command, [options])`](#execcommand-options)
+ [`spawn(command, [args], [options])`](#spawncommand-args-options)
+ [`cli(argv = process.argv, [options])`](#cliargv--processargv-options)
Expand Down Expand Up @@ -226,6 +227,17 @@ The created [`Rule`](#class Rule).
Calling `task(name)` without any `prerequisites` or `recipe` looks up and returns the previously created task `Rule` for
`name`, but *it will throw an `Error`* if no such task exists.

### `make(target)`

Makes the given target if necessary.

##### `target`
The name of a task or file, or an object conforming to the `Resource` interface

#### Returns
A `Promise` that will be resolved when the target recipe succeeds (or doesn't need to be rerun) or rejects when the target
recipe fails.

### `exec(command, [options])`

This is a wrapper for [`exec` from `promisify-child-process`](https://github.com/itsjustcon/node-promisify-child-process#exec)
Expand Down
5 changes: 5 additions & 0 deletions src/Promake.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class Promake {
return resource.lastModified()
}

make = async (target: any): Promise<void> => {
if (typeof target === 'string') target = this._normalizeName(target)
await this._make(target)
}

log = (verbosity: VerbosityLevel, ...args: any) => {
if (this.verbosity >= verbosity) console.error(chalk.bold('[promake]'), ...args) // eslint-disable-line no-console
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Rule {
}

make = (): Promise<any> => {
return this.promise = this._make()
return this.promise = this._make().finally(() => this.promise = null)
}

description: (() => ?string) & ((newDescription: string) => Rule) = function (newDescription?: string): any {
Expand Down

0 comments on commit a3211d3

Please sign in to comment.