Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node Build Script #550

Merged
merged 22 commits into from
Oct 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6eb10da
Add interface for new build script
sourrust Aug 22, 2014
17d56d9
Add useful tasks/functions used within each build
sourrust Aug 22, 2014
0df8ce5
Add browser build type
sourrust Aug 22, 2014
bcd014b
Add cdn build type
sourrust Aug 22, 2014
41471d6
Add node build type
sourrust Aug 22, 2014
d0b2ec0
Add dependences for the build script
sourrust Aug 22, 2014
9ff8ffa
Remove old build script and compression jar
sourrust Aug 22, 2014
26b732e
Update docs to mention the new was of building
sourrust Aug 22, 2014
7f8ca7c
Update travis file for node only environment
sourrust Aug 22, 2014
529c7c0
Stop using merge and just use the object directly
sourrust Aug 24, 2014
921c116
Change template to regular style of requiring
sourrust Aug 24, 2014
2a42158
Allow for options in the dest task
sourrust Aug 24, 2014
7b7357e
Use base option to include docs in meta files task
sourrust Aug 24, 2014
9dda2ce
Move over copyDocs to browser build
sourrust Aug 24, 2014
089d9d4
Change typeof comparison to isString function
sourrust Oct 9, 2014
beff3c3
Add category field to appropriate language headers
sourrust Oct 9, 2014
3183f77
Move parseHeader to the utility module
sourrust Oct 9, 2014
0d3f94d
Move headerRegex to top of file
sourrust Oct 9, 2014
cfdb77a
Add filter task
sourrust Oct 9, 2014
31cdc59
Add function for building a filtration callback
sourrust Oct 9, 2014
22cc098
Change builds to filtering tasks
sourrust Oct 9, 2014
b588ff7
Remove unneeded languagesGlob and CATEGORIES
sourrust Oct 9, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
language: python
python:
- "3.3"
before_install:
- "python tools/build.py -t node"
- npm config set python python2.7
install:
- npm install
language: node_js
node_js:
- "0.10"
script:
- npm test
- "node tools/build.js -t node && npm test"
17 changes: 10 additions & 7 deletions docs/building-testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ where you're going to run it: a browser, the node.js server, etc.
Building
--------

The build tool is written in Python, 3.x version. It also can use
YUICompressor for the in-browser builds so make sure you have Java installed
for that too.
The build tool is written in JavaScript using node.js. Before running the
script, make sure to have node installed and run ``npm install`` to get the
dependencies.

The tool is located in ``tools/build.py``. A few useful examples:
The tool is located in ``tools/build.js``. A few useful examples:

* Build for a browser using only common languages::

python3 tools/build.py :common
node tools/build.js :common

* Build for node.js including all available languages::

python3 tools/build.py -t node
node tools/build.js -t node

* Build two specific languages for debugging, skipping compression in this case::

python3 tools/build.py -n python ruby
node tools/build.js -n python ruby

On some systems the node binary is named ``nodejs``; simply replace ``node``
with ``nodejs`` in the examples above if that is the case.

The full option reference is available with the usual ``--help`` option.

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@
"node": "*"
},
"devDependencies": {
"commander": "^2.3.0",
"del": "^0.1.2",
"gear": "^0.9.4",
"gear-lib": "^0.9.1",
"glob": "^4.0.5",
"jsdom": "^0.11.1",
"lodash": "^2.4.1",
"mocha": "^1.21.4",
"should": "^4.0.4"
}
Expand Down
1 change: 1 addition & 0 deletions src/languages/apache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Author: Ruslan Keba <[email protected]>
Contributors: Ivan Sagalaev <[email protected]>
Website: http://rukeba.com/
Description: language definition for Apache configuration files (httpd.conf & .htaccess)
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: Bash
Author: vah <[email protected]>
Contributrors: Benjamin Pannell <[email protected]>
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/coffeescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Language: CoffeeScript
Author: Dmytrii Nagirniak <[email protected]>
Contributors: Oleg Efimov <[email protected]>, Cédric Néhémie <[email protected]>
Description: CoffeeScript is a programming language that transcompiles to JavaScript. For info about language see http://coffeescript.org/
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: C++
Author: Ivan Sagalaev <[email protected]>
Contributors: Evgeny Stepanischev <[email protected]>, Zaven Muradyan <[email protected]>
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/cs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Language: C#
Author: Jason Diamond <[email protected]>
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/css.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Language: CSS
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: Diff
Description: Unified and context diff
Author: Vasily Polovnyov <[email protected]>
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: HTTP
Description: HTTP request and response headers with automatic body highlighting
Author: Ivan Sagalaev <[email protected]>
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/ini.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Language: Ini
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/java.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Language: Java
Author: Vsevolod Solovyov <[email protected]>
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/javascript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Language: JavaScript
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/json.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Language: JSON
Author: Ivan Sagalaev <[email protected]>
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/makefile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Language: Makefile
Author: Ivan Sagalaev <[email protected]>
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Language: Markdown
Requires: xml.js
Author: John Crepezzi <[email protected]>
Website: http://seejohncode.com/
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/nginx.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: Nginx
Author: Peter Leonov <[email protected]>
Contributors: Ivan Sagalaev <[email protected]>
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/objectivec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: Objective C
Author: Valerii Hiora <[email protected]>
Contributors: Angel G. Olloqui <[email protected]>, Matt Diephouse <[email protected]>
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/perl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Language: Perl
Author: Peter Leonov <[email protected]>
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: PHP
Author: Victor Karamzin <[email protected]>
Contributors: Evgeny Stepanischev <[email protected]>, Ivan Sagalaev <[email protected]>
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/python.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Language: Python
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: Ruby
Author: Anton Kovalyov <[email protected]>
Contributors: Peter Leonov <[email protected]>, Vasily Polovnyov <[email protected]>, Loren Segal <[email protected]>, Pascal Hurni <[email protected]>
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/sql.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Language: SQL
Contributors: Nikolay Lisienko <[email protected]>, Heiko August <[email protected]>, Travis Odom <[email protected]>
Category: common
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/xml.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Language: HTML, XML
Category: common
*/

function(hljs) {
Expand Down
102 changes: 102 additions & 0 deletions tools/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
'use strict';

var _ = require('lodash');
var path = require('path');

var utility = require('./utility');

function copyDocs() {
var input = path.join(dir.root, 'docs', '*.rst'),
output = path.join(dir.build, 'docs');

return {
logDocs: { task: ['log', 'Copying documentation.'] },
readDocs: {
requires: 'logDocs',
task: ['glob', { pattern: input }]
},
writeDocsLog: {
requires: 'readDocs',
task: ['log', 'Writing documentation.']
},
writeDocs: { requires: 'writeDocsLog', task: ['dest', output] }
};
}

module.exports = function(commander) {
var amdArgs, hljsExt, output, requiresTask, tasks,
replace = utility.replace,
regex = utility.regex,
replaceClassNames = utility.replaceClassNames,

readArgs = { pattern: path.join('src', '**', '*.js') },
filterCB = utility.buildFilterCallback(commander.args),
replaceArgs = replace(regex.header, ''),
templateArgs = { _: 'hljs.registerLanguage(\'<%= name %>\',' +
' <%= content %>);\n'
, highlight: 'var hljs = new <%= content %>();\n'
};

tasks = {
startlog: { task: ['log', 'Building highlight.js pack file.'] },
read: { requires: 'startlog', task: ['glob', readArgs] },
filter: { requires: 'read', task: ['filter', filterCB] },
reorder: { requires: 'filter', task: 'reorderDeps' },
replace: { requires: 'reorder', task: ['replace', replaceArgs] },
template: { requires: 'replace', task: ['template', templateArgs] },
concat: { requires: 'template', task: 'concat' }
};
requiresTask = 'concat';

if(commander.target === 'amd') {
tasks.amdlog = {
requires: requiresTask,
task: ['log', 'Adding AMD wrapper.']
};

amdArgs = 'define(function() {\n<%= content %>\nreturn hljs;\n});';
tasks.amd = { requires: 'amdlog', task: ['template', amdArgs] };
requiresTask = 'amd';
}

if(commander.compress || commander.target === 'cdn') {
tasks.compresslog = {
requires: requiresTask,
task: ['log', 'Compressing highlight.js pack file.']
};

tasks.replace2 = {
requires: 'compresslog',
task: [ 'replaceSkippingStrings'
, replace(regex.replaces, replaceClassNames)
]
};

tasks.replace3 = {
requires: 'replace2',
task: ['replace', replace(regex.classname, '$1.className')]
};

tasks.minify = { requires: 'replace3', task: 'jsminify' };
requiresTask = 'minify';
}

tasks.writelog = {
requires: requiresTask,
task: ['log', 'Writing highlight.js pack file.']
};

hljsExt = commander.target === 'cdn' ? 'min' : 'pack';
output = path.join(dir.build, 'highlight.' + hljsExt + '.js');

tasks.write = {
requires: 'writelog',
task: ['write', output]
};

if(commander.target === 'browser') {
tasks = _.merge(copyDocs(), tasks);
}

return tasks;
};
41 changes: 41 additions & 0 deletions tools/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

var commander = require('commander');
var path = require('path');
var Queue = require('gear').Queue;
var registry = require('./tasks');

var build;

commander
.usage('[options] [<languages ...>]')
.option('-n, --no-compress', 'Disable compression')
.option('-t, --target <name>', 'Build for target <name> ' +
'[amd, browser, cdn, node]',
'browser')
.parse(process.argv);

switch(commander.target) {
case 'cdn':
build = require('./cdn');
break;
case 'node':
build = require('./node');
break;
case 'amd':
case 'browser':
default:
build = require('./browser');
break;
}

global.dir = {};
global.dir.root = path.dirname(__dirname);
global.dir.build = path.join(dir.root, 'build');

new Queue({ registry: registry })
.clean(dir.build)
.log('Starting build.')
.tasks(build(commander))
.log('Finished build.')
.run();
Loading