CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jake

JavaScript build tool, similar to Make or Rake

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

core-tasks.mddocs/

Core Task System

The core task system provides the foundation for defining and executing build tasks with prerequisites, asynchronous operations, and file dependency checking.

Capabilities

Task Definition

Creates a Jake Task that can have prerequisites and an action to perform.

/**
 * Creates a Jake Task
 * @param {string} name - The name of the Task
 * @param {string[]} [prereqs] - Prerequisites to be run before this task
 * @param {Function} [action] - The action to perform for this task
 * @param {Object} [opts] - Task options
 * @param {boolean} [opts.async=false] - Perform this task asynchronously
 * @param {number} [opts.concurrency=1] - Number of prereqs to run concurrently
 * @returns {Task} The created task instance
 */
function task(name, prereqs, action, opts);

Usage Examples:

// Simple task
desc('This is the default task.');
task('default', function () {
  console.log('This is the default task.');
});

// Task with prerequisites
desc('This task has prerequisites.');
task('hasPrereqs', ['foo', 'bar', 'baz'], function () {
  console.log('Ran some prereqs first.');
});

// Asynchronous task
desc('This is an asynchronous task.');
task('asyncTask', function () {
  setTimeout(complete, 1000);
}, { async: true });

// Task with parameters from command line
task('greet', function (name, greeting) {
  console.log(greeting + ', ' + name + '!');
});
// Usage: jake greet[John,Hello]

File Task Definition

Creates a Jake FileTask that represents a file and can check modification times against prerequisites.

/**
 * Creates a Jake FileTask
 * @param {string} name - The file path this task represents
 * @param {string[]} [prereqs] - Prerequisites to be run before this task
 * @param {Function} [action] - The action to create this file, if it doesn't exist
 * @param {Object} [opts] - Task options
 * @param {boolean} [opts.async=false] - Perform this task asynchronously
 * @returns {FileTask} The created file task instance
 */
function file(name, prereqs, action, opts);

Usage Examples:

// File task that compiles TypeScript
file('dist/app.js', ['src/app.ts'], function () {
  jake.exec(['tsc src/app.ts --outDir dist'], function () {
    complete();
  });
}, { async: true });

// File task with multiple dependencies
file('build/bundle.min.js', ['build/bundle.js'], function () {
  jake.exec(['uglifyjs build/bundle.js -o build/bundle.min.js'], function () {
    complete();
  });
}, { async: true });

// File task that only runs if source is newer
file('docs/api.html', ['src/**/*.js'], function () {
  jake.exec(['jsdoc src -d docs'], function () {
    complete();
  });
}, { async: true });

Directory Task Definition

Creates a Jake DirectoryTask that ensures a directory exists.

/**
 * Creates a Jake DirectoryTask that ensures a directory exists
 * @param {string} name - The directory path to create
 * @returns {DirectoryTask} The created directory task instance
 */
function directory(name);

Usage Examples:

// Create directories for build output
directory('dist');
directory('build/assets');
directory('tmp/cache');

// Use directory as prerequisite
file('dist/app.js', ['dist', 'src/app.js'], function () {
  // dist directory is guaranteed to exist
  jake.cpR('src/app.js', 'dist/app.js');
});

Task Description

Sets a description for the next task that will be created. The description is displayed when running jake -T.

/**
 * Creates a description for a Jake Task
 * @param {string} description - The description for the Task
 */
function desc(description);

Usage Examples:

desc('Compile all TypeScript files');
task('compile', ['clean'], function () {
  jake.exec(['tsc']);
});

desc('Run all tests');
task('test', ['compile'], function () {
  jake.exec(['mocha test/**/*.js']);
});

desc('Clean build directory');
task('clean', function () {
  jake.rmRf('dist');
});

Task Completion

Completes an asynchronous task, allowing Jake's execution to proceed to the next task.

/**
 * Completes an asynchronous task
 * @param {Task} [task] - Specific task to complete (optional)
 * @param {*} [value] - Return value for the task (optional)
 */
function complete(task, value);

Usage Examples:

// Complete the current task
task('asyncTask', function () {
  setTimeout(function () {
    console.log('Async work done');
    complete();
  }, 1000);
}, { async: true });

// Complete with a return value
task('getData', function () {
  fetchData(function (err, data) {
    if (err) {
      fail(err);
    } else {
      complete(null, data);
    }
  });
}, { async: true });

// Complete a specific task (for parallel execution)
task('parallelTask', ['taskA', 'taskB'], function () {
  // Both taskA and taskB run in parallel
  setTimeout(function () {
    complete(this, 'result');
  }.bind(this), 500);
}, { async: true });

Task Failure

Causes Jake execution to abort with an error and optional exit code.

/**
 * Causes Jake execution to abort with an error
 * @param {Error|string} err - The error to throw when aborting execution
 * @param {number} [code] - Optional exit code for the process
 */
function fail(err, code);

Usage Examples:

task('checkEnv', function () {
  if (!process.env.NODE_ENV) {
    fail('NODE_ENV environment variable is required');
  }
});

task('validateConfig', function () {
  try {
    const config = JSON.parse(fs.readFileSync('config.json'));
    if (!config.apiKey) {
      fail('API key is missing from config', 1);
    }
  } catch (e) {
    fail(e, 2);
  }
});

// Fail with multi-line error
task('complexValidation', function () {
  const errors = validateProject();
  if (errors.length > 0) {
    const errorMsg = 'Validation failed:\n' + errors.join('\n');
    fail(errorMsg);
  }
});

Task Execution Patterns

Sequential Execution

Tasks run their prerequisites in order before executing their own action:

task('build', ['clean', 'compile', 'bundle'], function () {
  console.log('Build complete');
});
// Execution order: clean → compile → bundle → build action

Parallel Prerequisites

Use concurrency option to run prerequisites in parallel:

task('test', ['unit-tests', 'integration-tests'], function () {
  console.log('All tests complete');
}, { concurrency: 2 }); // Run both test tasks in parallel

Conditional Execution

File tasks automatically check if they need to run based on modification times:

file('output.txt', ['input1.txt', 'input2.txt'], function () {
  // Only runs if input files are newer than output.txt
  jake.exec(['cat input1.txt input2.txt > output.txt']);
});

Asynchronous Task Patterns

// Using callbacks
task('fetchData', function () {
  https.get('https://api.example.com/data', function (res) {
    // Process response
    complete();
  });
}, { async: true });

// Using promises
task('processFiles', function () {
  processFilesAsync()
    .then(function (result) {
      console.log('Processing complete');
      complete();
    })
    .catch(function (err) {
      fail(err);
    });
}, { async: true });

// Using async/await (Node.js 8+)
task('modernAsync', async function () {
  try {
    const result = await processFilesAsync();
    console.log('Result:', result);
    complete();
  } catch (err) {
    fail(err);
  }
}, { async: true });

Advanced Task Management

Task Series

Creates a sequential execution function from multiple tasks that returns a Promise.

/**
 * Creates a sequential execution function from multiple tasks
 * @param {...Function} tasks - Functions representing tasks to run in series
 * @returns {Function} Function that returns a Promise when called
 */
function series(...tasks);

Usage Examples:

// Define tasks as functions
const cleanTask = function() {
  jake.rmRf('dist');
};

const buildTask = function() {
  jake.exec(['webpack --mode=production'], { printStdout: true });
};

const testTask = function() {
  jake.exec(['npm test'], { printStdout: true });
};

// Create series execution function
const buildPipeline = series(cleanTask, buildTask, testTask);

// Execute the series
task('pipeline', async function() {
  await buildPipeline();
  console.log('Pipeline complete');
});

Task Timeout Configuration

Sets the global timeout for all tasks in milliseconds.

/**
 * Sets the global timeout for all tasks
 * @param {number} timeout - Timeout in milliseconds
 */
function setTaskTimeout(timeout);

Usage Examples:

// Set 5 minute timeout for all tasks
setTaskTimeout(300000);

// Set different timeout for specific environments
if (process.env.NODE_ENV === 'ci') {
  setTaskTimeout(600000); // 10 minutes for CI
} else {
  setTaskTimeout(120000); // 2 minutes for development
}

Series Auto Prefix

Sets an automatic prefix for task names created through the series function.

/**
 * Sets an automatic prefix for series-generated task names
 * @param {string} prefix - Prefix to add to task names
 */
function setSeriesAutoPrefix(prefix);

Usage Examples:

// Set prefix for series tasks
setSeriesAutoPrefix('auto:');

const taskSeries = series(cleanTask, buildTask);
// Generated internal tasks will have names like 'auto:cleanTask', 'auto:buildTask'

docs

build-tasks.md

core-tasks.md

index.md

task-classes.md

task-organization.md

utilities.md

tile.json