Skip to content

Instantly share code, notes, and snippets.

@earnubs
Last active August 29, 2015 14:05
Show Gist options
  • Save earnubs/edb3d7bac8b3f1319b2b to your computer and use it in GitHub Desktop.
Save earnubs/edb3d7bac8b3f1319b2b to your computer and use it in GitHub Desktop.
yui module build
var buffer = require('vinyl-buffer');
var concat = require('gulp-concat');
var fs = require('fs');
var gulp = require('gulp');
var src = require('vinyl-fs').src;
var tap = require('gulp-tap');
var through = require('through2');
var uglify = require('gulp-uglify');
var paths = {
yui: {
src: ['./branches/yui-3.10.0/src/**/build.json'],
dest: './tmp'
}
};
/**
var ybuild = function (options) {
options = options || {};
options.src = options.src || process.cwd();
var stream = through.obj(function (file, enc, cb) {
var self = this;
if (file.isNull()) {
return cb();
}
if (file.isStream()) {
this.emit('error', new PluginError(PLUGIN_NAME, 'Streams are not supported!'));
return cb();
}
if (file.isBuffer()) {
var data = JSON.parse(file.contents.toString());
var builds = data.builds;
var class_name = data.name;
var jsfiles;
var root;
var paths;
var name;
for (name in builds) {
jsfiles = builds[name].jsfiles;
if (jsfiles !== undefined) {
root = options.src + class_name + '/js/';
paths = jsfiles;
src(paths.map(function(path){
return root + path;
}))
.pipe(concat('build/' + name + '/' + name + '.js'))
.pipe(tap(function(file) {
self.push(file);
}));
}
}
}
cb();
});
return stream;
};
gulp.task('yui', function() {
return gulp.src(paths.yui.src)
.pipe(ybuild({src: './branches/yui-3.10.0/src/'}), { end: false })
.pipe(uglify())
.pipe(gulp.dest('./tmp'));
});
**/
var memory = {};
var yui_src = './branches/yui-3.10.0/src/';
function process_build_json(file) {
var data = JSON.parse(file.contents.toString());
var builds = data.builds;
var class_name = data.name;
var jsfiles;
var root;
var paths;
var out_path;
var name;
var self = this;
var names = Object.keys(builds);
names.forEach(function(name, i, arr) {
jsfiles = builds[name].jsfiles;
if (jsfiles !== undefined) {
out_path = 'build/' + name + '/' + name + '.js';
root = yui_src + class_name + '/js/';
paths = jsfiles;
/**
gulp.src(paths.map(function(path){
return root + path;
}))
.pipe(concat(out_path))
.pipe(tap(function(file) {
memory[out_path] = file.contents.toString();
}));
**/
}
});
}
gulp.task('parse-yui-build-files', function () {
var stream = gulp.src(paths.yui.src)
.pipe(through.obj());
var process = process_build_json.bind(stream);
stream.on('data', function(file) {
process(file);
});
return stream;
});
gulp.task('write-jsfiles', ['parse-yui-build-files'], function() {
var jsfiles = Object.keys(memory);
var streams = [];
console.log(jsfiles);
jsfiles.forEach(function(file) {
var stream = source(file);
var fileContents = memory[file];
streams.push(stream);
stream.write(fileContents);
process.nextTick(function() {
// in the next process cycle, end the stream
stream.end();
});
stream
.pipe(vinylBuffer())
.pipe(uglify())
.pipe(gulp.dest('tmp'));
});
return es.merge.apply(this, streams);
});
gulp.task('yui', function(taskDone) {
runSequence(
['parse-yui-build-files'], // load the files in parallel
'write-jsfiles', // ready to write once all resources are in memory
taskDone // done
);
});
{
"name": "yui",
"prebuilds": [
"get",
"loader"
],
"postbuilds": [
"simpleyui"
],
"exec": [
"./scripts/build.js"
],
"builds": {
"features": {
"jsfiles": [
"features.js",
"load-tests.js"
]
},
"yui-log-nodejs": {
"jsfiles": [
"yui-log-nodejs.js"
]
},
"yui-log": {
"jsfiles": [
"yui-log.js"
]
},
"intl-base": {
"jsfiles": [
"intl-base.js"
]
},
"yui-later": {
"jsfiles": [
"yui-later.js"
]
},
"yui-core": {
"name": "yui-base",
"replace": {
"@YUI_CORE@": "['intl-base']"
},
"prependfiles": [
"js/yui.js"
],
"jsfiles": [
"yui-base.js",
"yui-lang.js",
"yui-array.js",
"queue-base.js",
"yui-core.js",
"yui-object.js",
"yui-ua.js",
"alias.js"
]
},
"yui-base": {
"basefilename": "yui-base",
"name": "yui-base",
"replace": {
"@YUI_CORE@": "['get', 'features', 'intl-base', 'yui-log', 'yui-later']"
},
"config": {
"use": [
"get",
"features",
"intl-base",
"yui-log",
"yui-later"
]
},
"prependfiles": [
"js/yui.js"
],
"jsfiles": [
"yui-base.js",
"yui-lang.js",
"yui-array.js",
"queue-base.js",
"yui-core.js",
"yui-object.js",
"yui-ua.js",
"alias.js"
]
},
"yui-nodejs": {
"basefilename": "yui-nodejs",
"name": "yui-base",
"replace": {
"@YUI_CORE@": "['get', 'features', 'intl-base', 'yui-log', 'yui-log-nodejs', 'yui-later', 'loader-base', 'loader-rollup', 'loader-yui3']"
},
"config": {
"use": [
"yui-base",
"get",
"features",
"intl-base",
"yui-log",
"yui-log-nodejs",
"yui-later",
"loader-base",
"loader-rollup",
"loader-yui3"
]
},
"prependfiles": [
"js/yui.js"
],
"jsfiles": [
"yui-base.js",
"yui-lang.js",
"yui-array.js",
"queue-base.js",
"yui-core.js",
"yui-object.js",
"yui-ua.js",
"alias.js"
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment