Skip to content

Commit 29703eb

Browse files
committed
Rename package to 'syntaxdev'; restructure CLI commands; add build pipelines
1 parent ee60bf1 commit 29703eb

File tree

4 files changed

+124
-59
lines changed

4 files changed

+124
-59
lines changed

bin/syntaxdev.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
6+
var syntaxdev = require('../index'),
7+
argparse = require('argparse'),
8+
packageInfo = require('../package.json'),
9+
_ = require('underscore');
10+
11+
12+
var cli = new argparse.ArgumentParser({
13+
prog: packageInfo.name,
14+
version: packageInfo.version,
15+
addHelp: true
16+
});
17+
18+
var sub = cli.addSubparsers({
19+
dest: 'command'
20+
});
21+
22+
var testCli = sub.addParser('test');
23+
24+
testCli.addArgument([ '--tests' ], {
25+
help: 'Test files, ex: "--tests test/**/*.test"',
26+
nargs: '*',
27+
action: 'append',
28+
required: true
29+
});
30+
31+
32+
testCli.addArgument([ '--no-color' ], {
33+
help: "Don't use colored output",
34+
action: 'storeTrue',
35+
default: false
36+
});
37+
38+
39+
testCli.addArgument([ '--syntax' ], {
40+
help: 'Syntax file in YAML format, ex: "--syntax FooLang.YAML-tmLanguage"',
41+
required: true
42+
});
43+
44+
45+
var buildCsonCli = sub.addParser('build-cson');
46+
47+
buildCsonCli.addArgument([ '--in' ], {
48+
help: '"in" YAML file',
49+
required: true
50+
});
51+
52+
buildCsonCli.addArgument([ '--out' ], {
53+
help: '"out" CSON file',
54+
required: true
55+
});
56+
57+
58+
var buildPListCli = sub.addParser('build-plist');
59+
60+
buildPListCli.addArgument([ '--in' ], {
61+
help: '"in" YAML file',
62+
required: true
63+
});
64+
65+
buildPListCli.addArgument([ '--out' ], {
66+
help: '"out" PList file',
67+
required: true
68+
});
69+
70+
71+
function main() {
72+
var options = cli.parseArgs();
73+
74+
if (options.command == 'test') {
75+
syntaxdev.test(
76+
_.chain(options.tests).flatten().uniq().sort().value(),
77+
options.syntax,
78+
{
79+
no_color: options.no_color
80+
}
81+
);
82+
} else if (options.command == 'build-cson') {
83+
syntaxdev.buildCson(options.in, options.out);
84+
} else if (options.command == 'build-plist') {
85+
syntaxdev.buildPList(options.in, options.out);
86+
}
87+
}
88+
89+
90+
main();

bin/syntaxtest.js

Lines changed: 0 additions & 51 deletions
This file was deleted.

index.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ var chalk = require("chalk"),
77
mate = require("first-mate"),
88
jsdiff = require("diff"),
99
temp = require("temp").track(),
10-
_ = require('underscore');
10+
_ = require("underscore"),
11+
cson = require("CSON"),
12+
plist = require("plist");
1113

1214

1315
function compileGrammar(grammarFile) {
@@ -166,7 +168,7 @@ function testFile(file, grammar, options) {
166168
}
167169

168170

169-
function run(testFiles, grammarFile, options) {
171+
function test(testFiles, grammarFile, options) {
170172
options = options || {};
171173

172174
var grammar = compileGrammar(grammarFile),
@@ -214,4 +216,26 @@ function run(testFiles, grammarFile, options) {
214216
}
215217

216218

217-
module.exports = run;
219+
function buildCson(inName, outName) {
220+
var yamlSource = fs.readFileSync(inName, 'utf8'),
221+
yamlSchema = yaml.safeLoad(yamlSource),
222+
csonSource = cson.createCSONString(yamlSchema, {indent: 2});
223+
224+
fs.writeFileSync(outName, csonSource);
225+
}
226+
227+
228+
function buildPList(inName, outName) {
229+
var yamlSource = fs.readFileSync(inName, 'utf8'),
230+
yamlSchema = yaml.safeLoad(yamlSource),
231+
plistSource = plist.build(yamlSchema);
232+
233+
fs.writeFileSync(outName, plistSource);
234+
}
235+
236+
237+
module.exports = {
238+
test: test,
239+
buildCson: buildCson,
240+
buildPList: buildPList
241+
};

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"name": "syntaxtest",
3-
"version": "0.0.2",
2+
"name": "syntaxdev",
3+
"version": "0.0.3",
44
"description": "Unit testing framework for TextMate/Sublime/Atom syntaxes.",
55
"main": "index.js",
66
"author": "Yury Selivanov <yury@magic.io>",
77
"license": "MIT",
88
"bin": {
9-
"syntaxtest": "bin/syntaxtest.js"
9+
"syntaxdev": "bin/syntaxdev.js"
1010
},
1111
"repository": {
1212
"type": "git",
13-
"url": "https://github.com/MagicStack/syntaxtest"
13+
"url": "https://github.com/MagicStack/syntaxdev"
1414
},
1515
"dependencies": {
1616
"first-mate": "^5.0.2",
@@ -19,6 +19,8 @@
1919
"argparse": "^1.0.2",
2020
"diff": "^2.1.3",
2121
"chalk": "^1.1.1",
22-
"underscore": "^1.8.3"
22+
"underscore": "^1.8.3",
23+
"plist": "^1.1.0",
24+
"cson": "^3.0.2"
2325
}
2426
}

0 commit comments

Comments
 (0)