Skip to content

Commit

Permalink
feat: prompt on hard-reset
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash committed Sep 16, 2024
1 parent f538c74 commit f48ec30
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
65 changes: 40 additions & 25 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -170,14 +170,26 @@ 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);
if ('error' in res) return this.showError(res.error, 'MANIFEST_VALIDATION_FAILED');

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<ParsedSquidReference>);

// some hack to normalize slot name in case if version is used
{
Expand Down Expand Up @@ -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;
}

Expand All @@ -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 });

Expand Down Expand Up @@ -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.`,
},
]);
Expand Down Expand Up @@ -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.`,
);
Expand All @@ -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',
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit f48ec30

Please sign in to comment.