js2 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/js2/fs.rb +2 -4
- data/lib/js2/js2.js +20 -11
- metadata +1 -1
data/lib/js2/fs.rb
CHANGED
@@ -9,7 +9,6 @@ class JS2::FS
|
|
9
9
|
return Dir["#{lookup}/*.#{ext}"].collect { |f| File.expand_path(f) }.reject { |f| f.match(/^\./) }
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
12
|
def expandPath(file)
|
14
13
|
return File.expand_path(file)
|
15
14
|
end
|
@@ -27,9 +26,8 @@ class JS2::FS
|
|
27
26
|
end
|
28
27
|
|
29
28
|
|
30
|
-
def mkdir(
|
31
|
-
dir
|
32
|
-
FileUtils.mkdir(dir) unless File.directory?(dir)
|
29
|
+
def mkdir(dir)
|
30
|
+
FileUtils.mkdir(dir) unless File.exists?(dir)
|
33
31
|
end
|
34
32
|
|
35
33
|
def isFile(dir)
|
data/lib/js2/js2.js
CHANGED
@@ -1107,7 +1107,7 @@ JS2.Class.extend('Updater', {
|
|
1107
1107
|
|
1108
1108
|
|
1109
1109
|
JS2.Class.extend('Config', {
|
1110
|
-
"CLI_REGEX":/^-(r|i|f)(
|
1110
|
+
"CLI_REGEX":/^-(r|i|f)(=(\w+))$/,
|
1111
1111
|
"optsLookup":{
|
1112
1112
|
'n': 'non-recursive',
|
1113
1113
|
'i': 'interval',
|
@@ -1133,7 +1133,7 @@ JS2.Class.extend('Config', {
|
|
1133
1133
|
var opt = argv.shift();
|
1134
1134
|
var m = opt.match(this.CLI_REGEX);
|
1135
1135
|
if (m) {
|
1136
|
-
this[this.optsLookup[m[
|
1136
|
+
this[this.optsLookup[m[1]]] = m[3] || true;
|
1137
1137
|
} else if (! this.command) {
|
1138
1138
|
this.command = opt;
|
1139
1139
|
} else {
|
@@ -1142,21 +1142,22 @@ JS2.Class.extend('Config', {
|
|
1142
1142
|
}
|
1143
1143
|
}
|
1144
1144
|
|
1145
|
+
this.recursive = !this['non-recursive'];
|
1145
1146
|
this.interval = parseInt(this.interval);
|
1146
|
-
|
1147
1147
|
},
|
1148
1148
|
|
1149
1149
|
loadConfigFile:function (file) {
|
1150
1150
|
if (this.fs.isFile(file)) {
|
1151
1151
|
try {
|
1152
|
-
var config = JSON.parse(this.fs.read(file).replace(/\n
|
1152
|
+
var config = JSON.parse(this.fs.read(file).replace(/\n\r?/g, ''));
|
1153
1153
|
|
1154
|
-
this.format = config.format
|
1155
|
-
this.recursive = config['non-recursive'] ? false : this.recursive;
|
1154
|
+
this.format = config.format || this.format;
|
1156
1155
|
this.interval = config['interval'] ? config['interval'] : this.interval;
|
1157
1156
|
this.sourceDir = config['source-dir'] || this.sourceDir;
|
1158
1157
|
this.outDir = config['out-dir'] || this.outDir;
|
1159
1158
|
|
1159
|
+
this['non-recursive'] = config['non-recursive'];
|
1160
|
+
|
1160
1161
|
return true;
|
1161
1162
|
} catch(e) {
|
1162
1163
|
console.log(e.toString());
|
@@ -1193,6 +1194,12 @@ JS2.Class.extend('Commander', {
|
|
1193
1194
|
this.fs = JS2.fs;
|
1194
1195
|
this.config = new JS2.Config(this.fs, argv);
|
1195
1196
|
this.command = this.config.command;
|
1197
|
+
|
1198
|
+
switch(this.config.format) {
|
1199
|
+
case 'ringo': JS2.DECORATOR = new JS2.RingoDecorator(); break;
|
1200
|
+
case 'node': JS2.DECORATOR = new JS2.NodeDecorator(); break;
|
1201
|
+
default: JS2.DECORATOR = new JS2.BrowserDecorator(); break;
|
1202
|
+
}
|
1196
1203
|
},
|
1197
1204
|
|
1198
1205
|
cli:function () {
|
@@ -1221,7 +1228,7 @@ JS2.Class.extend('Commander', {
|
|
1221
1228
|
},
|
1222
1229
|
|
1223
1230
|
getUpdater:function () {
|
1224
|
-
var inDir = this.config.args[0] || this.config.
|
1231
|
+
var inDir = this.config.args[0] || this.config.sourceDir || '.';
|
1225
1232
|
var outDir = this.config.args[1] || this.config.outDir || inDir;
|
1226
1233
|
return new JS2.Updater(this.fs, inDir, outDir, this.config.recursive);
|
1227
1234
|
},
|
@@ -1245,7 +1252,7 @@ JS2.Class.extend('Commander', {
|
|
1245
1252
|
|
1246
1253
|
|
1247
1254
|
|
1248
|
-
JS2.Class.extend('
|
1255
|
+
JS2.Class.extend('BrowserDecorator', {
|
1249
1256
|
file:function (code) {
|
1250
1257
|
return code;
|
1251
1258
|
},
|
@@ -1255,7 +1262,7 @@ JS2.Class.extend('Decorator.Browser', {
|
|
1255
1262
|
}
|
1256
1263
|
});
|
1257
1264
|
|
1258
|
-
JS2.Class.extend('
|
1265
|
+
JS2.Class.extend('NodeDecorator', {
|
1259
1266
|
file:function (code) {
|
1260
1267
|
return "var js2 = require('js2').js2;\nvar JS2 = js2;\n" + code;
|
1261
1268
|
},
|
@@ -1265,7 +1272,7 @@ JS2.Class.extend('Decorator.Node', {
|
|
1265
1272
|
}
|
1266
1273
|
});
|
1267
1274
|
|
1268
|
-
JS2.Class.extend('
|
1275
|
+
JS2.Class.extend('RingoDecorator', {
|
1269
1276
|
file:function (code) {
|
1270
1277
|
return "var js2 = require('js2').js2;\nvar JS2 = js2;\n" + code;
|
1271
1278
|
},
|
@@ -1275,10 +1282,12 @@ JS2.Class.extend('Decorator.Ringo', {
|
|
1275
1282
|
}
|
1276
1283
|
});
|
1277
1284
|
|
1285
|
+
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
|
1286
|
+
|
1278
1287
|
|
1279
1288
|
|
1280
1289
|
JS2.fs = new JS2.FileSystem(JS2_RUBY_FILE_ADAPTER);
|
1281
|
-
js2.DECORATOR = new JS2.
|
1290
|
+
js2.DECORATOR = new JS2.BrowserDecorator();
|
1282
1291
|
js2.ROOT = root;
|
1283
1292
|
|
1284
1293
|
return JS2;
|