Skip to content

Commit

Permalink
Merge pull request #6 from sesamecare/djmax/access
Browse files Browse the repository at this point in the history
feat(force): allow forced publish, most useful with limit
  • Loading branch information
djMax authored Jun 23, 2023
2 parents 12fe322 + 719292b commit ce6e473
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface Argv {
'to-password'?: string;
_: string[];
verbose?: boolean;
force?: boolean;
limit?: number;
}

Expand All @@ -22,7 +23,7 @@ function usage() {

export async function cli(argvSliced: string[]) {
const argv = minimist<Argv>(argvSliced, {
boolean: ['verbose'],
boolean: ['verbose', 'force'],
});
const from = {
url: argv.from,
Expand All @@ -44,6 +45,7 @@ export async function cli(argvSliced: string[]) {
const opts = {
verbose: argv.verbose || false,
limit: argv.limit,
force: argv.force,
};

// Run in series so the logs are more intelligible
Expand Down
15 changes: 10 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ export async function getVersionInfo(registry: string, auth: Partial<AuthOptions
registry,
forceAuth: auth,
});
const versions = Object.entries(response.time as Record<string, unknown>).sort(([, timeA], [, timeB]) => {
return Date.parse(timeA as string) - Date.parse(timeB as string);
}).map(([key]) => key);
const versions = Object
.entries(response.time as Record<string, unknown>)
.filter(([vspec]) => !['created', 'modified'].includes(vspec))
.sort(([, timeA], [, timeB]) => {
return Date.parse(timeA as string) - Date.parse(timeB as string);
})
.map(([key]) => key);
return {
versions,
response,
Expand All @@ -43,12 +47,13 @@ export async function syncVersion(from: RepoSpec, to: RepoSpec, fromInfo: Versio
});
}

export async function copyModule({ from, to, module, verbose, limit }: {
export async function copyModule({ force, from, to, module, verbose, limit }: {
from: RepoSpec;
to: RepoSpec;
module: string;
verbose?: boolean;
limit?: number;
force?: boolean;
}) {
const { url: fromUrl, ...fromAuth } = from;
const { url: toUrl, ...toAuth } = to;
Expand All @@ -61,7 +66,7 @@ export async function copyModule({ from, to, module, verbose, limit }: {
throw error;
});
const fromVersions = limit ? fromInfo.versions.slice(-limit) : fromInfo.versions;
const toPublish = diff(fromVersions, toInfo.versions);
const toPublish = diff(fromVersions, force ? [] : toInfo.versions);

if (toPublish.length === 0) {
(verbose ? console.log : debug)('No new versions of %s to publish', module);
Expand Down

0 comments on commit ce6e473

Please sign in to comment.