diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2019-10-06 17:48:10 +0200 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2019-10-06 17:48:10 +0200 |
commit | 33f717e2de267fafd22b9af3745240cf7051043f (patch) | |
tree | 489977037e406e24ec13d98b695714485d17732d /cmd | |
parent | 443c70d90a5cd0e958a653ed8df3352c9aac06d9 (diff) | |
download | npm4nix-33f717e2de267fafd22b9af3745240cf7051043f.tar.gz |
Refactor by moving template render on top
Diffstat (limited to 'cmd')
-rwxr-xr-x | cmd/main.js | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/cmd/main.js b/cmd/main.js index 43059ad..5ee7314 100755 --- a/cmd/main.js +++ b/cmd/main.js @@ -82,15 +82,18 @@ function isLocal(p) { return fs.existsSync(p); } -function processLocal(p) { - console.log(render(p, readPackage(p))); +function localSrc(p) { + return { + pkg: readPackage(p), + src: p + }; } function isArchive(url) { return url.match(new RegExp('(https?://)?.+/[^/]+\.t(ar\.)?(gz|bz2|xz)', 'i')); } -function processArchive(url) { +function fetchurl(url) { const dir = mkdtemp(); const file = path.join(dir, path.basename(url)); var sha256, pkg; @@ -101,11 +104,14 @@ function processArchive(url) { } finally { rmTree(dir); } - console.log(render({ - fetch: 'fetchurl', - url: url, - sha256: sha256 - }, pkg)); + return { + pkg: pkg, + src: { + fetch: 'fetchurl', + url: url, + sha256: sha256 + } + }; } function isGit(url) { @@ -114,7 +120,7 @@ function isGit(url) { url.match(new RegExp('^git(\\+https)?://.+', 'i')); } -function processGit(url) { +function fetchgit(url) { const dir = mkdtemp(); var rev, sha256, pkg; try { @@ -129,12 +135,14 @@ function processGit(url) { } finally { rmTree(dir); } - console.log(render({ - fetch: 'fetchgit', - url: url, - rev: rev, - sha256: sha256 - }, pkg)); + return { + pkg: pkg, + src: { + fetch: 'fetchgit', + rev: rev, + sha256: sha256 + } + }; } @@ -162,12 +170,12 @@ if (url === null) { } if (isLocal(url)) { - processLocal(url); + console.log(render(localSrc(url))); } else if (isGit(url)) { - processGit(url); + console.log(render(fetchgit(url))); } else if (isArchive(url)) { - processArchive(url); + console.log(render(fetchurl(url))); } else { log(`unsupported URL: '${url}'`); process.exit(1); -} +}
\ No newline at end of file |