aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcmd/main.js46
-rw-r--r--lib/template.js7
2 files changed, 32 insertions, 21 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
diff --git a/lib/template.js b/lib/template.js
index ce05473..c1446a9 100644
--- a/lib/template.js
+++ b/lib/template.js
@@ -29,7 +29,10 @@ function fmt(words, maxLine, glue1, glue2) {
}
-function render(src, pkg) {
+function render({
+ src,
+ pkg
+}) {
const deps = pkg.dependencies || {};
const devDeps = pkg.devDependencies || {};
const npmInputs = Object.keys({...deps,
@@ -86,4 +89,4 @@ ${source}
`;
}
-module.exports = render;
+module.exports = render; \ No newline at end of file