From 9230a1b8fb701ddad110c26ef6a0773876a0cd13 Mon Sep 17 00:00:00 2001 From: Alex Kit Date: Sun, 30 Nov 2014 22:58:10 +0100 Subject: [PATCH] + Build and Publish --- .gitignore | 3 +- bower.json | 4 +- package.json | 11 +++-- tools/atma-config.js | 15 +++++++ tools/build/builder.js | 87 ++++++++++++++++++++++++++++++++++++ tools/build/extension-umd.js | 30 +++++++++++++ tools/build/prism-lib.js | 15 +++++++ tools/release/process.js | 48 ++++++++++++++++++++ 8 files changed, 207 insertions(+), 6 deletions(-) create mode 100644 tools/atma-config.js create mode 100644 tools/build/builder.js create mode 100644 tools/build/extension-umd.js create mode 100644 tools/build/prism-lib.js create mode 100644 tools/release/process.js diff --git a/.gitignore b/.gitignore index 692a6cb8bc..dfa9bb57b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ hide-*.js node_modules -.idea/ \ No newline at end of file +.idea/ +lib/ \ No newline at end of file diff --git a/bower.json b/bower.json index 984b45ac05..fe42bccfbf 100644 --- a/bower.json +++ b/bower.json @@ -2,8 +2,8 @@ "name": "prism", "version": "0.0.1", "main": [ - "prism.js", - "prism.css" + "lib/prism.js", + "lib/prism.css" ], "homepage": "http://prismjs.com", "authors": "Lea Verou", diff --git a/package.json b/package.json index 06152b4fa8..e45118bb1a 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,12 @@ "name": "prismjs", "version": "0.0.1", "description": "Lightweight, robust, elegant syntax highlighting. A spin-off project from Dabblet.", - "main": "prism.js", + "main": "lib/prism.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "build": "atma tools/atma-config.js run build", + "release": "atma tools/atma-config.js run release", + "watch": "atma tools/atma-config.js run watch" }, "repository": { "type": "git", @@ -22,6 +25,8 @@ "gulp-concat": "^2.3.4", "gulp-header": "^1.0.5", "gulp-rename": "^1.2.0", - "gulp-uglify": "^0.3.1" + "gulp-uglify": "^0.3.1", + "uglify-js": "^2.4.15", + "atma": "^0.10.26" } } diff --git a/tools/atma-config.js b/tools/atma-config.js new file mode 100644 index 0000000000..07649775f5 --- /dev/null +++ b/tools/atma-config.js @@ -0,0 +1,15 @@ +module.exports = { + 'build': { + action: 'custom', + script: '/tools/build/builder.js' + }, + 'release': { + action: 'custom', + script: '/tools/release/process.js' + }, + 'watch': { + files: 'components/**', + config: '#[build]' + }, + 'default': [ 'build' ] +}; \ No newline at end of file diff --git a/tools/build/builder.js b/tools/build/builder.js new file mode 100644 index 0000000000..2e0fecb24a --- /dev/null +++ b/tools/build/builder.js @@ -0,0 +1,87 @@ +module.exports = { + process: function(config, done){ + + build_Prism(); + build_Components(); + build_Plugins(); + + done(); + } +}; + + +var OUTPUT = '/lib/', + DIR = __dirname + '/'; + +function build_Prism () { + io.settings({ + extensions: { + js: [ 'importer:read' ] + } + }); + + saveJavascript( + io.File.read(DIR + 'prism-lib.js'), '', 'prism.js' + ); +} +function build_Components () { + var umd = io.File.read(DIR + 'extension-umd.js'), + SKIP = [ + '.min.', + '-core.', + '-markup.', + '-css.', + '-clike.', + '-javascript.' + ]; + + io.glob.readFiles('components/*.js').forEach(function(file){ + if (!shouldSkip(file, SKIP)) + wrapJavascript(file, umd, 'components/'); + }); +} +function build_Plugins () { + var umd = io.File.read(DIR + 'extension-umd.js'), + SKIP = [ + '.min.', + 'index.html' + ]; + io.glob.read('plugins/*').forEach(function(dir){ + if (dir instanceof io.Directory === false) return; + + var pluginName = dir.getName(); + + dir.readFiles('*').files.forEach(function(file) { + if (shouldSkip(file, SKIP)) return; + if (file.uri.getName() !== 'prism-' + pluginName + '.js') { + file.copyTo(OUTPUT + 'plugins/' + pluginName + '/'); + return; + } + + wrapJavascript(file, umd, 'plugins/' + pluginName + '/'); + }); + }) +} + + +function minify (source) { + return require('uglify-js').minify(source, {fromString: true}).code; +} +function shouldSkip (file, patterns) { + return patterns.some(function(pattern){ + return file.uri.file.indexOf(pattern) !== -1; + }); +} +function wrapJavascript(file, umdSource, outputDir) { + logger.log('wrap', file.uri.file.bold); + + var source = umdSource.replace('//%SOURCE%', function() { + return file.read() + }); + + saveJavascript(source, outputDir, file.uri.file); +} +function saveJavascript(source, outputDir, filename) { + io.File.write(OUTPUT + outputDir + filename, source); + io.File.write(OUTPUT + outputDir + filename.replace('.js', '.min.js'), minify(source), { skipHooks: true }); +} \ No newline at end of file diff --git a/tools/build/extension-umd.js b/tools/build/extension-umd.js new file mode 100644 index 0000000000..c05b0435d0 --- /dev/null +++ b/tools/build/extension-umd.js @@ -0,0 +1,30 @@ +(function(factory){ + + var prism_ = (typeof Prism !== 'undefined' && Prism ) || null, + global_ = (typeof global !== 'undefined' && global) + || (typeof window !== 'undefined' && window) + || (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope && self) + || null; + + if (prism_ == null && typeof require === 'function') { + prism_ = require('prismjs'); + } + if (prism_ == null && typeof define === 'function' && define.amd) { + define(['prismjs'], function (Prism) { + return factory(Prism, global_, { Prism: Prism }); + }); + return; + } + + if (prism_ == null) { + throw Error('Prism is not loaded'); + } + + // some plugins depend on `self` + factory(prism_, global_, { Prism: Prism }); + +}(function(Prism, window, self) { + + //%SOURCE% + +})); \ No newline at end of file diff --git a/tools/build/prism-lib.js b/tools/build/prism-lib.js new file mode 100644 index 0000000000..7d9d821040 --- /dev/null +++ b/tools/build/prism-lib.js @@ -0,0 +1,15 @@ +(function(root, factory){ + + factory(root); + +}(this, function(self) { + + // import /components/prism-core.js + + // import /components/prism-markup.js + // import /components/prism-css.js + // import /components/prism-clike.js + // import /components/prism-javascript.js + // import /plugins/file-highlight/prism-file-highlight.js + +})); \ No newline at end of file diff --git a/tools/release/process.js b/tools/release/process.js new file mode 100644 index 0000000000..8d2bf6b234 --- /dev/null +++ b/tools/release/process.js @@ -0,0 +1,48 @@ +var Builder = require('../build/builder'); +var BRANCH = 'builder'; + +module.exports = { + process: function(config, done){ + + app + .findAction('release') + .done(function(Release){ + + // bump package.json and bower.json versions + Release.bump(function(err, version){ + + Release.runCommands([ + 'git add -A', + 'git commit -a -m "v' + version + '"', + 'git push origin ' + BRANCH, + 'git checkout -B release', + function (done) { + Builder.process({}, done); + }, + function () { + Release.includeFiles.create([ + 'lib/**', + 'themes/**', + 'README.md', + 'LICENSE', + 'package.json', + 'bower.json' + ]); + }, + 'git rm -r --cached .', + 'git add -A', + 'git commit -a -m "v' + version + '"', + 'git push origin release -ff', + 'git tag v' + version, + 'git push --tags', + //'npm publish', + function () { + Release.includeFiles.reset(); + }, + 'git checkout ' + BRANCH + ' -ff' + ], done); + }); + + }); + } +}; \ No newline at end of file