Permalink
Browse files

resolve path include space in windows

  • Loading branch information...
1 parent 7361b02 commit 947705a652aac9bb67745c0ed4f36cd8a2399066 @switer committed Jan 21, 2013
Showing with 14 additions and 13 deletions.
  1. +4 −4 bin/doverjs
  2. +1 −1 lib/coverhtml.js
  3. +3 −3 package.json
  4. +6 −5 phantomrun.js
View
8 bin/doverjs
@@ -1,7 +1,7 @@
#!/usr/bin/env node
var program = require('commander'),
chiProc = require('child_process'),
- currentPath = process.cwd(),
+ currentPath = encodeURIComponent(process.cwd()),
NOTICE_MSG = 'Runing...Covering will takes a few time, Please wait a monment',
cmd;
@@ -15,17 +15,17 @@ program
.parse(process.argv);
process.chdir(__dirname + '/../');
-var outputFile = program.output || '';
+var outputFile = encodeURIComponent(program.output) || '';
if (program.json) {
- cmd = "node phantomrun.js json '" + currentPath + "' " + program.json + ' ' + outputFile
+ cmd = "node phantomrun.js json '" + currentPath + "' " + encodeURIComponent(program.json) + ' ' + outputFile
console.log(NOTICE_MSG);
chiProc.exec(cmd, function (e, std, ste) {
e && console.log( e );
console.log( std );
console.log( ste );
});
} else if (program.style && program.destination) {
- cmd = "node phantomrun.js source '" + currentPath + "' " + program.style + ' ' + program.destination + ' ' + outputFile;
+ cmd = "node phantomrun.js source '" + currentPath + "' " + encodeURIComponent(program.style) + ' ' + encodeURIComponent(program.destination) + ' ' + outputFile;
console.log(NOTICE_MSG);
chiProc.exec(cmd, function (e, std, ste) {
e && console.log( e );
View
2 lib/coverhtml.js
@@ -7,7 +7,7 @@ var args = require('system').args,
SELECTOR_TEMP_FILE = 'doverjs_temp_file';
fs = require('fs');
count = 0;
-var cwd = args[args.length - 1],
+var cwd = decodeURIComponent(args[args.length - 1]),
styleString = fs.read(cwd + SELECTOR_TEMP_FILE),
//TODO <encode:uri{encode:sel1,encode:sel2,...]encode:uri{encode:sel1,...>
styleRuleSet = styleString.split(',');
View
6 package.json
@@ -1,9 +1,9 @@
{
"name": "doverjs",
- "version": "0.1.0",
+ "version": "0.1.2",
"private": false,
"scripts": {
- "start": "node phantomrun"
+ "start": "node ./bin/doverjs"
},
"directories": {
"bin": "bin"
@@ -20,5 +20,5 @@
"doverjs": "bin/doverjs"
},
"readmeFilename": "README.md",
- "description": "DoverJS No Deadweight"
+ "description": "DoverJS--Find unused seletor from your style-sheet to DHTML URI"
}
View
11 phantomrun.js
@@ -14,7 +14,7 @@ var HTML_TEMP_URI = 'http://localhost:3013/temp/',
var args = process.argv.slice(2),
optionType = args.shift(),
- localPath = args.shift().replace(/^\'/,'').replace(/\'$/,''),
+ localPath = decodeURIComponent(args.shift()).replace(/^\'/,'').replace(/\'$/,''),
params;
var REGEXES = {
@@ -27,7 +27,7 @@ this.config = {
}
}
if (optionType === this.config.OPTION_TYPE.JSON) {
- var packageJsName = args.shift()
+ var packageJsName = decodeURIComponent(args.shift())
try {
var params = JSON.parse(_readPackgeFile(localPath + '\\' + packageJsName));
params.html = _populateLocalURL(_readHTMLPropertiesAsArray(params.html), localPath, true)
@@ -40,12 +40,13 @@ if (optionType === this.config.OPTION_TYPE.JSON) {
} else if (optionType === this.config.OPTION_TYPE.SOURCE) {
params = {}
- var cssParams = args.shift().split(','),
- htmlParams = args.shift().split(',');
+ var cssParams = decodeURIComponent(args.shift()).split(','),
+ htmlParams = decodeURIComponent(args.shift()).split(',');
params.html = _populateLocalURL(htmlParams, localPath, true)
params.style = _populateLocalURL(cssParams, localPath)
}
var outputFile = args.shift();
+outputFile && (outputFile = decodeURIComponent(outputFile));
process.chdir(__dirname);
var that = this;
@@ -147,7 +148,7 @@ function _captureHTMLWhithArray (htmls, styles, callback) {
var styleRules = styles[s];
//@param <html1 html2 ...> TODO<encode:uri{encode:sel1,encode:sel2,...]encode:uri{encode:sel1,...>
fs.writeFileSync(localPath + '/' + SELECTOR_TEMP_FILE, parser.parse(styleRules["content"], true).join(','), 'UTF-8');
- cmd = 'phantomjs ' + CAPTURE_HTML_SCRIPT + ' ' + htmls.join(' ') + ' ' + localPath + '/';
+ cmd = 'phantomjs ' + CAPTURE_HTML_SCRIPT + ' ' + htmls.join(' ') + ' ' + encodeURIComponent(localPath + '/');
cp.exec(cmd, function (err, stdout,stderr) {
err && console.log(err);
console.log(stderr);

0 comments on commit 947705a

Please sign in to comment.