Skip to content

Commit 3d2ab29

Browse files
committed
Add source
1 parent d5b581b commit 3d2ab29

File tree

6 files changed

+87
-0
lines changed

6 files changed

+87
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib/*
2+
node_modules/*

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/*

gulpfile.coffee

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
gulp = require 'gulp'
2+
coffee = require 'gulp-coffee'
3+
4+
paths = {}
5+
paths.src = __dirname + '/src'
6+
paths.dest = __dirname + '/lib'
7+
8+
gulp.task 'coffee', () ->
9+
10+
gulp.src paths.src + '/**/*.coffee'
11+
.pipe coffee()
12+
.pipe gulp.dest paths.dest
13+
14+
gulp.task 'default', ['coffee']

package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "scripts-loader",
3+
"version": "0.1.0",
4+
"description": "Walk directory recursive and load all the scripts from there. (Super helpful when you want to separate your big gulp file into standalone tasks and load each task very easily.)",
5+
"main": "y",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/jsifalda/scripts-loader"
9+
},
10+
"keywords": [
11+
"gulp",
12+
"scripts",
13+
"loader",
14+
"tasks"
15+
],
16+
"author": "Jiri Sifalda <sifalda.jiri@gmail.com> (http://jsifalda.name/)",
17+
"license": "MIT",
18+
"bugs": {
19+
"url": "https://github.com/jsifalda/scripts-loader/issues"
20+
},
21+
"homepage": "https://github.com/jsifalda/scripts-loader",
22+
"devDependencies": {
23+
"coffee-script": "^1.8.0",
24+
"gulp": "^3.8.10",
25+
"gulp-coffee": "^2.2.0"
26+
}
27+
}

src/helpers/filter.coffee

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
path = require 'path'
2+
3+
module.exports = (name, endings = 'js|coffee') ->
4+
5+
pattern = "(\.(#{ endings })$)"
6+
regex = new RegExp pattern, 'i'
7+
8+
return regex.test(path.extname(name))

src/index.coffee

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
file = require 'file'
2+
3+
filter = require './helpers/filter'
4+
5+
scriptLoader = {
6+
7+
get : (path, options = {}) ->
8+
9+
tasks = []
10+
11+
file.walkSync path, (dir, b, files, d) ->
12+
13+
if files and files.length
14+
for file in files
15+
16+
if filter file, options.endings
17+
tasks.push dir + '/' + file
18+
19+
return tasks
20+
21+
load : (path, options = {}) ->
22+
23+
verbose = if options.verbose and options.verbose == true then true else false
24+
25+
tasks = scriptLoader.get path, options
26+
27+
for task in tasks
28+
if verbose
29+
console.log "Load script #{ task }"
30+
require task
31+
32+
}
33+
34+
35+
module.exports = scriptLoader

0 commit comments

Comments
 (0)