@ionic/cli-utils
Version:
Ionic CLI Utils
271 lines (270 loc) • 8.8 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.INTEGRATION_NAMES = ['capacitor', 'cordova'];
function isCommand(c) {
const cmd = c;
return cmd && typeof cmd.run === 'function';
}
exports.isCommand = isCommand;
function isCommandPreRun(c) {
const cmd = c;
return cmd && typeof cmd.preRun === 'function';
}
exports.isCommandPreRun = isCommandPreRun;
function isStarterManifest(o) {
const obj = o;
return obj &&
typeof obj.name === 'string' &&
typeof obj.baseref === 'string';
}
exports.isStarterManifest = isStarterManifest;
function isCordovaPackageJson(o) {
const obj = o;
return obj &&
typeof obj.name === 'string' &&
typeof obj.cordova === 'object' &&
typeof obj.cordova.platforms === 'object' &&
typeof obj.cordova.plugins === 'object';
}
exports.isCordovaPackageJson = isCordovaPackageJson;
function isExitCodeException(e) {
const err = e;
return err && typeof err.exitCode === 'number' && err.exitCode >= 0 && err.exitCode <= 255;
}
exports.isExitCodeException = isExitCodeException;
function isSuperAgentError(e) {
const err = e;
return e && err.response && typeof err.response === 'object';
}
exports.isSuperAgentError = isSuperAgentError;
function isAPIResponseSuccess(r) {
const res = r;
return res && (typeof res.data === 'object' || typeof res.data === 'string');
}
exports.isAPIResponseSuccess = isAPIResponseSuccess;
function isAPIResponseError(r) {
const res = r;
return res && typeof res.error === 'object';
}
exports.isAPIResponseError = isAPIResponseError;
function isOrg(o) {
const org = o;
return org && typeof org.name === 'string';
}
exports.isOrg = isOrg;
function isGithubRepo(r) {
const repo = r;
return repo
&& typeof repo.full_name === 'string'
&& typeof repo.id === 'number';
}
exports.isGithubRepo = isGithubRepo;
function isGithubBranch(r) {
const branch = r;
return branch
&& typeof branch.name === 'string';
}
exports.isGithubBranch = isGithubBranch;
function isGithubRepoListResponse(r) {
if (!isAPIResponseSuccess(r) || !Array.isArray(r.data)) {
return false;
}
if (r.data.length === 0) {
return true;
}
return typeof r.data[0] === 'object' && isGithubRepo(r.data[0]);
}
exports.isGithubRepoListResponse = isGithubRepoListResponse;
function isGithubBranchListResponse(r) {
if (!isAPIResponseSuccess(r) || !Array.isArray(r.data)) {
return false;
}
if (r.data.length === 0) {
return true;
}
return typeof r.data[0] === 'object' && isGithubBranch(r.data[0]);
}
exports.isGithubBranchListResponse = isGithubBranchListResponse;
function isAppAssociation(a) {
const association = a;
return (association &&
typeof association.repository === 'object' &&
typeof association.repository.html_url === 'string' &&
(isGithubRepoAssociation(association.repository) ||
isBitbucketCloudRepoAssociation(association.repository) ||
isBitbucketServerRepoAssociation(association.repository)));
}
exports.isAppAssociation = isAppAssociation;
function isAppAssociationResponse(r) {
return isAPIResponseSuccess(r)
&& typeof r.data === 'object'
&& isAppAssociation(r.data);
}
exports.isAppAssociationResponse = isAppAssociationResponse;
function isGithubRepoAssociation(a) {
const repo = a;
return repo
&& repo.type === 'github'
&& typeof repo.id === 'number';
}
exports.isGithubRepoAssociation = isGithubRepoAssociation;
function isBitbucketCloudRepoAssociation(a) {
const repo = a;
return repo
&& repo.type === 'bitbucket_cloud'
&& typeof repo.id === 'string';
}
exports.isBitbucketCloudRepoAssociation = isBitbucketCloudRepoAssociation;
function isBitbucketServerRepoAssociation(a) {
const repo = a;
return repo
&& repo.type === 'bitbucket_server'
&& typeof repo.id === 'number';
}
exports.isBitbucketServerRepoAssociation = isBitbucketServerRepoAssociation;
function isApp(d) {
const details = d;
return details
&& typeof details === 'object'
&& typeof details.id === 'string'
&& typeof details.name === 'string'
&& typeof details.slug === 'string'
&& (!details.org || isOrg(details.org))
&& (!details.association || isAppAssociation(details.association));
}
exports.isApp = isApp;
function isAppResponse(r) {
return isAPIResponseSuccess(r)
&& typeof r.data === 'object'
&& isApp(r.data);
}
exports.isAppResponse = isAppResponse;
function isAppsResponse(r) {
if (!isAPIResponseSuccess(r) || !Array.isArray(r.data)) {
return false;
}
if (r.data.length === 0) {
return true;
}
return typeof r.data[0] === 'object' && isApp(r.data[0]);
}
exports.isAppsResponse = isAppsResponse;
function isOAuthLoginResponse(r) {
const res = r;
return isAPIResponseSuccess(res) && typeof res.data === 'object' && typeof res.data.redirect_url === 'string';
}
exports.isOAuthLoginResponse = isOAuthLoginResponse;
function isSnapshot(s) {
const snapshot = s;
return snapshot
&& typeof snapshot.id === 'string'
&& typeof snapshot.sha === 'string'
&& typeof snapshot.ref === 'string'
&& typeof snapshot.state === 'string'
&& typeof snapshot.created === 'string'
&& typeof snapshot.note === 'string';
}
exports.isSnapshot = isSnapshot;
function isSnapshotResponse(r) {
const res = r;
return isAPIResponseSuccess(res) && isSnapshot(res.data);
}
exports.isSnapshotResponse = isSnapshotResponse;
function isSnapshotListResponse(r) {
if (!isAPIResponseSuccess(r) || !Array.isArray(r.data)) {
return false;
}
if (r.data.length === 0) {
return true;
}
return typeof r.data[0] === 'object' && isSnapshot(r.data[0]);
}
exports.isSnapshotListResponse = isSnapshotListResponse;
function isLogin(l) {
const login = l;
return login
&& isUser(login.user)
&& typeof login.token === 'string';
}
exports.isLogin = isLogin;
function isLoginResponse(r) {
const res = r;
return isAPIResponseSuccess(res)
&& typeof res.data === 'object'
&& isLogin(res.data);
}
exports.isLoginResponse = isLoginResponse;
function isUser(u) {
const user = u;
return user
&& typeof user.id === 'number'
&& typeof user.email === 'string';
}
exports.isUser = isUser;
function isUserResponse(r) {
return isAPIResponseSuccess(r)
&& typeof r.data === 'object'
&& isUser(r.data);
}
exports.isUserResponse = isUserResponse;
function isSSHKey(k) {
const key = k;
return key
&& typeof key.id === 'string'
&& typeof key.pubkey === 'string'
&& typeof key.fingerprint === 'string'
&& typeof key.annotation === 'string'
&& typeof key.name === 'string'
&& typeof key.created === 'string'
&& typeof key.updated === 'string';
}
exports.isSSHKey = isSSHKey;
function isSSHKeyListResponse(r) {
if (!isAPIResponseSuccess(r) || !Array.isArray(r.data)) {
return false;
}
if (r.data.length === 0) {
return true;
}
return typeof r.data[0] === 'object' && isSSHKey(r.data[0]);
}
exports.isSSHKeyListResponse = isSSHKeyListResponse;
function isSSHKeyResponse(r) {
return isAPIResponseSuccess(r)
&& typeof r.data === 'object'
&& isSSHKey(r.data);
}
exports.isSSHKeyResponse = isSSHKeyResponse;
function isSecurityProfile(o) {
const obj = o;
return obj && typeof obj === 'object'
&& typeof obj.name === 'string'
&& typeof obj.tag === 'string'
&& typeof obj.type === 'string'
&& typeof obj.created === 'string'
&& typeof obj.credentials === 'object';
}
exports.isSecurityProfile = isSecurityProfile;
function isSecurityProfileResponse(r) {
const res = r;
return isAPIResponseSuccess(res) && isSecurityProfile(res.data);
}
exports.isSecurityProfileResponse = isSecurityProfileResponse;
function isTreatableAilment(a) {
const ailment = a;
return ailment && ailment.treatable && typeof ailment.getTreatmentSteps === 'function';
}
exports.isTreatableAilment = isTreatableAilment;
function isIntegrationName(name) {
const n = name;
return exports.INTEGRATION_NAMES.includes(n);
}
exports.isIntegrationName = isIntegrationName;
function isProjectConfig(configFile) {
return configFile !== undefined && !configFile.hasOwnProperty('projects');
}
exports.isProjectConfig = isProjectConfig;
function isMultiProjectConfig(configFile) {
return configFile !== undefined && configFile.hasOwnProperty('projects');
}
exports.isMultiProjectConfig = isMultiProjectConfig;
;