@adinsure-ops/ops-cli
Version:
Operations CLI for working with AdInsure
85 lines (84 loc) • 3.5 kB
JavaScript
import { __awaiter } from "tslib";
import { Flags, ux } from '@oclif/core';
import chalk from 'chalk';
import CommandBase from '../../command.base.js';
import NpmContext from '../../lib/npm.js';
class NpmCheckPublish extends CommandBase {
checkPackagesExists(packages, allPackages, version) {
return __awaiter(this, void 0, void 0, function* () {
let errorCount = 0;
for (const pkg of packages) {
ux.action.start(`${pkg.name}@${version}`, undefined, { stdout: true });
const matchedPackage = allPackages.value.find(azurePackage => azurePackage.name === pkg.name);
if (!matchedPackage) {
ux.action.stop(`${chalk.red('package missing')}`);
errorCount++;
continue;
}
const matchVersion = matchedPackage.versions.find(azurePackageVersion => azurePackageVersion.version === version);
if (!matchVersion) {
ux.action.stop(`${chalk.red('version missing')}`);
errorCount++;
continue;
}
ux.action.stop(`${chalk.green('exists')}`);
}
if (errorCount > 0) {
throw new Error(`${errorCount} packages or versions missing!`);
}
});
}
run() {
const _super = Object.create(null, {
run: { get: () => super.run }
});
return __awaiter(this, void 0, void 0, function* () {
_super.run.call(this);
try {
const { flags } = (yield this.parse(NpmCheckPublish)).flags;
const npmContext = new NpmContext();
ux.action.start('Parsing packages to check', undefined, { stdout: true });
const packages = yield npmContext.packageList(this, flags.package, flags.exclude);
ux.action.stop(`${chalk.green('done')}`);
ux.action.start('Getting list of available packages', undefined, { stdout: true });
const allPackages = (yield npmContext.getAllNpmPackages(flags.pat)).data;
ux.action.stop(`${chalk.green('done')}`);
yield this.checkPackagesExists(packages, allPackages, flags.version);
ux.action.stop('success');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}
catch (error) {
ux.action.stop('error');
this.error(`${error.message}`);
}
});
}
}
NpmCheckPublish.description = 'check if npm packages were published';
NpmCheckPublish.usage = 'npm:check-publish [options]';
NpmCheckPublish.examples = [
'$ ops npm:check-publish -v 6.0.1',
'$ ops npm:check-publish -p @adinsure/* -v 6.0.0',
'$ ops npm:check-publish -p @adinsure/* -x @adisure/demo -v 6.0.0',
];
NpmCheckPublish.flags = {
package: Flags.string({
char: 'p',
description: 'package name filter you want to check',
multiple: true,
}),
exclude: Flags.string({
char: 'x',
description: 'exclude packages from filter',
multiple: true,
}),
version: Flags.string({
char: 'v',
description: 'version we want to check if published',
required: true,
}),
pat: Flags.string({
description: 'PAT token or AZURE_DEVOPS_EXT_PAT environment variable',
}),
};
export default NpmCheckPublish;