aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2019-10-03 16:49:01 +0200
committerIgor Pashev <pashev.igor@gmail.com>2019-10-03 16:49:01 +0200
commiteb78615206a2210cb64675bba07f3f1d29f2796f (patch)
treeeed018f1b3369be6475433310da7f38a0e4e52c4
parent63bf277a01a4fd4df692bf319b6d6ef0dc2c0ec8 (diff)
downloadnpm.nix-eb78615206a2210cb64675bba07f3f1d29f2796f.tar.gz
Add get-index.js script
This script regenerates npmPackages/index.nix
-rwxr-xr-xgen-index.js48
-rw-r--r--npmPackages/index.nix1
2 files changed, 49 insertions, 0 deletions
diff --git a/gen-index.js b/gen-index.js
new file mode 100755
index 0000000..3024f7c
--- /dev/null
+++ b/gen-index.js
@@ -0,0 +1,48 @@
+#!/usr/bin/env node
+
+const fs = require('fs');
+const path = require('path');
+const process = require('process');
+
+var packages = {};
+
+function normalize(name) {
+ return name.replace('/', '-').replace('@', '').replace('.', '-');
+}
+
+function findPackages(dir) {
+ fs.readdirSync(dir).forEach(function(entry) {
+ const p = path.join(dir, entry);
+ const name = normalize(dir);
+ if (fs.lstatSync(p).isDirectory()) {
+ findPackages(p);
+ } else if (entry === 'default.nix' && dir !== '.') {
+ packages[name] = dir;
+ }
+ });
+}
+
+process.chdir(path.join(path.dirname(process.argv[1]), 'npmPackages'));
+findPackages('.');
+
+const names = Object.keys(packages).sort();
+
+const index = fs.createWriteStream('index.nix');
+index.once('open', (fd) => {
+ fs.writeSync(fd, '# XXX this file is automatically generated.\n');
+ fs.writeSync(fd, 'self: super:\n');
+ fs.writeSync(fd, 'let\n');
+ fs.writeSync(fd, ' inherit (super) callPackage;\n');
+ fs.writeSync(fd, 'in {\n');
+ for (var i = 0; i < names.length; i++) {
+ var path = packages[names[i]];
+ if (path[0] === '@') {
+ path = `(./. + "${path}")`;
+ } else {
+ path = `./${path}`;
+ }
+ fs.writeSync(fd, ` ${names[i]} = callPackage ${path} {};\n`);
+ }
+ fs.writeSync(fd, '}\n');
+ fs.closeSync(fd);
+});
diff --git a/npmPackages/index.nix b/npmPackages/index.nix
index 27880b5..6aeebb4 100644
--- a/npmPackages/index.nix
+++ b/npmPackages/index.nix
@@ -1,3 +1,4 @@
+# XXX this file is automatically generated.
self: super:
let
inherit (super) callPackage;