1 | var path = require('path')
|
2 | var manifest = require(process.cwd() + '/gulp-manifest.json')
|
3 | var tasks = require(path.dirname(__filename) + '/lib/gulp-tasks.js')(manifest)
|
4 | var fs = require('fs')
|
5 | var argv = require('yargs').argv
|
6 |
|
7 | var exports = {
|
8 | determineAction : determineAction,
|
9 | buildGulpfile : buildGulpfile
|
10 | }
|
11 |
|
12 | module.exports = function(){
|
13 | return exports
|
14 | }
|
15 |
|
16 |
|
17 |
|
18 | function 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 |
|
66 | var gulpfileHeader = ""
|
67 | gulpfileHeader += "var gulp = require('gulp')\n"
|
68 | gulpfileHeader += "var glob = require('glob')\n"
|
69 | gulpfileHeader += "var babelify = require('babelify')\n"
|
70 | gulpfileHeader += "var browserify = require('browserify')\n"
|
71 | gulpfileHeader += "var buffer = require('vinyl-buffer')\n"
|
72 | gulpfileHeader += "var source = require('vinyl-source-stream')\n"
|
73 | gulpfileHeader += "var uglify = require('gulp-uglify')\n"
|
74 | gulpfileHeader += "var sass = require('gulp-sass')\n"
|
75 | gulpfileHeader += "var autoprefixer = require('gulp-autoprefixer')\n"
|
76 | gulpfileHeader += "var rename = require('gulp-rename')\n"
|
77 | gulpfileHeader += "var path = require('path')\n"
|
78 | gulpfileHeader += "\n"
|
79 | gulpfileHeader += "var manifest = require('./gulp-manifest.json')\n"
|
80 | gulpfileHeader += "var amTasks = require('./node_modules/asset-mate/lib/gulp-tasks.js')(manifest)\n"
|
81 | gulpfileHeader += "var amCopy = require('./node_modules/asset-mate/lib/copy.js')(manifest)\n"
|
82 | gulpfileHeader += "var amRewrite = require('./node_modules/asset-mate/lib/rewrite.js')(manifest)\n"
|
83 | gulpfileHeader += "var amAWS = require('./node_modules/asset-mate/lib/aws.js')(manifest)\n"
|
84 | gulpfileHeader += "var amImages = require('./node_modules/asset-mate/lib/images.js')(manifest)\n"
|
85 | gulpfileHeader += "var amBuild = require('./node_modules/asset-mate/gulpbuild.js')(manifest)\n"
|
86 | gulpfileHeader += "\n"
|
87 | gulpfileHeader += "\n"
|
88 | gulpfileHeader += "//----------------------------------------------------------------\n"
|
89 | gulpfileHeader += "\n"
|
90 | gulpfileHeader += "var action = amBuild.determineAction()\n"
|
91 | gulpfileHeader += "var pkg = action[0]\n"
|
92 | gulpfileHeader += "var dest = action[1]\n"
|
93 | gulpfileHeader += "\n"
|
94 | gulpfileHeader += "var buildTaskName = amTasks.buildTaskname(pkg, dest)\n"
|
95 | gulpfileHeader += "var copyTaskName = amTasks.copyTaskname(pkg, dest)\n"
|
96 | gulpfileHeader += "var imagesTaskName = amTasks.imagesTaskname(pkg, dest)\n"
|
97 | gulpfileHeader += "var deployTaskName = amTasks.deployTaskname(pkg, dest)\n"
|
98 | gulpfileHeader += "var watchTaskName = amTasks.watchTaskname(pkg, dest)\n"
|
99 | gulpfileHeader += "var scriptsTaskName = amTasks.scriptsTaskname(pkg, dest)\n"
|
100 | gulpfileHeader += "var stylesTaskName = amTasks.stylesTaskname(pkg, dest)\n"
|
101 | gulpfileHeader += "\n"
|
102 | gulpfileHeader += "\n"
|
103 |
|
104 |
|
105 | var gulpfileFooter = "\n"
|
106 | gulpfileFooter += "gulp.task('build', [buildTaskName])\n"
|
107 | gulpfileFooter += "gulp.task('copy', [copyTaskName])\n"
|
108 | gulpfileFooter += "gulp.task('images', [imagesTaskName])\n"
|
109 | gulpfileFooter += "gulp.task('deploy', [deployTaskName])\n"
|
110 | gulpfileFooter += "gulp.task('scripts', [scriptsTaskName])\n"
|
111 | gulpfileFooter += "gulp.task('styles', [stylesTaskName])\n"
|
112 | gulpfileFooter += "gulp.task('watch', [watchTaskName])\n"
|
113 | gulpfileFooter += "\n"
|
114 |
|
115 | function 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 |
|