diff --git a/node_modules/architect-build/compress.js b/node_modules/architect-build/compress.js index f4e52eaa..343f5d70 100644 --- a/node_modules/architect-build/compress.js +++ b/node_modules/architect-build/compress.js @@ -17,7 +17,7 @@ function compress(sources, opts) { if (pkg.file) console.log("Adding '" + pkg.file + "'."); toplevel = UglifyJS.parse(pkg.source, { - filename: pkg.file.replace(new RegExp("^" + opts.basepath + "/"), ""), //@todo remove prefix + filename: (pkg.file || pkg.id).replace(new RegExp("^" + opts.basepath + "/"), ""), //@todo remove prefix toplevel: toplevel }); }); diff --git a/plugins/c9.cli.publish/publish.git.sh b/plugins/c9.cli.publish/publish.git.sh index f1208cb4..bf32c8d7 100644 --- a/plugins/c9.cli.publish/publish.git.sh +++ b/plugins/c9.cli.publish/publish.git.sh @@ -1,13 +1,13 @@ -PACKAGE_PATH=$1 -VERSION=$2 -CWD=${PWD} +VERSION="$1" +PACKAGE_PATH="$2" +CWD="${PWD}" if [ ! -d .git ]; then echo "$CWD is not a git repository" 1>&2 exit 1 fi -if [ ! -e $PACKAGE_PATH ]; then +if [ ! -f "$PACKAGE_PATH" ]; then echo "Could not find package.json" 1>&2 exit 1 fi diff --git a/plugins/c9.cli.publish/publish.js b/plugins/c9.cli.publish/publish.js index 245b78a6..757cdc60 100644 --- a/plugins/c9.cli.publish/publish.js +++ b/plugins/c9.cli.publish/publish.js @@ -43,6 +43,7 @@ define(function(require, exports, module) { var verbose = false; var force = false; var dryRun = false; + var createTag = false; // Set up basic auth for api if needed if (BASICAUTH) api.basicAuth = BASICAUTH; @@ -78,16 +79,23 @@ define(function(require, exports, module) { "description": "Only build a test version", "default": false, "boolean": true + }, + "tag" : { + "description": "Create git tag for published version", + "alias": "t", + "default": false, + "boolean": true } }, check: function(argv) { - if (argv._.length < 2 && !argv["newversion"] && !argv["dry-run"]) - throw new Error("Missing version"); + // if (argv._.length < 2 && !argv["newversion"] && !argv["dry-run"]) + // throw new Error("Missing version"); }, exec: function(argv) { verbose = argv["verbose"]; force = argv["force"]; dryRun = argv["dry-run"]; + createTag = argv["tag"]; publish( argv._[1], @@ -108,7 +116,7 @@ define(function(require, exports, module) { } }); - cmd.addCommand({ + cmd.addCommand({ name: "build", info: " Builds development version of package to load in non-debug mode.", usage: "[--devel]", @@ -372,7 +380,7 @@ define(function(require, exports, module) { var version = options.version; var cwd = process.cwd(); var packagePath = cwd + "/package.json"; - fs.readFile(packagePath, function(err, data){ + fs.readFile(packagePath, "utf8", function(err, data){ if (err) return callback(new Error("ERROR: Could not find package.json in " + cwd)); var json; @@ -437,7 +445,7 @@ define(function(require, exports, module) { if (warned && !force && !dryRun) return callback(new Error("Use --force to ignore these warnings.")); - if (!dryRun) { + if (version) { var v = (json.version || "0.0.1").split("."); // Update the version field in the package.json file if (version == "major") { @@ -458,48 +466,16 @@ define(function(require, exports, module) { json.version = v.join("."); } - if (dryRun) + if (!version) return build(); // Write the package.json file - fs.writeFile(packagePath, JSON.stringify(json, null, " "), function(err){ + var indent = data.match(/{\n\r?^ {4}"/) ? 4 : 2; + fs.writeFile(packagePath, JSON.stringify(json, null, indent), function(err){ if (err) return callback(err); - - if (dryRun) return build(); - - commit(); + return build(); }); - function commit() { - SHELLSCRIPT = SHELLSCRIPT - .replace(/\$1/, packagePath) - .replace(/\$2/, json.version); - - proc.spawn("bash", { - args: ["-c", SHELLSCRIPT] - }, function(err, p){ - if (err) return callback(err); - - if (verbose) { - p.stdout.on("data", function(c){ - process.stdout.write(c.toString("utf8")); - }); - p.stderr.on("data", function(c){ - process.stderr.write(c.toString("utf8")); - }); - } - - p.on("exit", function(code, stderr, stdout){ - if (code !== 0) - return callback(new Error("ERROR: publish failed with exit code " + code)); - - console.log("Created tag and updated package.json to version", json.version); - - build(); - }); - }); - } - // Build the package // @TODO add a .c9exclude file that excludes files var zipFilePath; @@ -862,7 +838,7 @@ define(function(require, exports, module) { return callback(new Error("ERROR: Failed to update existing package - " + stringifyError(err))); if (verbose) - console.log("Successfully updated existing package"); + console.log("Successfully updated metadata of existing package"); next(pkg); }); @@ -897,15 +873,47 @@ define(function(require, exports, module) { form.pipe(request); request.on('response', function(res) { + // TODO better handle version exists error + if (res.statusCode == 412 && !version) + console.error("ERROR: most likely version " + json.version + " already exisits, try increasing version"); if (res.statusCode != 200) return callback(new Error("ERROR: Unknown Error:" + res.statusCode)); - // Create Version Complete - callback(null, json); + commitAndPush(); }); } }); } + + function commitAndPush() { + // Create Version Complete + if (!createTag) + callback(null, json); + + proc.spawn("bash", { + args: ["-c", SHELLSCRIPT, "--", json.version, normalizePath(packagePath)] + }, function(err, p){ + if (err) return callback(err); + + if (verbose) { + p.stdout.on("data", function(c){ + process.stdout.write(c.toString("utf8")); + }); + p.stderr.on("data", function(c){ + process.stderr.write(c.toString("utf8")); + }); + } + + p.on("exit", function(code, stderr, stdout){ + if (code !== 0) + return callback(new Error("ERROR: publish failed with exit code " + code)); + + console.log("Created tag and updated package.json to version", json.version); + + callback(null, json); + }); + }); + } }); }