Skip to content

Commit

Permalink
Merge pull request #25 from robcresswell/fix/correctly-support-shorth…
Browse files Browse the repository at this point in the history
…and-urls

fix: Correctly support shorthand URLs
  • Loading branch information
robcresswell authored Jun 25, 2019
2 parents 3d73a15 + d8d6e5e commit c125235
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 388 deletions.
9 changes: 6 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ jobs:
test:
working_directory: ~/dems
docker:
- image: node:12-stretch-slim
- image: node:12-alpine
steps:
- run:
name: Install certificate handling for artifact uploading
command: apk --update add ca-certificates git
- checkout
- run:
name: Install fixed dependencies from lockfile
Expand All @@ -22,11 +25,11 @@ jobs:
release:
working_directory: ~/dems
docker:
- image: node:12-stretch-slim
- image: node:12-alpine
steps:
- checkout
- run:
command: apt update && apt install -y git
command: apk --update add git
- run: yarn --frozen-lockfile
- run: yarn build
- run: npx semantic-release
Expand Down
201 changes: 0 additions & 201 deletions LICENSE.md

This file was deleted.

64 changes: 0 additions & 64 deletions README.md

This file was deleted.

5 changes: 1 addition & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ export async function cli(

try {
const { resolvedDest, archiveUrl } = await getValidConfig(...args);

// TODO: Clean up this side-effect nightmare
const templateVariables: Set<string> = new Set();
await downloadRepo(archiveUrl, resolvedDest, templateVariables);
const templateVariables = await downloadRepo(archiveUrl, resolvedDest);

if (templateVariables.size > 0) {
const variables: { [key: string]: string } = {};
Expand Down
13 changes: 6 additions & 7 deletions src/download-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ function getMapStream(templateVariables: Set<string>) {
export async function downloadRepo(
archiveUrl: string,
dest: string,
templateVariables: Set<string>,
) {
): Promise<Set<string>> {
return new Promise((resolve, reject) => {
// TODO: Clean up this side-effect nightmare
const templateVariables: Set<string> = new Set();

// eslint-disable-next-line consistent-return
get(archiveUrl, (response) => {
if (!response.statusCode || response.statusCode >= 400) {
Expand All @@ -57,10 +59,7 @@ export async function downloadRepo(
);
}

downloadRepo(redirectUrl, dest, templateVariables).then(
resolve,
reject,
);
downloadRepo(redirectUrl, dest).then(resolve, reject);
} else {
const mapStream = getMapStream(templateVariables);
response
Expand All @@ -71,7 +70,7 @@ export async function downloadRepo(
mapStream,
}),
)
.on('finish', resolve)
.on('finish', () => resolve(templateVariables))
.on('error', reject);
}
});
Expand Down
18 changes: 12 additions & 6 deletions src/get-scm-info.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { InvalidSourceError } from './errors';
import { SCMType } from './types';

export function getScmInfo(url: string): { type: SCMType; repo: string } {
const repoUrlMap = {
github: (repo: string) => `https://github.com/${repo}`,
gitlab: (repo: string) => `https://gitlab.com/${repo}`,
bitbucket: (repo: string) => `https://bitbucket.org/${repo}`,
};

export function getScmInfo(descriptor: string): { type: SCMType; url: string } {
const pattern = /(?:https:\/\/|git@)?(github|bitbucket|gitlab)?(?::)?(?:\.org|\.com)?(?:\/|:)?([\w-]+\/[\w-]+)(?:\.git)?/;
const match = url.match(pattern);
const match = descriptor.match(pattern);

if (!match) {
throw new InvalidSourceError();
}

return {
type: (match[1] || 'github') as SCMType,
repo: match[2],
};
const type = (match[1] || 'github') as SCMType;
const url = repoUrlMap[type](match[2]);

return { type, url };
}
Loading

0 comments on commit c125235

Please sign in to comment.