Skip to content

Instantly share code, notes, and snippets.

/path.diff Secret

Created February 3, 2014 22:23
Show Gist options
  • Save anonymous/f9f7e996dd74c525d1b0 to your computer and use it in GitHub Desktop.
Save anonymous/f9f7e996dd74c525d1b0 to your computer and use it in GitHub Desktop.
commit 0544880648583163eaf64652b66bdcbe076afe37
Author: Stuart Knightley <stuart@stuartk.com>
Date: Mon Feb 3 14:21:03 2014 -0800
Small fixes for Mop. Needs tidying
diff --git a/optimize.js b/optimize.js
index 6dbb867..5f7c142 100755
--- a/optimize.js
+++ b/optimize.js
@@ -6,6 +6,7 @@ All Rights Reserved.
</copyright> */
var URL = require("url2");
+var Path = require("path");
var build = require("./lib/build");
var spinner = require("./lib/spinner");
@@ -38,11 +39,13 @@ module.exports = optimize;
function optimize(location, config) {
config = config || {};
+ // console.log("before format", location)
location = URL.format({
protocol: "file:",
slashes: true,
pathname: directory(location)
- });
+ }).replace(/\\/g, "/");
+ console.log("after format", location)
if (config.out) {
// Fill in any missing output functions
@@ -60,13 +63,19 @@ function optimize(location, config) {
// mainly here so that fs can be mocked out for testing
var fs = config.fs || require("q-io/fs");
function read(location) {
+ console.log("read location", location, new Error().stack)
var path = URL.parse(location).pathname;
+ console.log("read path", path);
+ if (fs.SEPARATOR !== "/") {
+
+ }
return fs.read(path);
}
-
+ console.log("buildLocation", URL.resolve(location, (config.buildLocation || "builds") + "/"))
+ // return { done: noop };
return build(location, {
// configurable
- buildLocation: URL.resolve(location, directory(config.buildLocation || "builds")),
+ buildLocation: URL.resolve(location, (config.buildLocation || "builds") + "/"),
minify: config.minify !== void 0 ? !!config.minify : true,
lint: config.lint !== void 0 ? !!config.lint : false,
noCss: config.noCss !== void 0 ? !!config.noCss : false,
@@ -82,12 +91,12 @@ function optimize(location, config) {
});
// Once implemented but currently disabled options:
- //incremental: true,
- //bundle: !!bundle,
- //copyright: !!copyright,
- //shared: !!shared,
- //manifest: !!manifest,
- //force: !!force,
+ // incremental: true,
+ // bundle: !!bundle,
+ // copyright: !!copyright,
+ // shared: !!shared,
+ // manifest: !!manifest,
+ // force: !!force,
}
function usage() {
@@ -110,15 +119,16 @@ function version() {
console.log(config.title + " version " + config.version);
}
+var DIRECTORY_RE = new RegExp("\\" + Path.sep + "$");
function directory(path) {
if (path.length) {
- if (/\/$/.test(path)) {
+ if (DIRECTORY_RE.test(path)) {
return path;
} else {
- return path + "/";
+ return path + Path.sep;
}
} else {
- return "./";
+ return "." + Path.sep;
}
}
@@ -159,7 +169,7 @@ function main() {
var location = argv._.length ? argv._[0] : ".";
// convert path to locations
- location = URL.resolve(directory(process.cwd()), directory(location));
+ location = directory(Path.resolve(directory(process.cwd()), directory(location)));
optimize(location, {
buildLocation: argv.t || argv.target,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment