Written build script for assets
This commit is contained in:
parent
5f9d4a54a2
commit
955232d587
197
Jakefile.js
197
Jakefile.js
|
@ -1,197 +0,0 @@
|
|||
/**
|
||||
* Jake build script
|
||||
*/
|
||||
var jake = require('jake'),
|
||||
CleanCSS = require('clean-css'),
|
||||
archiver = require('archiver'),
|
||||
fs = require('fs');
|
||||
|
||||
require('jake-utils');
|
||||
|
||||
// constants
|
||||
var BUILD = './',
|
||||
ASSET = BUILD + 'asset/',
|
||||
BUILD_ACE = BUILD + 'asset/ace/',
|
||||
BUILD_JSONLINT = BUILD + 'asset/jsonlint/',
|
||||
JSONEDITOR = BUILD +'jsoneditor.js',
|
||||
JSONEDITOR_CSS = BUILD + 'jsoneditor.css',
|
||||
JSONEDITOR_MIN = BUILD + 'jsoneditor.min.js',
|
||||
JSONEDITOR_CSS_MIN = BUILD + 'jsoneditor.min.css';
|
||||
|
||||
/**
|
||||
* default task
|
||||
*/
|
||||
desc('Execute all tasks');
|
||||
task('default', ['clear', 'build', 'minify'], function () {
|
||||
console.log('Done');
|
||||
});
|
||||
|
||||
/**
|
||||
* build the library
|
||||
*/
|
||||
desc('Clear the asset directory');
|
||||
task('clear', function () {
|
||||
jake.rmRf(ASSET);
|
||||
});
|
||||
|
||||
/**
|
||||
* build the library
|
||||
*/
|
||||
desc('Build the library');
|
||||
task('build', ['clear'], function () {
|
||||
var jsoneditorSrc = './src/';
|
||||
// concatenate the javascript files
|
||||
concat({
|
||||
src: [
|
||||
jsoneditorSrc + 'js/JSONEditor.js',
|
||||
jsoneditorSrc + 'js/TreeEditor.js',
|
||||
jsoneditorSrc + 'js/TextEditor.js',
|
||||
jsoneditorSrc + 'js/Node.js',
|
||||
jsoneditorSrc + 'js/AppendNode.js',
|
||||
jsoneditorSrc + 'js/ContextMenu.js',
|
||||
jsoneditorSrc + 'js/History.js',
|
||||
jsoneditorSrc + 'js/modebox.js',
|
||||
jsoneditorSrc + 'js/SearchBox.js',
|
||||
jsoneditorSrc + 'js/Highlighter.js',
|
||||
jsoneditorSrc + 'js/util.js',
|
||||
jsoneditorSrc + 'js/module.js'
|
||||
],
|
||||
dest: JSONEDITOR,
|
||||
header: read(jsoneditorSrc +'js/header.js') + '\n' +
|
||||
'(function () {\n',
|
||||
separator: '\n',
|
||||
footer: '\n})();\n'
|
||||
});
|
||||
|
||||
// update version number and stuff in the javascript files
|
||||
replacePlaceholders(JSONEDITOR);
|
||||
console.log('Created ' + JSONEDITOR);
|
||||
|
||||
// concatenate and stringify the css files
|
||||
concat({
|
||||
src: [
|
||||
jsoneditorSrc + 'css/jsoneditor.css',
|
||||
jsoneditorSrc + 'css/contextmenu.css',
|
||||
jsoneditorSrc + 'css/menu.css',
|
||||
jsoneditorSrc + 'css/searchbox.css'
|
||||
],
|
||||
dest: JSONEDITOR_CSS,
|
||||
separator: '\n'
|
||||
});
|
||||
console.log('Created ' + JSONEDITOR_CSS);
|
||||
|
||||
// minify the css file
|
||||
write(JSONEDITOR_CSS_MIN, new CleanCSS().minify(String(read(JSONEDITOR_CSS))));
|
||||
|
||||
// create a folder img and copy the icons
|
||||
jake.mkdirP('./img');
|
||||
jake.cpR(jsoneditorSrc + 'css/img/jsoneditor-icons.png', './img/');
|
||||
console.log('Copied jsoneditor-icons.png to ./img/');
|
||||
|
||||
// copy assets
|
||||
// concatenate and copy ace files
|
||||
var aceSrc = './node_modules/ace/build/src-min/';
|
||||
jake.mkdirP(BUILD_ACE);
|
||||
concat({
|
||||
src: [
|
||||
aceSrc + 'ace.js',
|
||||
aceSrc + 'ext-searchbox.js',
|
||||
aceSrc + 'mode-json.js',
|
||||
aceSrc + 'theme-textmate.js',
|
||||
jsoneditorSrc + 'js/ace/theme-jsoneditor.js'
|
||||
],
|
||||
dest: BUILD_ACE + 'ace.js',
|
||||
separator: '\n'
|
||||
});
|
||||
jake.cpR(aceSrc + 'worker-json.js', BUILD_ACE);
|
||||
|
||||
// copy and minify json lint file
|
||||
jake.mkdirP(BUILD_JSONLINT);
|
||||
minify({
|
||||
src: './node_modules/jsonlint/lib/jsonlint.js',
|
||||
dest: BUILD_JSONLINT + 'jsonlint.js'
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* minify the library
|
||||
*/
|
||||
desc('Minify the library');
|
||||
task('minify', ['build'], function () {
|
||||
// minify javascript
|
||||
minify({
|
||||
src: JSONEDITOR,
|
||||
dest: JSONEDITOR_MIN,
|
||||
header: read('./src/js/header.js'),
|
||||
separator: '\n'
|
||||
});
|
||||
|
||||
// update version number and stuff in the javascript files
|
||||
replacePlaceholders(JSONEDITOR_MIN);
|
||||
|
||||
console.log('Created ' + JSONEDITOR_MIN);
|
||||
});
|
||||
|
||||
/**
|
||||
* zip the library
|
||||
*/
|
||||
desc('Zip the library');
|
||||
task('zip', ['build', 'minify'], {async: true}, function () {
|
||||
var pkg = 'jsoneditor-' + version();
|
||||
var zipfile = BUILD + pkg + '.zip';
|
||||
jake.mkdirP(BUILD);
|
||||
|
||||
var output = fs.createWriteStream(zipfile);
|
||||
var archive = archiver('zip');
|
||||
|
||||
archive.on('error', function(err) {
|
||||
throw err;
|
||||
});
|
||||
|
||||
archive.pipe(output);
|
||||
|
||||
var filelist = new jake.FileList();
|
||||
filelist.include([
|
||||
'README.md',
|
||||
'NOTICE',
|
||||
'LICENSE',
|
||||
'HISTORY.md',
|
||||
JSONEDITOR,
|
||||
JSONEDITOR_CSS,
|
||||
JSONEDITOR_MIN,
|
||||
JSONEDITOR_CSS_MIN,
|
||||
'img/*.*',
|
||||
'lib/**/*.*',
|
||||
'docs/**/*.*',
|
||||
'examples/**/*.*'
|
||||
]);
|
||||
var files = filelist.toArray();
|
||||
files.forEach(function (file) {
|
||||
archive.append(fs.createReadStream(file), {
|
||||
name: pkg + '/' + file
|
||||
})
|
||||
});
|
||||
|
||||
archive.finalize(function(err, written) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
console.log('Zipped ' + zipfile);
|
||||
complete();
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* replace version, date, and name placeholders in the provided file
|
||||
* @param {String} filename
|
||||
*/
|
||||
var replacePlaceholders = function (filename) {
|
||||
replace({
|
||||
replacements: [
|
||||
{pattern: '@@date', replacement: today()},
|
||||
{pattern: '@@version', replacement: version()}
|
||||
],
|
||||
src: filename
|
||||
});
|
||||
};
|
22
README.md
22
README.md
|
@ -96,25 +96,23 @@ download:
|
|||
|
||||
### Build
|
||||
|
||||
The code of the JSON Editor is located in the folder `src`. To build
|
||||
The code of the JSON Editor is located in the folder `./src`. To build
|
||||
jsoneditor:
|
||||
|
||||
- Install dependencies:
|
||||
|
||||
npm install
|
||||
|
||||
- Build Ace editor:
|
||||
|
||||
cd node_modules/ace
|
||||
npm install
|
||||
node ./Makefile.dryice.js -m
|
||||
cd ../..
|
||||
|
||||
This generates the ace editor files in the folder `node_modules/ace/build`.
|
||||
|
||||
- Build JSON Editor:
|
||||
|
||||
npm run build
|
||||
|
||||
This will generate the files `jsoneditor.js`, `jsoneditor.css`, and minified
|
||||
versions in the root of the project.
|
||||
This will generate the files `./jsoneditor.js`, `./jsoneditor.css`, and
|
||||
minified versions in the root of the project.
|
||||
|
||||
- To rebuild the assets (not necessary):
|
||||
|
||||
npm run build-assets
|
||||
|
||||
This will build Ace editor, and then generates necessary ace editor files in
|
||||
the folder `./asset/ace`, and jsonlint in the folder `./asset/jsonlint`.
|
||||
|
|
|
@ -146,4 +146,3 @@ background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZ
|
|||
var dom = require("../lib/dom");
|
||||
dom.importCssString(exports.cssText, exports.cssClass);
|
||||
});
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ var options = {
|
|||
"mode": "tree",
|
||||
"search": true
|
||||
};
|
||||
var editor = new JSONEditor (container, options);
|
||||
var editor = new JSONEditor(container, options);
|
||||
var json = {
|
||||
"Array": [1, 2, 3],
|
||||
"Boolean": true,
|
||||
|
@ -155,7 +155,7 @@ var options = {
|
|||
"mode": "text",
|
||||
"indentation": 2
|
||||
};
|
||||
var editor = new JSONEditor (container, options);
|
||||
var editor = new JSONEditor(container, options);
|
||||
var json = {
|
||||
"Array": [1, 2, 3],
|
||||
"Boolean": true,
|
||||
|
|
93
gulpfile.js
93
gulpfile.js
|
@ -1,8 +1,13 @@
|
|||
var fs = require('fs'),
|
||||
gulp = require('gulp'),
|
||||
gutil = require('gulp-util'),
|
||||
concat = require('gulp-concat'),
|
||||
concatCss = require('gulp-concat-css'),
|
||||
minifyCSS = require('gulp-minify-css'),
|
||||
clean = require('gulp-clean'),
|
||||
shell = require('gulp-shell'),
|
||||
merge = require('merge-stream'),
|
||||
mkdirp = require('mkdirp'),
|
||||
webpack = require('webpack'),
|
||||
uglify = require('uglify-js');
|
||||
|
||||
|
@ -16,7 +21,9 @@ var ENTRY = './src/js/JSONEditor.js',
|
|||
JSONEDITOR_MIN_JS = DIST + FILE_MIN,
|
||||
JSONEDITOR_MAP_JS = DIST + FILE_MAP,
|
||||
JSONEDITOR_CSS = DIST + 'jsoneditor.css',
|
||||
JSONEDITOR_MIN_CSS = DIST + 'jsoneditor.min.css';
|
||||
JSONEDITOR_MIN_CSS = DIST + 'jsoneditor.min.css',
|
||||
DIST_ACE = './asset/ace/',
|
||||
DIST_JSONLINT = './asset/jsonlint/';
|
||||
|
||||
// generate banner with today's date and correct version
|
||||
function createBanner() {
|
||||
|
@ -55,10 +62,12 @@ var uglifyConfig = {
|
|||
// create a single instance of the compiler to allow caching
|
||||
var compiler = webpack(webpackConfig);
|
||||
|
||||
gulp.task('bundle', function (cb) {
|
||||
gulp.task('bundle', function (done) {
|
||||
// update the banner contents (has a date in it which should stay up to date)
|
||||
bannerPlugin.banner = createBanner();
|
||||
|
||||
// TODO: split this task in three tasks? bundle-js, bundle-css, bundle-img
|
||||
|
||||
// bundle javascript
|
||||
compiler.run(function (err, stats) {
|
||||
if (err) {
|
||||
|
@ -67,7 +76,7 @@ gulp.task('bundle', function (cb) {
|
|||
|
||||
gutil.log('bundled ' + JSONEDITOR_JS);
|
||||
|
||||
cb();
|
||||
done();
|
||||
});
|
||||
|
||||
// bundle css
|
||||
|
@ -86,6 +95,11 @@ gulp.task('bundle', function (cb) {
|
|||
gutil.log('bundled ' + JSONEDITOR_CSS);
|
||||
gutil.log('bundled ' + JSONEDITOR_MIN_CSS);
|
||||
|
||||
// create a folder img and copy the icons
|
||||
mkdirp.sync('./img');
|
||||
gulp.src('./src/css/img/jsoneditor-icons.png')
|
||||
.pipe(gulp.dest('./img/'));
|
||||
gutil.log('Copied jsoneditor-icons.png to ./img/');
|
||||
});
|
||||
|
||||
gulp.task('minify', ['bundle'], function () {
|
||||
|
@ -99,9 +113,80 @@ gulp.task('minify', ['bundle'], function () {
|
|||
|
||||
});
|
||||
|
||||
gulp.task('asset-clean', function () {
|
||||
return gulp.src('./asset', {read: false})
|
||||
.pipe(clean());
|
||||
});
|
||||
|
||||
// TODO: bundle and minify assets
|
||||
gulp.task('build-ace', shell.task([
|
||||
// see https://github.com/ajaxorg/ace/#building-ace
|
||||
'cd ./node_modules/ace/; '+
|
||||
'npm install; ' +
|
||||
'node ./Makefile.dryice.js -m; ' +
|
||||
'cd ../..'
|
||||
]));
|
||||
|
||||
gulp.task('asset-ace', ['build-ace', 'asset-clean'], function () {
|
||||
// concatenate and copy ace files
|
||||
var aceSrc = './node_modules/ace/build/src-min/';
|
||||
mkdirp.sync(DIST_ACE);
|
||||
|
||||
// TODO: throw an error when aceSrc is missing?
|
||||
|
||||
return merge(
|
||||
gulp.src([
|
||||
aceSrc + 'ace.js',
|
||||
aceSrc + 'ext-searchbox.js',
|
||||
aceSrc + 'mode-json.js',
|
||||
aceSrc + 'theme-textmate.js',
|
||||
'./src/js/ace/theme-jsoneditor.js'
|
||||
])
|
||||
.pipe(concat('ace.js'))
|
||||
.pipe(gulp.dest(DIST_ACE)),
|
||||
|
||||
gulp.src(aceSrc + 'worker-json.js')
|
||||
.pipe(gulp.dest(DIST_ACE))
|
||||
);
|
||||
});
|
||||
|
||||
gulp.task('asset-jsonlint', ['asset-clean'], function (done) {
|
||||
// copy and minify json lint file
|
||||
mkdirp.sync(DIST_JSONLINT);
|
||||
var result = uglify.minify(['./node_modules/jsonlint/lib/jsonlint.js']);
|
||||
fs.writeFileSync(DIST_JSONLINT + 'jsonlint.js', result.code);
|
||||
gutil.log('Minified ' + DIST_JSONLINT + 'jsonlint.js');
|
||||
done();
|
||||
});
|
||||
|
||||
gulp.task('build-assets', ['asset-clean', 'asset-ace', 'asset-jsonlint'], function () {});
|
||||
|
||||
// TODO: create zip file?
|
||||
//gulp.task('zip', ['bundle', 'minify'], function () {
|
||||
// var pkg = 'jsoneditor-' + require('./package.json').version;
|
||||
// var file = BUILD + pkg + '.zip';
|
||||
//
|
||||
// var zip = require('gulp-zip');
|
||||
//
|
||||
// gulp.task('default', function () {
|
||||
// gulp.src([
|
||||
// 'README.md',
|
||||
// 'NOTICE',
|
||||
// 'LICENSE',
|
||||
// 'HISTORY.md',
|
||||
// JSONEDITOR_JS,
|
||||
// JSONEDITOR_CSS,
|
||||
// JSONEDITOR_MIN_JS,
|
||||
// JSONEDITOR_MAP_JS,
|
||||
// JSONEDITOR_MIN_CSS,
|
||||
// 'img/*.*',
|
||||
// 'asset/**/*.*',
|
||||
// 'docs/**/*.*',
|
||||
// 'examples/**/*.*'
|
||||
// ])
|
||||
// .pipe(zip(file))
|
||||
// .pipe(gulp.dest('.'));
|
||||
// });
|
||||
//});
|
||||
|
||||
// The default task (called when you run `gulp`)
|
||||
gulp.task('default', ['bundle', 'minify']);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
*
|
||||
* @author Jos de Jong, <wjosdejong@gmail.com>
|
||||
* @version 3.0.0-SNAPSHOT
|
||||
* @date 2014-05-29
|
||||
* @date 2014-05-30
|
||||
*/
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -17,16 +17,22 @@
|
|||
},
|
||||
"bugs": "https://github.com/josdejong/jsoneditor/issues",
|
||||
"scripts": {
|
||||
"build": "gulp"
|
||||
"build": "gulp",
|
||||
"build-assets": "gulp build-assets"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"ace": "git://github.com/ajaxorg/ace.git",
|
||||
"gulp": "latest",
|
||||
"gulp-clean": "^0.3.0",
|
||||
"gulp-concat": "^2.2.0",
|
||||
"gulp-concat-css": "^0.1.4",
|
||||
"gulp-minify-css": "^0.3.4",
|
||||
"gulp-shell": "^0.2.5",
|
||||
"gulp-util": "latest",
|
||||
"jsonlint": "latest",
|
||||
"merge-stream": "^0.1.1",
|
||||
"mkdirp": "^0.5.0",
|
||||
"uglify-js": "latest",
|
||||
"webpack": "latest"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue