npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mimamuh/gulp-tasks

v2.1.0

Published

Some gulp task factories to help with working with frontend and craft backends.

Downloads

12

Readme

gulp-tasks

A small collectionn of factories to create gulp task with different purposes.

There are tasks to:

  • Copy files from one project to another with copyFilesFactory
  • Create a assets.json file with createAssetsJsonFactory
  • More to come ...

How to install it?

You can install this task with npm:

npm install --save-dev @mimamuh/gulp-tasks

Or with yarn:

yarn add --dev @mimamuh/gulp-tasks

Requirements

  • Node.js >= 8.x
  • Gulp >= 4.x

Tasks

copyFilesFactory(gulp, taskName, config)

Copies files from one project to another one.

Params:

  • gulp - gulp instance
  • taskName - unique name of the task
  • config - configuration object

Example usage:

// gulpfile.js
const gulp = require('gulp');
const { copyFilesFactory } = require('@mimamuh/gulp-tasks');

// Permission settings for specific tasks.
// They may not apply to all tasks!!!
const permissionsConfig = {
	// Use "allowForceRemove" to spedify that your gulp tasks
	// are allowed to run outsite of the root folder gulp is
	// executed in. Needed if you want to execute tasks outside
	// of your project root folder. Be aware that it could ruin
	// your computer if you are careless.
	allowForceRemove: true,
	// Use "dryRun" to spedify if you want to run the gulp tasks
	// without any transformative operations. Only the tasks of
	// "gulp-tasks" may support this feature. On a dry run the
	// tasks will log their output to your terminal
	dryRun: false,
};

// Config to copy asset from one project to another
const copyConfig = {
	permissions: permissionsConfig,
	// Array with copy commands ...
	// @from: Use "from" to specify from which folder you want to copy files.
	// @to: Use "to" to specify to which folder you want to copy the files.
	// @extensions: Use "extensions" to specify which files should be copied based on their extension.
	// @includeSubDirs: Use "includeSubDirs" when you also want to copy files from subdirectories. Defaults to "false". Files copied from subdirectories keep their folder structure.
	// @removeSrcFiles: Use "removeSrcFiles" when source files should be deleted after they have been copied to their destination. Defaults to "false".
	// @removeDistFiles: Use "removeDistFiles" when files in the destination directory should be removed before new files will be copied there. It only removes files which match the same extension patterns like the source files. Defaults to "false".
	copy: [
		{
			from: './dist/',
			to: './../backend/web',
			extensions: ['css', 'css.map'],
			includeSubDirs: false,
			removeSrcFiles: false,
			removeDistFiles: true,
		},
		{
			from: './dist/critical',
			to: './../backend/templates/critical',
			extensions: ['css'],
			includeSubDirs: false,
			removeSrcFiles: false,
			removeDistFiles: false,
		},
		{
			from: './dist/assets/js/',
			to: './../backend/web/assets/js/',
			extensions: ['js', 'js.map'],
			includeSubDirs: false,
			removeSrcFiles: false,
			removeDistFiles: true,
		},
	],
};

// Create the copy task
copyFilesFactory(gulp, 'copy-bundles', copyConfig);

createAssetsJsonFactory(gulp, taskName, config)

Create a assets.json file to be used with CraftCMS 3 Rev plugin or similar. It parses folders for files with a specific extension and includes them in the assets.json file. It expects that the asset files follow a naming convention of: [name]-[hash].[extension]. It also works with underscore _ or dot . as a seperator like: [name]_[hash].[extension]

The outputted asset.json file will have a structure of:

{
	"css/main": "/main-23ds3nsx45.css",
	"js/home": "/assets/js/home-23ds3nsx45.js",
	"js/contact": "/assets/js/contact-23ds3nsx45.js"
}

Params:

  • gulp - gulp instance
  • taskName - unique name of the task
  • config - configuration object

Example usage:

// gulpfile.js
const gulp = require('gulp');
const { createAssetsJsonFactory } = require('@mimamuh/gulp-tasks');

// Permission settings for specific tasks.
// They may not apply to all tasks!!!
const permissionsConfig = {
	// Use "allowForceRemove" to spedify that your gulp tasks
	// are allowed to run outsite of the root folder gulp is
	// executed in. Needed if you want to execute tasks outside
	// of your project root folder. Be aware that it could ruin
	// your computer if you are careless.
	allowForceRemove: true,
	// Use "dryRun" to spedify if you want to run the gulp tasks
	// without any transformative operations. Only the tasks of
	// "gulp-tasks" may support this feature. On a dry run the
	// tasks will log their output to your terminal
	dryRun: false,
};

// Config create a assets.json which could be used with
// the Craft Rev plugin: https://github.com/clubstudioltd/craft-asset-rev
const assetsJsonConfig = {
	// Specify permission options ...
	permissions: permissionsConfig,
	// Use "projectRoot" to specify where your project is
	// located relative to your gulpfile.js
	projectRoot: './../backend/',
	// specify output options ...
	output: {
		// Use "assetsShouldBeRelativeTo" to specify to which folder
		// the assets in your assets.json file should be relative to.
		// "assetsShouldBeRelativeTo" should be relative to "projectRoot".
		assetsShouldBeRelativeTo: './web/',
		// Use "storeAssetsJsonTo" to specify where you want to store
		// your assets.json file relative to "projectRoot".
		storeAssetsJsonTo: './',
	},
	// Array with include commands ...
	// @from: Use "from" to specify from where you want to include assets to your assets.json.
	// @extensions: Use "extensions" to specify which files should be included in your assets.json based on their extension.
	// @includeSubDirs: Use "includeSubDirs" to spedify if files from subdirectories should be included. Defaults to "false".
	include: [
		{
			from: './web',
			extensions: ['css'],
			includeSubDirs: false,
		},
		{
			from: './web/assets/js/',
			extensions: ['js'],
			includeSubDirs: false,
		},
	],
};

// Create the generate assets.json task
createAssetsJsonFactory(gulp, 'create-assets-json', assetsJsonConfig);

injectImportStatementsFactory(gulp, taskName, config)

Inject import statements to a file. It allows to configure, where to look for files, define a template for the import statement and in which file and where it should place the import statements.

Params:

  • gulp - gulp instance
  • taskName - unique name of the task
  • config - configuration object

Example usage:

In this example we look for all scss files within styles folders in our project and inject them as @import '<%= dir %>/<%= name %>'; in our global.scss file.

// gulpfile.js
const gulp = require('gulp');
const { injectImportStatementsFactory } = require('@mimamuh/gulp-tasks');

// Inject scss dependencies to a global.scss file
const injectScssConfig = {
	// Glob string to find files to be
	// injected as import statements to your
	// summary file.
	inject: './src/**/styles/*.scss',
	to: {
		// File in which we inject the found files
		// as a import statement
		file: './src/assets/scss/global.scss',
		// Inject import statements between the following
		// tags. Make sure to have them written in your file!
		between: {
			startTag: '/* inject:imports */',
			endTag: '/* endinject */',
		},
	},
	// Template for the import statement.
	// It uses the lodash template syntax:
	// https://lodash.com/docs/4.17.10#template
	// Possible variables are:
	// <%= path %> 		'/home/user/dir/file.txt'
	// <%= base %> 		'file.txt'
	// <%= ext %> 		'.txt'
	// <%= dir %> 		'/home/user/dir'
	// <%= name %> 		'file'
	// <%= root %> 		'/'
	with: "@import '<%= dir %>/<%= name %>';",
};

injectImportStatementsFactory(gulp, 'inject-scss', injectScssConfig);