Gathering detailed insights and metrics for tinyflow
Gathering detailed insights and metrics for tinyflow
Gathering detailed insights and metrics for tinyflow
Gathering detailed insights and metrics for tinyflow
npm install tinyflow
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
4
1
Tiny module for automating tasks in your workflow
Use npm to install this module on your project:
npm install --save tinyflow
Create a new file and write the tasks that you want to automatize. For example, let's create a file called tasks.js
:
1let flow = require("tinyflow"); 2let fs = require("fs"); 3let path = require("path"); 4let sass = require("node-sass"); 5let mkdirp = require("mkdirp"); 6let uglify = require("uglify-js"); 7 8//Create the dist folder 9flow.task("create-dist", function (done) { 10 mkdirp.sync("./dist"); 11 return done(); 12}); 13 14//Compile SCSS files 15//First we must run the create-dist task 16flow.task("compile-scss", ["create-dist"], function (done) { 17 let content = fs.readFileSync("./scss/style.scss", "utf8"); 18 //Compile the scss files 19 return sass.render({data: content}, function (error, result) { 20 if (error) { 21 return done(error); 22 } 23 //Write the compiled scss file 24 fs.writeFileSync("./dist/style.scss", result.css, "utf8"); 25 return done(); 26 }); 27}); 28 29//Minify JS files 30//First we should run the create-dist task 31flow.task("minify-js", ["create-dist"], function (done) { 32 let content = fs.readFileSync("./js/index.js", "utf8"); 33 let result = uglify.minify(content); 34 if (result.error) { 35 return done(result.error); 36 } 37 fs.writeFileSync("./dist/index.js", result.code, "utf8"); 38 return done(); 39}); 40 41//Default tasks 42flow.defaultTask(["compile-scss", "minify-js"]); 43
You can execute all tasks defined in flow.defaultTask
by running this script with node
:
1$ node ./tasks.js
You can execute a single task (or a subset of tasks) by using the flag --flow-tasks
with the task to execute (or a comma-separated list of tasks):
`
1$ node ./tasks.js --flow-tasks compile-scss
You can use the npm scripts field in package.json
to define these commands:
1{ 2 "scripts": { 3 "compile-scss": "node ./tasks.js --flow-tasks compile-scss", 4 "minify-js": "node ./tasks.js --flow-tasks minify-js", 5 } 6}
Register a new task called name
. This method is an alias of keue.addTask
.
The task dependencies
is a string
or an array
of strings
with the names of the tasks that should be executed before running this task. This argument is optionally.
The task handler
is a function that will execute the task operations. This function will be called with only one argument: a done
function that should be called when the all the task operations are finished.
1flow.task("task0", function (done) { 2 //Do your task operations 3 //. . . 4 5 //When all the operations are finished, call the done function 6 return done(); 7});
If there is an error running the task operations, you can call the done
function with an error object. After that, the error will be automatically printed in console and the flow will be aborted, so no more tasks will be executed.
1flow.task("task-async", function (done) { 2 yourAsyncFunction(arg1, ..., function (error, data) { 3 if (error) { 4 //Something went wrong running 'yourAsyncFunction', print the error and abort the tasks 5 return done(error); 6 } 7 //Continue with your operations. 8 //. . . 9 return done(); 10 }); 11});
Define the default task or tasks that should be runned if the script is called without the --flow-tasks
option. The task
argument can be a string
with the name of the single task to execute, or an array
of strings with the order that the tasks should be executed. Note that this order will change if any task has dependencies, so in this case the dependencies will be executed before.
1//Set a single default task to run 2flow.defaultTask("task0"); 3 4// OR 5 6//Set an array with thasks to be executed in order: 7flow.defaultTask(["task0", "task1", "task2"]);
Use this method to access to any argument passed to the script using a single or a double hyphenated arguments.
1// node script.js --name John 2 3let name = flow.getArgument("name"); 4console.log(name); // John
Print log messages in console.
1flow.log("This is a log message");
Print error messages in console.
1flow.error("Something went wrong...");
You can use the following flags from the command-line to change the default behavior of the tool. Your custom flags can be accessed with flow.getArgument
.
--flow-tasks tasks
Define the tasks that will be executed. It also determines the order where these tasks will be executed. If this option is not used, the module will execute the tasks provided with flow.defaultTask
.
You can execute a single task (and all the dependencies of these task) providing the name of the task to execute:
1$ node ./my-tasks.js --flow-tasks compile-scss
You can also execute multiple tasks providing a list of comma-separated tasks to execute:
1$ node ./my-tasks.js --flow-tasks compile-css,compile-js,minify-css,minify-js
--flow-no-colors
All logs and errors messages will be displayed without colors.
1$ node ./my-tasks.js --flow-no-colors
Under the MIT LICENSE.
No vulnerabilities found.
No security vulnerabilities found.