Skip to content

Commit

Permalink
refactor: removed constants module (most of these were unused) and un…
Browse files Browse the repository at this point in the history
…used composeUrl method
  • Loading branch information
grob committed Sep 25, 2021
1 parent 09611c3 commit 2c03100
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 36 deletions.
5 changes: 2 additions & 3 deletions tools/admin/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const term = require("ringo/term");
const {Parser} = require("ringo/args");
const fs = require("fs");

const constants = require("../constants");
const packages = require("../utils/packages");
const specs = require("../utils/specs");
const files = require("../utils/files");
Expand Down Expand Up @@ -124,9 +123,9 @@ const installPackage = exports.installPackage = (url, packagesDirectory, options
}
const spec = specs.get(url);
switch (spec.type) {
case constants.TYPE_ARCHIVE:
case specs.TYPE_ARCHIVE:
return installArchive(spec, packagesDirectory, options);
case constants.TYPE_GIT:
case specs.TYPE_GIT:
return installGit(spec, packagesDirectory, options);
default:
throw new Error("Unknown spec type '" + spec.type + "'");
Expand Down
9 changes: 0 additions & 9 deletions tools/admin/constants.js

This file was deleted.

13 changes: 6 additions & 7 deletions tools/admin/test/specs_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const system = require("system");
const assert = require("assert");
const specs = require("../utils/specs");
const constants = require("../constants");

const {URI} = java.net;

Expand Down Expand Up @@ -90,7 +89,7 @@ exports.testNewGitHubSpec = () => {
if (!url.includes("github.com")) {
url = "https://github.com/" + url;
}
assert.strictEqual(spec.type, constants.TYPE_GIT, uri);
assert.strictEqual(spec.type, specs.TYPE_GIT, uri);
assert.strictEqual(spec.url, url, uri);
assert.strictEqual(spec.treeish, treeish || null, uri);
});
Expand Down Expand Up @@ -118,7 +117,7 @@ exports.testNewGitSpec = () => {
const treeish = gitUrl.split("#")[1] || null;
const receivedUri = URI.create(spec.url);
const expectedUri = URI.create(gitUrl);
assert.strictEqual(spec.type, constants.TYPE_GIT, gitUrl);
assert.strictEqual(spec.type, specs.TYPE_GIT, gitUrl);
assert.strictEqual(receivedUri.getScheme(), scheme.expected, gitUrl);
assert.strictEqual(receivedUri.getSchemeSpecificPart(), expectedUri.getSchemeSpecificPart(), gitUrl);
assert.strictEqual(spec.treeish, expectedUri.getFragment(), gitUrl);
Expand All @@ -139,17 +138,17 @@ exports.testNewArchiveSpec = () => {
uris.map(part => [scheme, part].join("://"))
.forEach(url => {
const spec = specs.newArchiveSpec(url);
assert.strictEqual(spec.type, constants.TYPE_ARCHIVE, url);
assert.strictEqual(spec.type, specs.TYPE_ARCHIVE, url);
assert.strictEqual(spec.url, url, url);
});
});
};

exports.testGet = () => {
const tests = [
{urls: GIT_URLS.positive, type: constants.TYPE_GIT},
{urls: GITHUB_URLS.positive, type: constants.TYPE_GIT},
{urls: ARCHIVE_URLS.positive, type: constants.TYPE_ARCHIVE}
{urls: GIT_URLS.positive, type: specs.TYPE_GIT},
{urls: GITHUB_URLS.positive, type: specs.TYPE_GIT},
{urls: ARCHIVE_URLS.positive, type: specs.TYPE_ARCHIVE}
];
const test = (test) => {
test.urls.forEach(url => assert.strictEqual(specs.get(url).type, test.type, url));
Expand Down
13 changes: 0 additions & 13 deletions tools/admin/utils/httpclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ const log = require("ringo/logging").getLogger(module.id);
const files = require("ringo/utils/files");
const {request} = require("ringo/httpclient");

const RE_SLASH_LEADING = /^\//;
const RE_SLASH_TRAILING = /\/$/;

exports.getBinary = (url) => {
log.debug("GET (binary)", url);
const exchange = request({
Expand All @@ -22,13 +19,3 @@ exports.getBinary = (url) => {
return tmpFile;
};

exports.composeUrl = function() {
return Array.prototype.map.call(arguments, (val, idx, arr) => {
val = val.replace(RE_SLASH_LEADING, "");
if (idx < arr.length -1) {
val = val.replace(RE_SLASH_TRAILING, "");
}
return val;
}).join("/");
};

10 changes: 6 additions & 4 deletions tools/admin/utils/specs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const {URI} = java.net;
const constants = require("../constants");

const GIT_SCHEMES = {
"git+ssh": "ssh",
Expand All @@ -8,6 +7,9 @@ const GIT_SCHEMES = {
"git+file": "file"
};

const TYPE_GIT = exports.TYPE_GIT = "git";
const TYPE_ARCHIVE = exports.TYPE_ARCHIVE = "archive";

exports.isValidUrl = (url) => {
try {
URI.create(url);
Expand Down Expand Up @@ -56,7 +58,7 @@ const newGitHubSpec = exports.newGitHubSpec = (url) => {
url = [uri.getScheme(), uri.getSchemeSpecificPart()].join(":");
}
return {
type: constants.TYPE_GIT,
type: TYPE_GIT,
url: url,
treeish: treeish
};
Expand All @@ -69,15 +71,15 @@ const newGitSpec = exports.newGitSpec = (url) => {
const uriString = (scheme + ":" + uri.getSchemeSpecificPart()).toString();
const treeish = uri.getFragment();
return {
type: constants.TYPE_GIT,
type: TYPE_GIT,
url: uriString,
treeish: treeish
};
};

const newArchiveSpec = exports.newArchiveSpec = (url) => {
return {
type: constants.TYPE_ARCHIVE,
type: TYPE_ARCHIVE,
url: url
};
};
Expand Down

0 comments on commit 2c03100

Please sign in to comment.