Skip to content

Commit 1a9bdc0

Browse files
committedAug 22, 2013
add swig.version and -v to cli
1 parent 76669ec commit 1a9bdc0

File tree

7 files changed

+64
-2
lines changed

7 files changed

+64
-2
lines changed
 

‎Makefile

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SHA := $(shell git rev-parse HEAD)
22
THIS_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
3-
VERSION_REGEX = [0-9]*\.[0-9]*\.[0-9]*[^\" ]*
3+
VERSION_REGEX = [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*[^\" ]*
44
VERSION := $(shell npm ls | grep "swig@" | grep -Eo "${VERSION_REGEX}" -m 1)
55

66
TMP = 'tmp'
@@ -14,6 +14,14 @@ all:
1414
@cp scripts/githooks/* .git/hooks/
1515
@chmod -R +x .git/hooks/
1616

17+
.INTERMEDIATE version: \
18+
browser/comments.js \
19+
docs/index.json
20+
21+
version:
22+
@sed -i.bak 's/${VERSION_REGEX}/${VERSION}/' lib/swig.js
23+
@rm lib/swig.js.bak
24+
1725
browser/comments.js: FORCE
1826
@sed -i.bak 's/v${VERSION_REGEX}/v${VERSION}/' $@
1927
@rm $@.bak
@@ -156,7 +164,7 @@ docs: build build-docs
156164

157165
FORCE:
158166

159-
.PHONY: all \
167+
.PHONY: all version \
160168
build build-docs \
161169
test test-browser lint coverage \
162170
docs/index.json docs gh-pages

‎bin/swig.js

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var command,
1616
' $0 render [files] [options]\n'
1717
)
1818
.describe({
19+
v: 'Show the Swig version number.',
1920
o: 'Output location.',
2021
h: 'Show this help screen.',
2122
j: 'Variable context as a JSON file.',
@@ -25,6 +26,7 @@ var command,
2526
'wrap-end': 'Template wrapper end for "compile".',
2627
'method-name': 'Method name to set template to and run from.'
2728
})
29+
.alias('v', 'version')
2830
.alias('o', 'output')
2931
.default('o', 'stdout')
3032
.alias('h', 'help')
@@ -35,6 +37,10 @@ var command,
3537
.default('wrap-end', ';')
3638
.default('method-name', 'tpl')
3739
.check(function (argv) {
40+
if (argv.v) {
41+
return;
42+
}
43+
3844
if (!argv._.length) {
3945
throw new Error('');
4046
}
@@ -62,6 +68,11 @@ var command,
6268
files,
6369
fn;
6470

71+
if (argv.v) {
72+
console.log(require('../package').version);
73+
process.exit(0);
74+
}
75+
6576
if (argv.j) {
6677
ctx = JSON.parse(fs.readFileSync(argv.j, 'utf8'));
6778
} else if (argv.c) {

‎docs/docs/api.html

+18
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ <h3>Examples</h3>
4242
</section>
4343
{% endfor %}
4444

45+
{% for prop in properties %}
46+
<section id="{{ prop.name }}" class="doc">
47+
<h2>swig.{{ prop.name }}</h2>
48+
49+
<p>{{ prop.description|replace('\n', '</p><p>')|raw }}</p>
50+
51+
{% if prop.examples.length %}
52+
<h3>Examples</h3>
53+
{% for example in prop.examples %}
54+
<pre><code data-language="js">{{ example }}</code></pre>
55+
{% endfor %}
56+
{% endif %}
57+
</section>
58+
{% endfor %}
59+
4560
{% for fn in functions %}
4661
{% if fn.access !== "private" %}
4762
<section id="{{ fn.name }}" class="doc">
@@ -104,6 +119,9 @@ <h3>Examples</h3>
104119
{% for def in typedefs %}
105120
<li><a href="#{{ def.name }}">Object: {{ def.name }}</a></li>
106121
{% endfor %}
122+
{% for prop in properties %}
123+
<li><a href="#{{ prop.name }}">swig.{{ prop.name }}</a></li>
124+
{% endfor %}
107125
{% for fn in functions %}
108126
{% if fn.access !== "private" %}
109127
<li>

‎docs/docs/cli.html

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ <h2>Usage</h2>
2121

2222
<h3>Options</h3>
2323
<pre>
24+
-v, --version Show the Swig version number.
2425
-o, --output Output location. [default: "stdout"]
2526
-h, --help Show this help screen.
2627
-j, --json Variable context as a JSON file.

‎lib/swig.js

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ var fs = require('fs'),
66
parser = require('./parser'),
77
dateformatter = require('./dateformatter');
88

9+
/**
10+
* Swig version number as a string.
11+
* @example
12+
* if (swig.version === "1.0.0-pre3") { ... }
13+
*
14+
* @type {String}
15+
*/
16+
exports.version = "1.0.0-pre3";
17+
918
/**
1019
* Swig Options Object. This object can be passed to many of the API-level Swig methods to control various aspects of the engine. All keys are optional.
1120
* @typedef {Object} SwigOpts

‎tests/basic.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ function resetOptions() {
1212
swig.invalidateCache();
1313
}
1414

15+
describe('version', function () {
16+
it('is 1.0.0-pre3', function () {
17+
expect(swig.version).to.equal('1.0.0-pre3');
18+
});
19+
});
20+
1521
describe('options', function () {
1622
beforeEach(resetOptions);
1723
afterEach(resetOptions);

‎tests/bin.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ var casefiles = fs.readdirSync(__dirname + '/cases/'),
2121
return f.split('.')[0];
2222
});
2323

24+
describe('bin/swig -v', function () {
25+
it('shows the version number', function (done) {
26+
exec(bin + ' -v', function (err, stdout, stderr) {
27+
expect((/^\d+\.\d+\.\d+/).test(stdout)).to.equal(true);
28+
done();
29+
});
30+
});
31+
});
32+
2433
describe('bin/swig render', function () {
2534
_.each(cases, function (files, c) {
2635
var test = _.find(files, isTest),

0 commit comments

Comments
 (0)
Please sign in to comment.