diff --git a/package.json b/package.json index a6457a2..194bb36 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@subsquid/cli", "description": "squid cli tool", - "version": "3.0.0-beta.10", + "version": "3.0.0-beta.11", "license": "GPL-3.0-or-later", "repository": "git@github.com:subsquid/squid-cli.git", "publishConfig": { @@ -78,7 +78,7 @@ "@oclif/plugin-autocomplete": "3.2.2", "@oclif/plugin-warn-if-update-available": "^3.1.13", "@subsquid/commands": "^2.3.1", - "@subsquid/manifest": "^2.0.0-beta.2", + "@subsquid/manifest": "^2.0.0-beta.3", "@subsquid/manifest-expr": "^0.0.1", "@types/fast-levenshtein": "^0.0.4", "@types/lodash": "^4.17.7", diff --git a/src/commands/deploy.ts b/src/commands/deploy.ts index c7637df..afc6286 100644 --- a/src/commands/deploy.ts +++ b/src/commands/deploy.ts @@ -17,7 +17,7 @@ import { deploySquid, OrganizationRequest, Squid, uploadFile } from '../api'; import { SqdFlags, SUCCESS_CHECK_MARK } from '../command'; import { DeployCommand } from '../deploy-command'; import { loadManifestFile } from '../manifest'; -import { printSquid } from '../utils'; +import { formatSquidReference, ParsedSquidReference, printSquid } from '../utils'; const compressAsync = promisify(targz.compress); @@ -170,6 +170,18 @@ export default class Deploy extends DeployCommand { return this.error('Not implemented yet'); } + if (interactive && hardReset) { + const { confirm } = await inquirer.prompt([ + { + name: 'confirm', + type: 'confirm', + message: `Are you sure?`, + prefix: `Your squid will be reset, which may potentially result in data loss.`, + }, + ]); + if (!confirm) return; + } + this.log(`🦑 Releasing the squid from local folder`); const res = resolveManifest(source, manifestPath); @@ -177,7 +189,7 @@ export default class Deploy extends DeployCommand { const { buildDir, squidDir, manifest } = res; - const overrides = reference ? reference : pick(flags, 'slot', 'name', 'tag', 'org'); + const overrides = reference || (pick(flags, 'slot', 'name', 'tag', 'org') as Partial); // some hack to normalize slot name in case if version is used { @@ -218,11 +230,19 @@ export default class Deploy extends DeployCommand { }); } + /** + * Squid exists we should check running deploys + */ + if (target) { + const attached = await this.promptAttachToDeploy(target, { interactive }); + if (attached) return; + } + /** * Squid exists we should ask for update */ if (target && !flags['allow-update']) { - const update = await this.promptUpdateSquid(target, { interactive, hardReset }); + const update = await this.promptUpdateSquid(target, { interactive }); if (!update) return; } @@ -235,15 +255,7 @@ export default class Deploy extends DeployCommand { if (!add) return; } - /** - * Squid exists we should check running deploys - */ - if (target) { - const attached = await this.promptAttachToDeploy(target, { interactive }); - if (attached) return; - } - - const archiveName = `${manifest.name}.tar.gz`; + const archiveName = `${formatSquidReference({ name, slot, tag })}.tar.gz`; const artifactPath = await this.pack({ buildDir, squidDir, archiveName }); const artifactUrl = await this.upload({ organization, artifactPath }); @@ -279,31 +291,32 @@ export default class Deploy extends DeployCommand { } private async promptUpdateSquid( - target: Squid, + squid: Squid, { using = 'using "--allow-update" flag', interactive, - hardReset, }: { using?: string; interactive?: boolean; - hardReset?: boolean; } = {}, ) { - const warning = `The squid ${printSquid(target)} already exists.`; + const warning = [ + `The squid ${printSquid(squid)} already exists${squid.tags.length > 0 ? ` and has one or more tags assigned to it:` : ``}`, + ...squid.tags.map((t) => chalk.dim(` - ${t.name}`)), + ]; - if (!interactive) { - this.error([warning, `Please do it explicitly ${using}`].join('\n')); + if (interactive) { + this.warn(warning.join('\n')); + } else { + this.error([...warning, `Please do it explicitly ${using}`].join('\n')); } - this.warn(warning); - const { confirm } = await inquirer.prompt([ { name: 'confirm', type: 'confirm', message: 'Are you sure?', - prefix: `The squid ${printSquid(target)} will be updated.`, + prefix: `The squid ${printSquid(squid)} will be updated.`, }, ]); @@ -334,11 +347,12 @@ export default class Deploy extends DeployCommand { ``, ].join('\n'); - if (!interactive) { + if (interactive) { + this.warn(warning); + } else { this.error([warning, `Please do it explicitly ${using}`].join('\n')); } - this.warn(warning); this.log( `If it is intended and you'd like to override them, just skip this message and confirm, the manifest name will be overridden automatically in the Cloud during the deploy.`, ); @@ -362,11 +376,12 @@ export default class Deploy extends DeployCommand { const warning = `The squid name is not defined either in the manifest or via CLI command.`; - if (!interactive) { + if (interactive) { + this.warn(warning); + } else { this.error([warning, `Please specify it explicitly ${using}`].join('\n')); } - this.warn(warning); const { input } = await inquirer.prompt([ { name: 'input', diff --git a/yarn.lock b/yarn.lock index c3d7f0b..55da827 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1411,7 +1411,7 @@ __metadata: "@oclif/plugin-autocomplete": "npm:3.2.2" "@oclif/plugin-warn-if-update-available": "npm:^3.1.13" "@subsquid/commands": "npm:^2.3.1" - "@subsquid/manifest": "npm:^2.0.0-beta.2" + "@subsquid/manifest": "npm:^2.0.0-beta.3" "@subsquid/manifest-expr": "npm:^0.0.1" "@types/async-retry": "npm:^1.4.8" "@types/blessed": "npm:^0.1.25" @@ -1513,15 +1513,15 @@ __metadata: languageName: node linkType: hard -"@subsquid/manifest@npm:^2.0.0-beta.2": - version: 2.0.0-beta.2 - resolution: "@subsquid/manifest@npm:2.0.0-beta.2" +"@subsquid/manifest@npm:^2.0.0-beta.3": + version: 2.0.0-beta.3 + resolution: "@subsquid/manifest@npm:2.0.0-beta.3" dependencies: "@subsquid/manifest-expr": "npm:^0.0.1" joi: "npm:17.13.3" js-yaml: "npm:^4.1.0" lodash: "npm:^4.17.21" - checksum: 10c0/32059ac92737aa1728fdfd50f6e3c300e662b7d05f13c33dd59538aa84a9beb5ae4d830513754f6a0a87b8f2f41968b14890144be93ccf0455b15b2bc59b539b + checksum: 10c0/7265c405631db86b2ac553f2c95070dd1f0e612ac71211b6cf70fed7d4150bc7bc979c6605662fd66364c25a40905a60f29477f415add31fee4cc4fa16220112 languageName: node linkType: hard