From eb78615206a2210cb64675bba07f3f1d29f2796f Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Thu, 3 Oct 2019 16:49:01 +0200 Subject: Add get-index.js script This script regenerates npmPackages/index.nix --- gen-index.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ npmPackages/index.nix | 1 + 2 files changed, 49 insertions(+) create mode 100755 gen-index.js 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; -- cgit v1.2.3