diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..8dfe563 --- /dev/null +++ b/Readme.md @@ -0,0 +1,85 @@ +This package provides tasks to work with npm. + +# Example + +a very simple example looks like this + +```js +require('gulp-tasks-npm')(); + +``` + +a more complex example may look like this + +```js + +require('gulp-tasks-npm'({ + + user: "username", + password: "password", + buildVersion: "1.0.0", + strictSsl: false, + registery: "http://myprivateregistry" +}); + +``` + + +# Api + +## gulp-helper-npm(config) + +#### config + +#### config.user (optional) + +Type: `string` +Default: undefined + +The user to use. This could also come from other npm sources like .npmrc + +#### config.password (optional) + +Type: `string` +Default: undefined + +The user to use. This could also come from other npm sources like .npmrc + + +#### config.buildVersion (optional) + +Type: `string` +Default: undefined + +a semvar version in a string if provided a task named `packageJson-mutateVersion` is added that will mutate your package.json file to add that version + + +#### config.email (optional) + +Type: `string` +Default: undefined + +the email to use with npm tasks + + +#### config.strictSsl (optional) + +Type: `bool` +Default: true + +use strict ssl or not + +#### config.registry (optional) + +Type: `string` +Default: `https://registry.npmjs.org/` + +the npm registery to use + +#### config.npmObj (optional) + +Type: `object` +Default: Calculated based on user input + +Defines the npm configuration object we use to do npm operations. If undefined one is built from your previous inputs, which is the prefered method to interact with. + diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..764fde7 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,2 @@ +var gulp = require('gulp'); +require('./index.js')(); \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..5feb3a0 --- /dev/null +++ b/index.js @@ -0,0 +1,67 @@ +var npmWrapper = require("grunt-npm-helper/lib/npm-wrapper"); +var jsonTransform = require('gulp-json-transform'); +var gutil = require('gulp-util'); +var gulp = require('gulp'); +var publishDeps = []; +module.exports = function(config){ + config = config || {}; + config.user = config.user || undefined; + config.password = config.password || undefined; + config.buildVersion = config.buildVersion || undefined; + config.email = config.email || undefined; + config.strictSsl = config.strictSsl || true; + config.registry = config.registry || "https://registry.npmjs.org/"; + config.npmObj = config.npmObj || { + registry: config.registry , + "strict-ssl": config.strictSsl, + username: config.user, + "_password": config.password, + loglevel: "http", + email: config.email + }; + +if(config.buildVersion){ + gulp.task('packageJson-mutateVersion', function() { + gulp.src("./package.json") + .pipe(jsonTransform((data)=> { + data.version = config.buildVersion; + return data; + })) + .pipe(gulp.dest('.')); +}); +publishDeps.push('packageJson-mutateVersion'); +} +else{ + gutil.log('No build version passed, packageJson-mutateVersion task omitted') +} + + +gulp.task('npm-install', function(cb){ + + npmWrapper( + ["install"], + config.npmObj, + cb); + + +}); + +gulp.task('npm-publish', publishDeps, (callback)=>{ + if(config.user && !config.password){ + gutil.log('username specified but no password specified'); + process.exit(1); + } + if(!config.password && config.user){ + gutil.log('password specified but no password specified'); + process.exit(1); + } + + npmWrapper( + ["publish"], + config.npmObj, + callback + ); +}); + + +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..c20abb2 --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "gulp-tasks-npm", + "version": "0.1.0", + "description": "adds npm install and publish tasks to gulp", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/tparnell8/gulp-tasks-npm.git" + }, + "keywords": [ + "gulp", + "npm" + ], + "author": "Tommy Parnell", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/tparnell8/gulp-tasks-npm/issues" + }, + "homepage": "https://github.com/tparnell8/gulp-tasks-npm#readme", + "dependencies": { + "grunt-npm-helper": "0.0.2", + "gulp": "^3.9.1", + "gulp-json-transform": "^0.3.2", + "gulp-util": "^3.0.7" + } +}