Git Product home page Git Product logo

gulp-monkeyscript's Introduction

Install

$ npm install gulp-monkeyscript --save-dev

See DEVELOPMENT.md for details on customizing gulp-monkeyscript.

Usage

Either use package.json directly or use separate monkeyscript.json.

If you use monkeyscript.json you can and add the following line in it to get Intellisense working:

"$schema": "./node_modules/gulp-monkeyscript/schema.json",

Add the key-value pairs to your needs. See Showcase for an example.

Simple gulp file

gulpfile.js:

var ms = require('gulp-monkeyscript');
var msProject = ms.createProject("monkeyscript.json");

//...
gulp.src("src/**/*.js")
	.pipe(concat("script.user.js"))
    .pipe(msProject())
	.pipe(gulp.dest("dist/"));

Note! You should use createFullProject if you want to create both meta.js and user.js.

Also note that createProject returns a function with pre-complied properties.

Gulp file with meta.js (updates)

You only need the meta file for updates of your user script. This will make things easier for your users. So most of the time you should generate both the main script (user.js) and the meta-data file (meta.js).

An example gulp:

var ms = require('gulp-monkeyscript');
var msProject = ms.createFullProject("package.json");

//...

	// user.js
	gulp.src("src/**/*.js")
		.pipe(concat("script.user.js"))
		.pipe(msProject.main()) // add monkeyscript header
		.pipe(gulp.dest("dist/"));
	;

	// meta.js
	var stream = source("script.meta.js");
	stream.end('');
	stream
		.pipe(msProject.meta()) // add monkeyscript header
		.pipe(gulp.dest("dist/"));
	;

Note! You can find a full glupfile example in the example/ folder.

Also note that this just create an empty stream: var stream = source("script.meta.js");stream.end('');. This was tested with "vinyl-source-stream": "2.0.0",.

Showcase

This monkeyscript.json:

{
    "$schema": "./node_modules/gulp-monkeyscript/schema.json",
    "name": "My Awesome Userscript!",
    "version": "1.0.0",
    "author": "Tom",
    "description": "This userscript adds new functionality!",
    "match": [
        "http://www.website.com/page1/",
        "http://www.website-alter.com/*"
    ],
    "runAt": "document-start",
    "useStrict": true
}

Becomes:

// ==UserScript==
// @name        My Awesome Userscript!
// @version     1.0.0
// @author      Tom
// @description This userscript adds new functionality!
// @match       http://www.website.com/page1/
// @match       http://www.website-alter.com/*
// @run-at      document-start
// ==/UserScript==
'use strict';

<other source>

Where <other source> is whatever things you contacted or built with gulp.

Using package.json

Basic package.json can be generate with a standard Node command:

npm init

By using package.json you will not have to repeat author, name, version and description twice.

You will just add user-script specific information in a separate property called "monkeyscript".

So a minimum package.json would be created by adding some match array for user-script meta like so:

{
    "author": "Tom",
    "name": "My Awesome Userscript!",
    "version": "1.0.0",
    "description": "This userscript adds new functionality!",
	"monkeyscript": {
	    "meta": {
		    "match": [
		        "http://www.expample.com/page1/*"
		    ]
		}
	}
}

gulpfile.js:

const ms = require('gulp-monkeyscript');
const msProject = ms.createProject("package.json");

gulp.src("src/**/*.js")				// get all js from `src` folder 
	.pipe(concat("script.user.js"))	// concat js to a single file
    .pipe(msProject())				// append Grease/Tampermonkey header to that file
	.pipe(gulp.dest("dist/"));		// put the file in `dist` folder

Dependencies

License

MIT © 2017-2020 Tom O'Neill, Maciej Nux Jaros

gulp-monkeyscript's People

Contributors

eccenux avatar tomoneill avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.