-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional shorter syntax #4
Comments
@timfish nice idea :) In the meanwhile (while it gets implemented) I suggest you to use something like this const run = (...commands) => {
return {
run: async(exec) => {
await exec(...commands);
}
};
}
module.exports = {
commands: {
clean: run('del-cli ./dist/**', 'another command'),
build: run('tsc --pretty')
}
}; Do you think it is better to use a built-in 'run' approach or an array approach? |
Great, one of the plus points of it being pure JavaScript! One downside is that command names are limited to valid JavaScript. Automatic camel to kebab conversion Wildcard commands in parallel would be great too |
For kebab, you can just do `{"build-ts": exec => …}`, no?
…On Tue, Jul 25, 2017, 4:14 PM Tim Fish ***@***.***> wrote:
Great, one of the plus points of it being pure JavaScript!
One downside is that command names are limited to valid JavaScript.
Automatic camel to kebab conversion buildTs -> build-ts would help.
Wildcard commands in parallel would be great too @build-*
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#4 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AADWlv9X0XchlQf74CVSlmGbTaEXVgP0ks5sRfgygaJpZM4OhIQl>
.
|
I did try that but it errors.
and then: > makfy --list
using command file 'makfyfile.js'...
[ERROR] commands - 0: instance additionalProperty "build-ts" exists in instance when not allowed |
so basically you want buildTs to be also invokable by using build-ts? or alternatively I could remove the restriction for commands to be valid JS identifiers |
As for wildcommands in parallel/series you can try (note - untested) const expandCommands = (commands, startsWithName) => {
return Object.keys(commands).filter(v => v.startsWith(startsWithName)).map(v => `@${v}`);
}
module.exports = {
commands: {
clean: {
run: async (exec, args, utils) => {
const allCommands = utils.makfyContext.commands; // or module.exports.commands
// in series
await exec(...expandCommands(allCommands, 'clean:');
// in parallel
await exec([ ...expandCommands(allCommands, 'clean:') ]);
}
}
}
}; alternative implementation that would work with run: const expandCommands = (startsWithName) => {
return Object.keys(module.exports.commands).filter(v => v.startsWith(startsWithName)).map(v => `@${v}`);
}
module.exports = {
commands: {
clean: run(...expandCommands('clean:')), // parallel: run([ ...expandCommands('clean:') ]),
}
}; |
@xaviergonz Looks good, I'll give it a try! Currently in my npm scripts I have Underscores could work equally well here to denote the hierarchy and are valid js so no camel/kebab/etc case conversion would actually be unnecessary. |
I just released v1.2.0:
Now you can freely use build:ts, build-ts or whatever as your command names :) |
Also I just updated the snipped above to show how it would work with the "run" function |
Thanks! Just realised for wildcard searching I have to be careful not to call the current function and create a huge recursive crash! |
either that or change the filter to filter(v => v !== startsWithName && v.startsWith(startsWithName)) :) |
new in 1.4.0 Short syntaxIf your command doesn't need any arguments or any description then you can use the js const { run } = require('makfy');
...
clean: run(
// running sequentially
"rimraf ./dist-a",
"rimraf ./dist-b",
// and these run after the other ones too, but in parallel!
["rimraf ./dist-c", "rimraf ./dist-d"]
) ts import { run } from 'makfy';
...
// note how command() is not needed when using run
clean: run(
// running sequentially
"rimraf ./dist-a",
"rimraf ./dist-b",
// and these run after the other ones too, but in parallel!
["rimraf ./dist-c", "rimraf ./dist-d"]
) |
not closing this since I still have to add the "*" commands in parallel and sequential |
makfy is just what I've been looking for! There are a couple of things its missing to make it perfect for me but I'm happy to contribute.
Many of my commands are simple one-liners with not much else. The rest simply call other commands in series and parallel. This makes the full syntax quite verbose in places.
Could users optionally just set the command to array of commands which get passed straight to
await exec(...)
? It appears this would still work even with stacked series/parallel arrays or commands.becomes:
The text was updated successfully, but these errors were encountered: