Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI auto-updates on every run #441

Merged
merged 33 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1a5b163
[CLI] Make solc default backup compilation
adam-maj Dec 2, 2022
8de803f
Add changeset
adam-maj Dec 2, 2022
c8f3881
Merge branch 'main' into am/cli
adam-maj Dec 2, 2022
5afb56c
CLI auto-updates on every run
adam-maj Dec 2, 2022
86f2283
Update
adam-maj Dec 2, 2022
f309e50
Merge branch 'main' into am/cli
adam-maj Dec 2, 2022
0825d37
Update
adam-maj Dec 2, 2022
0861ca9
Merge branch 'am/cli' of https://github.com/thirdweb-dev/js into am/cli
adam-maj Dec 2, 2022
1b661e6
Remove shelljs
adam-maj Dec 2, 2022
c2b20ee
Add changeset
adam-maj Dec 2, 2022
121fa4a
Update package.json
adam-maj Dec 2, 2022
00ad963
Switch back package.json
adam-maj Dec 2, 2022
a179b38
Merge branch 'main' into am/cli
adam-maj Dec 2, 2022
8dd0195
Merge branch 'main' into am/cli
adam-maj Dec 2, 2022
47d7ed4
Merge branch 'main' into am/cli
adam-maj Dec 3, 2022
725330f
Lower package version
adam-maj Dec 3, 2022
62f87dc
Install by package manager
adam-maj Dec 3, 2022
5622835
Extract out local package detection
adam-maj Dec 3, 2022
d5b649c
Reset versio
adam-maj Dec 3, 2022
569ac86
Update package version
adam-maj Dec 3, 2022
21ed6c5
Update packages
adam-maj Dec 3, 2022
a87f3ec
Merge branch 'main' into am/cli
adam-maj Dec 5, 2022
4d57123
Merge branch 'main' into am/cli
adam-maj Dec 5, 2022
58ac7aa
Catch cases for global install
adam-maj Dec 6, 2022
2cea325
Update version
adam-maj Dec 6, 2022
504eaff
Fix pnpm edge case
adam-maj Dec 6, 2022
b05c6ad
Update package.json
adam-maj Dec 6, 2022
272b1f0
Update to account for all cases
adam-maj Dec 6, 2022
32bec49
Update package.json version
adam-maj Dec 6, 2022
b02274f
Update again :(
adam-maj Dec 6, 2022
5bec267
Automatically accept install npx
adam-maj Dec 6, 2022
fab2a9a
Update package version
adam-maj Dec 6, 2022
c58ec99
Add default case for package manager
adam-maj Dec 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chilly-cows-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

CLI autoupdates on run
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "thirdweb",
"main": "dist/cli/index.js",
"version": "0.9.3",
"version": "0.9.1",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
"author": "thirdweb eng <eng@thirdweb.com>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -73,4 +73,4 @@
"sourcemap": true,
"clean": true
}
}
}
139 changes: 120 additions & 19 deletions packages/cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@
import { detectExtensions } from "../common/feature-detector";
import { processProject } from "../common/processor";
import { cliVersion, pkg } from "../constants/urls";
import { info, logger } from "../core/helpers/logger";
import { info, logger, spinner } from "../core/helpers/logger";
import { twCreate } from "../create/command";
import { deploy } from "../deploy";
import { upload } from "../storage/command";
import { ThirdwebStorage } from "@thirdweb-dev/storage";
import chalk from "chalk";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
jnsdls marked this conversation as resolved.
Show resolved Hide resolved
import { exec, spawn } from "child_process";
import { Command } from "commander";
import open from "open";
// import ora from "ora";
import prompts from "prompts";

const main = async () => {
const program = new Command();

//yes this has to look like this, eliminates whitespace
console.info(`
$$\\ $$\\ $$\\ $$\\ $$\\
$$ | $$ | \\__| $$ | $$ |
$$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$$$$\\
\\_$$ _| $$ __$$\\ $$ |$$ __$$\\ $$ __$$ |$$ | $$ | $$ |$$ __$$\\ $$ __$$\\
$$ | $$ | $$ |$$ |$$ | \\__|$$ / $$ |$$ | $$ | $$ |$$$$$$$$ |$$ | $$ |
$$ |$$\\ $$ | $$ |$$ |$$ | $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ |
\\$$$$ |$$ | $$ |$$ |$$ | \\$$$$$$$ |\\$$$$$\\$$$$ |\\$$$$$$$\\ $$$$$$$ |
\\____/ \\__| \\__|\\__|\\__| \\_______| \\_____\\____/ \\_______|\\_______/ `);
console.info(`\n 💎 thirdweb-cli v${cliVersion} 💎\n`);
import("update-notifier").then(({ default: updateNotifier }) => {
updateNotifier({
pkg,
shouldNotifyInNpmScript: true,
// check every time while we're still building the CLI
updateCheckInterval: 0,
}).notify();
});
// eslint-disable-next-line turbo/no-undeclared-env-vars
if (process.env.THIRDWEB_CLI_SKIP_INTRO !== "true") {
console.info(`
$$\\ $$\\ $$\\ $$\\ $$\\
$$ | $$ | \\__| $$ | $$ |
$$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$$$$\\
\\_$$ _| $$ __$$\\ $$ |$$ __$$\\ $$ __$$ |$$ | $$ | $$ |$$ __$$\\ $$ __$$\\
$$ | $$ | $$ |$$ |$$ | \\__|$$ / $$ |$$ | $$ | $$ |$$$$$$$$ |$$ | $$ |
$$ |$$\\ $$ | $$ |$$ |$$ | $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ |
\\$$$$ |$$ | $$ |$$ |$$ | \\$$$$$$$ |\\$$$$$\\$$$$ |\\$$$$$$$\\ $$$$$$$ |
\\____/ \\__| \\__|\\__|\\__| \\_______| \\_____\\____/ \\_______|\\_______/ `);
console.info(`\n 💎 thirdweb-cli v${cliVersion} 💎\n`);
}

program
.name("thirdweb-cli")
Expand Down Expand Up @@ -198,6 +197,108 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$
await detectExtensions(options);
});

// eslint-disable-next-line turbo/no-undeclared-env-vars
if (process.env.THIRDWEB_CLI_SKIP_INTRO !== "true") {
jnsdls marked this conversation as resolved.
Show resolved Hide resolved
const versionSpinner = spinner("Checking for updates...");
await import("update-notifier").then(
async ({ default: updateNotifier }) => {
const notifier = updateNotifier({
pkg,
shouldNotifyInNpmScript: true,
// check every time while we're still building the CLI
updateCheckInterval: 0,
});

const versionInfo = await notifier.fetchInfo();
versionSpinner.stop();

if (versionInfo.type !== "latest") {
const res = await prompts({
type: "toggle",
name: "upgrade",
message: `A new version of the CLI is available. Would you like to upgrade?`,
initial: true,
active: "yes",
inactive: "no",
});

if (res.upgrade) {
const updateSpinner = spinner(
`Upgrading CLI to version ${versionInfo.latest}...`,
);

// Check if thirdweb package is already installed in local package.json
const localPackages: string[] = await new Promise((resolve) => {
jnsdls marked this conversation as resolved.
Show resolved Hide resolved
exec("npm ls --depth=0", (err, stdout) => {
var packages: string[] = [];
packages = stdout.split("\n");
packages = packages.filter(function (item) {
if (item.match(/^├──.+/g) !== null) {
return true;
}
if (item.match(/^└──.+/g) !== null) {
return true;
}
return undefined;
});
packages = packages
.map(function (item) {
if (item.match(/^├──.+/g) !== null) {
return item.replace(/^├──\s/g, "");
}
if (item.match(/^└──.+/g) !== null) {
return item.replace(/^└──\s/g, "");
}
})
.filter((item) => !!item) as string[];
resolve(packages);
});
});

const isLocal = localPackages.find((packageName) =>
packageName.includes("thirdweb@"),
);
const command = isLocal ? "npm i thirdweb" : "npm i -g thirdweb";
jnsdls marked this conversation as resolved.
Show resolved Hide resolved
await new Promise((done, failed) => {
exec(command, (err, stdout, stderr) => {
if (err) {
failed(err);
return;
}

done({ stdout, stderr });
});
});

updateSpinner.succeed(
`Successfully upgraded CLI to version ${versionInfo.latest}. Continuing execution...`,
);

const clonedEnvironment = { ...process.env };
clonedEnvironment.THIRDWEB_CLI_SKIP_INTRO = "true";

await new Promise((done, failed) => {
const shell = spawn(
`npx thirdweb ${process.argv.slice(2).join(" ")}`,
[],
{ stdio: "inherit", shell: true, env: clonedEnvironment },
);
shell.on("close", (code) => {
if (code === 0) {
done("");
} else {
failed();
}
});
});

process.exit(0);
}
}
},
);
}

await program.parseAsync();
};

Expand Down