-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 91fc94a
Showing
11 changed files
with
400 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
/.idea | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"node": true, | ||
"esnext": true, | ||
"bitwise": true, | ||
"camelcase": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"indent": false, | ||
"latedef": false, | ||
"newcap": true, | ||
"noarg": true, | ||
"quotmark": "single", | ||
"regexp": true, | ||
"undef": true, | ||
"unused": true, | ||
"strict": true, | ||
"trailing": true, | ||
"smarttabs": true, | ||
"white": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.* | ||
test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- '0.10' | ||
- '0.11' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2016 Malindu Warapitiya | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# gulp-yarn | ||
Automatically install yarn packages/dependencies. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
'use strict'; | ||
var through2 = require('through2'); | ||
var gutil = require('gulp-util'); | ||
var path = require('path'); | ||
var commandRunner = require('./lib/commandRunner'); | ||
var commandList = { | ||
'package.json': { | ||
cmd: 'yarn', | ||
args: [] | ||
} | ||
}; | ||
|
||
module.exports = function install(opts) { | ||
var toRun = []; | ||
var count = 0; | ||
|
||
return through2({ | ||
objectMode: true | ||
}, | ||
function (file, enc, callback) { | ||
if (!file.path) { | ||
callback(); | ||
} | ||
var cmd = clone(commandList[path.basename(file.path)]); | ||
|
||
if (cmd) { | ||
if (opts && opts.production) { | ||
cmd.args.push('--production'); | ||
} | ||
if (opts && opts.ignoreScripts) { | ||
cmd.args.push('--ignore-scripts'); | ||
} | ||
if (opts && opts.args) { | ||
formatArguments(opts.args).forEach(function (arg) { | ||
cmd.args.push(arg); | ||
}); | ||
} | ||
|
||
cmd.cwd = path.dirname(file.path); | ||
toRun.push(cmd); | ||
} | ||
this.push(file); | ||
callback(); | ||
}, | ||
function (callback) { | ||
if (!toRun.length) { | ||
return callback(); | ||
} | ||
if (skipInstall()) { | ||
log('Skipping install.', 'Run `' + gutil.colors.yellow(formatCommands(toRun)) + '` manually'); | ||
return callback(); | ||
} else { | ||
toRun.forEach(function (command) { | ||
commandRunner.run(command, function (err) { | ||
if (err) { | ||
log(err.message, ', run `' + gutil.colors.yellow(formatCommand(command)) + '` manually'); | ||
return callback(err); | ||
} | ||
done(callback, toRun.length); | ||
}); | ||
}); | ||
} | ||
} | ||
); | ||
|
||
function done(callback, length) { | ||
if (++count === length) { | ||
callback(); | ||
} | ||
} | ||
}; | ||
|
||
function log() { | ||
if (isTest()) { | ||
return; | ||
} | ||
gutil.log.apply(gutil, [].slice.call(arguments)); | ||
} | ||
|
||
function formatCommands(cmds) { | ||
return cmds.map(formatCommand).join(' && '); | ||
} | ||
|
||
function formatCommand(command) { | ||
return command.cmd + ' ' + command.args.join(' '); | ||
} | ||
|
||
function formatArguments(args) { | ||
if (Array.isArray(args)) { | ||
args.forEach(function (arg, index, arr) { | ||
arr[index] = formatArgument(arg); | ||
}); | ||
return args; | ||
} else if (typeof args === 'string' || args instanceof String) { | ||
return [formatArgument(args)]; | ||
} else { | ||
log('Arguments are not passed in a valid format: ' + args); | ||
return []; | ||
} | ||
} | ||
|
||
function formatArgument(arg) { | ||
var result = arg; | ||
while (!result.match(/--.*/)) { | ||
result = '-' + result; | ||
} | ||
return result; | ||
} | ||
|
||
function skipInstall() { | ||
return process.argv.slice(2).indexOf('--skip-install') >= 0; | ||
} | ||
|
||
function isTest() { | ||
return process.env.NODE_ENV === 'test'; | ||
} | ||
|
||
function clone(obj) { | ||
if (Array.isArray(obj)) { | ||
return obj.map(clone); | ||
} else if (typeof obj === 'object') { | ||
var copy = {}; | ||
Object.keys(obj).forEach(function (key) { | ||
copy[key] = clone(obj[key]); | ||
}); | ||
return copy; | ||
} else { | ||
return obj; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var which = require('which'), | ||
childProcess = require('child_process'); | ||
|
||
exports.run = function run(command, cb) { | ||
which(command.cmd, function (err, cmdpath) { | ||
if (err) { | ||
cb(new Error('Can\'t install! `' + command.cmd + '` doesn\'t seem to be installed.')); | ||
return; | ||
} | ||
var cmd = childProcess.spawn(cmdpath, command.args, {stdio: 'inherit', cwd: command.cwd || process.cwd()}); | ||
cmd.on('close', function (code) { | ||
if (code !== 0) { | ||
return cb(new Error(command.cmd + ' exited with non-zero code ' + code)); | ||
} | ||
cb(); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "gulp-yarn", | ||
"version": "0.0.1", | ||
"description": "Automatically install yarn, packages/dependencies if the relative configurations are found in the gulp file stream respectively", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "NODE_ENV=test mocha -R spec" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/warapitiya/gulp-yarn" | ||
}, | ||
"keywords": [ | ||
"gulpplugin", | ||
"yarn", | ||
"install" | ||
], | ||
"author": "Malindu Warapitiya <warapitiya93@gmail.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/warapitiya/gulp-yarn/issues" | ||
}, | ||
"homepage": "https://github.com/warapitiya/gulp-yarn", | ||
"dependencies": { | ||
"gulp-util": "^3.0.4", | ||
"through2": "^2.0.0", | ||
"which": "^1.0.9" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.2.0", | ||
"mocha": "^3.1.2" | ||
} | ||
} |
Oops, something went wrong.