Skip to content

Commit

Permalink
Revert "feat: allow hljs to be run from command line (#1951)"
Browse files Browse the repository at this point in the history
This reverts commit ee2ae80.
  • Loading branch information
Marcos Cáceres committed Feb 25, 2019
1 parent 1372427 commit e92ebc6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 81 deletions.
52 changes: 1 addition & 51 deletions docs/building-testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,8 @@ Building and testing
To actually run highlight.js it is necessary to build it for the environment
where you're going to run it: a browser, the node.js server, etc.

Building a bundle from the command line
--------
After installing, you can use `hljs` directly from the command line to build a bundle
with the core languages you need. This is useful for software that requires hljs as part of a build chain.

Usage: `hljs [options] [<language>...]`

Options:
-d, --docs Include documentation and demo (when target "browser")
-n, --no-compress Disable compression
-o, --output <path> directory to output to
(default: "/usr/local/lib/node_modules/highlight.js/build")
-t, --target <name> Build for target [all, browser, cdn, node] (default: "browser")
-h, --help output usage information

Unlike the legacy build tool (section below), it disables generation of docs and demo files by default.

### Example
The following example shows how to build a highlightjs bundle with that outputs to the "js/deps" directory, and includes only the "xml", "javascript", and "css" languages in the bundle.
The bundle is outputted uncompressed (`-n`).

```Bash
hljs -n --output js/deps/ xml javascript css
```

Build just for Web, don't include docs:

```Bash
hljs --output "some/path" xml javascript
```

Build for Web, include docs:

```Bash
hljs --docs --output "some/path" xml javascript
```

Build for NodeJS:

```Bash
hljs -t node --output "some/path" xml javascript
```

Build for everything (Node and Browser):

```Bash
hljs -t all --output "some/path" xml javascript
```

If you provide no arguments, a bundle is built as the described below (the old way).

Building (the old way)
Building
--------

The build tool is written in JavaScript using node.js. Before running the
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
"url": "git://github.com/highlightjs/highlight.js.git"
},
"main": "./lib/index.js",
"bin": {
"hljs": "tools/build.js"
},
"scripts": {
"mocha": "mocha",
"test": "mocha --globals document test",
Expand All @@ -32,9 +29,9 @@
"engines": {
"node": "*"
},
"dependencies": {
"commander": "^2.19.0",
"devDependencies": {
"bluebird": "^3.5.3",
"commander": "^2.19.0",
"del": "^3.0.0",
"gear": "^0.9.7",
"gear-lib": "^0.9.2",
Expand Down
16 changes: 8 additions & 8 deletions tools/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ let path = require('path');
let registry = require('./tasks');
let utility = require('./utility');

let directory = {};
let directory;

function templateAllFunc(blobs) {
const name = path.join(directory.root, 'demo/index.html');
const name = path.join('demo', 'index.html');

blobs = _.compact(blobs);

Expand Down Expand Up @@ -69,29 +69,29 @@ function generateDemo(filterCB, readArgs) {
writeImages: { requires:'readImages', task: ['dest', destArgs] },
readDemoJS: {
requires: 'logStart',
task: ['read', path.join(directory.root, 'demo/demo.js')]
task: ['read', path.join('demo', 'demo.js')]
},
minifyDemoJS: { requires: 'readDemoJS', task: 'jsminify' },
writeDemoJS: { requires: 'minifyDemoJS', task: ['dest', demoRoot] },
readDemoCSS: {
requires: 'logStart',
task: ['read', path.join(directory.root, 'demo/style.css')]
task: ['read', path.join('demo', 'style.css')]
},
minifyDemoCSS: { requires: 'readDemoCSS', task: 'cssminify' },
writeDemoCSS: { requires: 'minifyDemoCSS', task: ['dest', demoRoot] }
};
}

module.exports = function(commander, dir) {
Object.assign(directory, dir);
directory = dir;

let hljsExt, output, requiresTask, tasks,
replace = utility.replace,
regex = utility.regex,
replaceClassNames = utility.replaceClassNames,

coreFile = path.join(directory.root, 'src/highlight.js'),
languages = utility.glob(path.join(directory.root, 'src/languages', '*.js')),
coreFile = path.join('src', 'highlight.js'),
languages = utility.glob(path.join('src', 'languages', '*.js')),
filterCB = utility.buildFilterCallback(commander.args),
replaceArgs = replace(regex.header, ''),
templateArgs =
Expand Down Expand Up @@ -157,7 +157,7 @@ module.exports = function(commander, dir) {
task: ['write', output]
};

tasks = (commander.target === 'browser' && commander.docs)
tasks = (commander.target === 'browser')
? [copyDocs(), generateDemo(filterCB, languages), tasks]
: [tasks];

Expand Down
26 changes: 10 additions & 16 deletions tools/build.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node
// For the basic introductions on using this build script, see:
//
// <https://highlightjs.readthedocs.org/en/latest/building-testing.html>
Expand All @@ -13,11 +12,9 @@
//
// The default target. This will package up the core `highlight.js` along
// with all the language definitions into the file `highlight.pack.js` --
// which will be compressed without including the option to disable it.
//
// If the --docs options is set, it also builds the documentation for our
// readthedocs page, mentioned above, along with a local instance of the demo
// at:
// which will be compressed without including the option to disable it. It
// also builds the documentation for our readthedocs page, mentioned
// above, along with a local instance of the demo at:
//
// <https://highlightjs.org/static/demo/>.
//
Expand Down Expand Up @@ -68,28 +65,25 @@ let path = require('path');
let Queue = require('gear').Queue;
let registry = require('./tasks');

const defaultOutPath = path.resolve(__dirname, '../build');
let build, dir = {};

commander
.usage('[options] [<language>...]')
.option('-d, --docs', 'Include documentation and demo (when target "browser")')
.option('-n, --no-compress', 'Disable compression')
.option('-o, --output <path>', 'directory to output to', defaultOutPath)
.option('-t, --target <name>', 'Build for target ' +
'[all, browser, cdn, node]',
/^(browser|cdn|node|all)$/i, 'browser')
.parse(process.argv);

commander.target = commander.target.toLowerCase();

const build = require(`./${commander.target}`);
const dir = {
build: path.resolve(process.cwd(), commander.output),
root: path.resolve(__dirname, "../"),
};
build = require(`./${commander.target}`);
dir.root = path.dirname(__dirname);
dir.build = path.join(dir.root, 'build');

new Queue({ registry: registry })
.log(`⚒ Starting build for "${commander.target}."`)
.clean(dir.build)
.log('Starting build.')
.series(build(commander, dir))
.log('❤️ Finished build.')
.log('Finished build.')
.run();
2 changes: 1 addition & 1 deletion tools/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function copyMetaFiles() {
glob = `{README.md,LICENSE,${docs}}`,

input = utility.glob(path.join(directory.root, glob)),
output = { dir: directory.build, base: directory.build };
output = { dir: directory.build, base: '.' };

return {
startLog: { task: ['log', 'Copying meta files.'] },
Expand Down

0 comments on commit e92ebc6

Please sign in to comment.