UNPKG

5.9 kBJavaScriptView Raw
1var path = require('path')
2var manifest = require(process.cwd() + '/gulp-manifest.json')
3var tasks = require(path.dirname(__filename) + '/lib/gulp-tasks.js')(manifest)
4var fs = require('fs')
5var argv = require('yargs').argv
6
7var exports = {
8 determineAction : determineAction,
9 buildGulpfile : buildGulpfile
10}
11
12module.exports = function(){
13 return exports
14}
15
16//---------------------------------------------------------
17
18function determineAction() {
19
20 var src = null
21 var dest = null
22
23 if(argv.src !== null && argv.src !== undefined) {
24 if(isNaN(argv.src)){
25 for(var i in manifest) {
26 if(manifest[i]["name"] && manifest[i]["name"].toLowerCase() === argv.src.toString().toLowerCase()) {
27 src = i
28
29 if(argv.dest !== null && argv.dest !== undefined){
30 if(isNaN(argv.dest)) {
31 for(var d in manifest[src]["dest"]) {
32 if(manifest[src]["dest"][d]["name"] && manifest[src]["dest"][d]["name"].toLowerCase() === argv.dest.toString().toLowerCase()) {
33 dest = d
34 }
35 }
36 }
37 else if(manifest[src]["dest"].length > argv.dest && argv.dest >= 0) {
38 dest = Math.floor(argv.dest)
39 }
40 }
41 }
42 }
43 }
44 else if (manifest.length > argv.src && argv.src >= 0) {
45 src = Math.floor(argv.src)
46 if(argv.dest !== null && argv.dest !== undefined){
47 if(isNaN(argv.dest)) {
48 for(var d in manifest[src]["dest"]) {
49 if(manifest[src]["dest"][d]["name"] && manifest[src]["dest"][d]["name"].toLowerCase() === argv.dest.toString().toLowerCase()) {
50 dest = d
51 }
52 }
53 }
54 else if(manifest[src]["dest"].length > argv.dest && argv.dest >= 0) {
55 dest = Math.floor(argv.dest)
56 }
57 }
58 }
59 }
60
61 return [src, dest]
62}
63
64//-------------------------------------------------------------
65
66var gulpfileHeader = ""
67gulpfileHeader += "var gulp = require('gulp')\n"
68gulpfileHeader += "var glob = require('glob')\n"
69gulpfileHeader += "var babelify = require('babelify')\n"
70gulpfileHeader += "var browserify = require('browserify')\n"
71gulpfileHeader += "var buffer = require('vinyl-buffer')\n"
72gulpfileHeader += "var source = require('vinyl-source-stream')\n"
73gulpfileHeader += "var uglify = require('gulp-uglify')\n"
74gulpfileHeader += "var sass = require('gulp-sass')\n"
75gulpfileHeader += "var autoprefixer = require('gulp-autoprefixer')\n"
76gulpfileHeader += "var rename = require('gulp-rename')\n"
77gulpfileHeader += "var path = require('path')\n"
78gulpfileHeader += "\n"
79gulpfileHeader += "var manifest = require('./gulp-manifest.json')\n"
80gulpfileHeader += "var amTasks = require('./node_modules/asset-mate/lib/gulp-tasks.js')(manifest)\n"
81gulpfileHeader += "var amCopy = require('./node_modules/asset-mate/lib/copy.js')(manifest)\n"
82gulpfileHeader += "var amRewrite = require('./node_modules/asset-mate/lib/rewrite.js')(manifest)\n"
83gulpfileHeader += "var amAWS = require('./node_modules/asset-mate/lib/aws.js')(manifest)\n"
84gulpfileHeader += "var amImages = require('./node_modules/asset-mate/lib/images.js')(manifest)\n"
85gulpfileHeader += "var amBuild = require('./node_modules/asset-mate/gulpbuild.js')(manifest)\n"
86gulpfileHeader += "\n"
87gulpfileHeader += "\n"
88gulpfileHeader += "//----------------------------------------------------------------\n"
89gulpfileHeader += "\n"
90gulpfileHeader += "var action = amBuild.determineAction()\n"
91gulpfileHeader += "var pkg = action[0]\n"
92gulpfileHeader += "var dest = action[1]\n"
93gulpfileHeader += "\n"
94gulpfileHeader += "var buildTaskName = amTasks.buildTaskname(pkg, dest)\n"
95gulpfileHeader += "var copyTaskName = amTasks.copyTaskname(pkg, dest)\n"
96gulpfileHeader += "var imagesTaskName = amTasks.imagesTaskname(pkg, dest)\n"
97gulpfileHeader += "var deployTaskName = amTasks.deployTaskname(pkg, dest)\n"
98gulpfileHeader += "var watchTaskName = amTasks.watchTaskname(pkg, dest)\n"
99gulpfileHeader += "var scriptsTaskName = amTasks.scriptsTaskname(pkg, dest)\n"
100gulpfileHeader += "var stylesTaskName = amTasks.stylesTaskname(pkg, dest)\n"
101gulpfileHeader += "\n"
102gulpfileHeader += "\n"
103
104
105var gulpfileFooter = "\n"
106gulpfileFooter += "gulp.task('build', [buildTaskName])\n"
107gulpfileFooter += "gulp.task('copy', [copyTaskName])\n"
108gulpfileFooter += "gulp.task('images', [imagesTaskName])\n"
109gulpfileFooter += "gulp.task('deploy', [deployTaskName])\n"
110gulpfileFooter += "gulp.task('scripts', [scriptsTaskName])\n"
111gulpfileFooter += "gulp.task('styles', [stylesTaskName])\n"
112gulpfileFooter += "gulp.task('watch', [watchTaskName])\n"
113gulpfileFooter += "\n"
114
115function buildGulpfile() {
116
117 var output = gulpfileHeader
118
119 output += tasks.build()
120 for(var p in manifest) {
121 output += tasks.build(p)
122 for(var d in manifest[p]["dest"]) {
123 output += tasks.build(p, d)
124 }
125 }
126
127 output += tasks.copy()
128 for(var p in manifest) {
129 output += tasks.copy(p)
130 for(var d in manifest[p]["dest"]) {
131 output += tasks.copy(p, d)
132 }
133 }
134
135 output += tasks.images()
136 for(var p in manifest) {
137 output += tasks.images(p)
138 for(var d in manifest[p]["dest"]) {
139 output += tasks.images(p, d)
140 }
141 }
142
143 output += tasks.deploy()
144 for(var p in manifest) {
145 output += tasks.deploy(p)
146 for(var d in manifest[p]["dest"]) {
147 output += tasks.deploy(p, d)
148 }
149 }
150
151 output += tasks.scripts()
152 for(var p in manifest) {
153 output += tasks.scripts(p)
154 for(var d in manifest[p]["dest"]) {
155 output += tasks.scripts(p, d)
156 }
157 }
158
159 output += tasks.styles()
160 for(var p in manifest) {
161 output += tasks.styles(p)
162 for(var d in manifest[p]["dest"]) {
163 output += tasks.styles(p, d)
164 }
165 }
166
167 output += tasks.watch()
168 for(var p in manifest) {
169 output += tasks.watch(p)
170 }
171
172 output += gulpfileFooter
173 var base = process.cwd()
174 if(base !== "") base += '/'
175 fs.writeFileSync(base + "gulpfile.js", output)
176}
177
178