1.1.8 • Published 9 years ago

tentacle-js v1.1.8

Weekly downloads
13
License
MIT
Repository
github
Last release
9 years ago

npm version Dependencies

Installation

You can download the tentacle via NPM or clone the latest release via GitHub.

npm install --save -g tentacle-js

CLI

A command line interface (CLI) is provided by default as you install tentacle. It enables you to run the tentacle scripts from your terminal, dos console or bash. The tentacle binary will look for a file called 'tentacle.js' in your directory where you're executing the tentacle command, so you have to name your file tentacle.js. Using the CLI then is pretty simple and explained with an example below.

Example

# displays version x.x.x (alternate '-V')
tentacle -version

# sets the loglevel to errors only (alternate '-L')
tentacle -loglevel 0

# run in silent mode (alternate '-S')
tentacle -silent

# run a specific task in silent mode
tentacle -tasks default -S

API

Basically you can create several task to execute with different pipes. The only thing you need is an input (files) and eventually an output (folder or file). All functions for this basic process are provided by Tentacle. A guide for the API is avaible below. If something's missing, please open an issue - thanks!

setLogLevel

LevelDescription
-1Equivalent to the .silent() method
0Display only errors
1Display errors and warnings
2Display errors, warnings and infos
3Default - Display errors, warnings, infos and logs (everything)
Example
var tentacle = require('tentacle-js');
tentacle.setLogLevel(0); // Only errors

task

Creates a task which can be executed by tentacle via CLI or in the default task of your tentaclefile. A task doesn't have to return a stream but if you do any IO activity within your task, it's recommended to use the return statement.

Example
var tentacle = require('tentacle-js');
tentacle.task('example:task', function() {
    console.log('I\'m a task');
});

read

Reads one or multiple files by a global pattern. It can be a regex or a path, no matter what. All files affected by this global path will be passed into the stream of the task and will be modified by your code inside. Use tentacle.write() to set the destination of the files.

Example
var tentacle = require('tentacle-js');
tentacle.task('example:task', function() {
    // Reads all js files form this directory
    return tentacle.read('*.js');
});

write

Writes one or multiple files back to the filesystem. The destination must be a path, otherwise it will create a folder named like your output destination.

Example
var tentacle = require('tentacle-js');
tentacle.task('example:task', function() {
    // Copy all js files form this directory to /copy
    return tentacle.read('*.js')
        .pipe(tentacle.write('/copy'));
});

remote

You can run tentacle scripts on a remote with the embedded method. It uses an SSH2 connection to your server, requiring the host and credentials. Tentacle must be installed on the server before running a script.

Example
var tentacle = require('tentacle-js');
tentacle.remote('/path/to/tentacle.js', {
    user: 'root',
    password: '',
    host: '192.17.210.3'
});

watch

Files can be watched with a global pattern and execute other tasks simultaneously as one of the matching files changes. It is useful for local development and demonstration purposes.

Example
var tentacle = require('tentacle-js');
tentacle.watch('/files/to/watch/**/*.less', function() {
    // Auto-compile less on change of a less file
    tentacle.start('compile:less');
});

run

Basically runs a task defined in tentacle.

Example
var tentacle = require('tentacle-js');
tentacle.run('my-task-name');

silent

Is equivalent to .setLogLevel(-1) and prevents tentacle from logging anything into the console, doesn't matter if it's an error or something else which would be fatal.

Example
var tentacle = require('tentacle-js');
tentacle.silent();

tentacle.task('will-fail', function() {
    throw new Error('Testing silent mode ...');
});

tentacle.task('default', ['will-fail']);
// Console will stay empty

Example Tentacle

This tentacle script will strip all one-line comments out of all JavaScript files located anywhere under the current directory.

'use strict';

var through = require('through2');
var tentacle = require('tentacle-js');
var stripComments = require('strip-comments');

tentacle.task('stripcomments:line', function() {
    return tentacle.read('./**/*.js')
        .pipe(through.obj(function(file, enc, handle) {
            file.contents = new Buffer(
                stripComments.line(file.contents.toString(), {
                    safety: true
                })
            );
            this.push(file);
            return handle();
        }));
});

tentacle.task('default', ['stripcomments:line'])