Permalink
Browse files

tweaks for NPM publishing

  • Loading branch information...
1 parent fe48484 commit 913949ffaebe8675add84fe8b72d38bd4e3f72b3 @cadorn cadorn committed Sep 30, 2011
Showing with 55 additions and 8 deletions.
  1. +6 −0 package.json
  2. +1 −8 programs/publish-to-npm/rsync-exclude.txt
  3. +2 −0 scripts/export.js
  4. +46 −0 scripts/postinstall.js
View
@@ -5,6 +5,7 @@
"label": "CommonJS Module Loader",
"description": "Versatile & Complete Cross-Platform CommonJS JavaScript Module, Package & Program Loader",
"homepage": "https://github.com/pinf/loader-js",
+ "author": "Christoph Dorn (http://www.christophdorn.com/) <christoph@christophdorn.com>",
"repositories": [
{
"type": "git",
@@ -24,10 +25,15 @@
"url": "http://www.opensource.org/licenses/mit-license.php"
}
],
+ "bin": {
+ "commonjs": "./pinf-loader.sh"
+ },
+ "main": "./pinf-loader.js",
"directories": {
"lib": "lib/pinf-loader-js"
},
"scripts": {
+ "postinstall": "node ./scripts/postinstall.js",
"export": {
"location": "./",
"module": "/scripts/export.js"
@@ -7,16 +7,9 @@ README.md
Thumbs.db
.build/
*.local.*
+.*.jsc
-/bin/
/demos/
/docs/
-/lib/pinf-loader-js/adapter/jetpack.js
-/lib/pinf-loader-js/adapter/narwhal.js
-/lib/pinf-loader-js/platform/jetpack/
/tests/
-/programs/
/NOTES.md
-/pinf-loader
-/pinf-loader.js
-/pinf-loader.sh
View
@@ -1,4 +1,6 @@
+// NOTE: Called via `commonjs --script export ...`
+
exports.main = function(env)
{
View
@@ -0,0 +1,46 @@
+
+// NOTE: Called via `npm run-script postinstall ...`
+
+var SYS = require("sys"),
+ PATH = require("path"),
+ FS = require("fs");
+
+/**
+ * Update the `../pinf-loader.sh` script to set an absolute `BASE_PATH`.
+ * This is necessary as the dynamic base path detection does not work because
+ * npm links the `commonjs` binary using a relative path.
+ */
+function main()
+{
+ try {
+
+ var basePath = process.cwd(),
+ scriptPath = basePath + "/pinf-loader.sh",
+ // TODO: Adjust this based on ENV var
+ baseSourcePath = "/pinf/workspaces/github.com/pinf/loader-js";
+
+ // If loader source found on local system we use that instead
+ // of the code shipped with the NPM package!
+ if (PATH.existsSync(baseSourcePath))
+ {
+ basePath = baseSourcePath;
+ SYS.print([
+ "-------",
+ " NOTE: Linked `commonjs` command to source at '" + basePath + "'!",
+ "-------"
+ ].join("\n") + "\n\n");
+ }
+
+ var scriptContent = "" + FS.readFileSync(scriptPath);
+
+ scriptContent = scriptContent.replace(/(\nBASE_PATH=).*(\n)/, "$1\"" + basePath + "\"$2");
+
+ FS.writeFileSync(scriptPath, scriptContent);
+
+ } catch(e) {
+ console.error("Fatal Error '" + e + "' updating `pinf-loader.sh` script!");
+ process.exit(1);
+ }
+}
+
+main();

0 comments on commit 913949f

Please sign in to comment.