Skip to content

Commit 441d624

Browse files
committed
Added install beta script. Fixed urls to point to dashboard.codifycli.com. Fixed logins if another process is already using the port. Fixed logins not saving credentials if .codify folder doesn't exist.
1 parent ad81e8f commit 441d624

File tree

7 files changed

+75
-20
lines changed

7 files changed

+75
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g codify
1818
$ codify COMMAND
1919
running command...
2020
$ codify (--version)
21-
codify/0.9.0 darwin-arm64 node-v20.19.5
21+
codify/1.0.0 darwin-arm64 node-v22.19.0
2222
$ codify --help [COMMAND]
2323
USAGE
2424
$ codify COMMAND

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
"start:dev": "./bin/dev.js",
142142
"start:vm": "npm run build && npm run pack:macos && npm run start:vm"
143143
},
144-
"version": "0.9.0",
144+
"version": "1.0.0",
145145
"bugs": "https://github.com/kevinwang5658/codify/issues",
146146
"keywords": [
147147
"oclif"

scripts/install-beta.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -e;
3+
# Always clean up tmp dir even if install fails
4+
trap 'rm -rf $TEMP_DIR' EXIT
5+
6+
if [ $(uname -s) != "Darwin" ]; then
7+
echo "Only macOS systems are currently supported"
8+
exit 1;
9+
fi;
10+
11+
ARCH=$(uname -m)
12+
TEMP_DIR=$(mktemp -d -t "codify")
13+
14+
echo "Downloading beta installer...";
15+
curl -L -o "$TEMP_DIR/codify-installer.pkg" "https://api.codifycli.com/v2/cli/releases/beta/$ARCH/installer";
16+
echo "Downloaded Codify beta installer";
17+
18+
printf "\nRunning installer... (sudo may be required)\n";
19+
sudo installer -pkg "$TEMP_DIR/codify-installer.pkg" -target /;
20+
21+
CYAN='\033[0;36m'
22+
END_ESCAPE='\033[0m'
23+
24+
printf "${CYAN}\n🎉 %s 🎉\n%s${END_ESCAPE}\n" "Successfully installed Codify beta. Type codify --help for a list of commands." "Visit the documentation at https://docs.codifycli.com for more info."
25+
26+
exit 0;

src/commands/login.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import chalk from 'chalk';
2+
13
import { BaseCommand } from '../common/base-command.js';
24
import { LoginOrchestrator } from '../orchestrators/login.js';
35

@@ -19,7 +21,8 @@ For more information, visit: https://docs.codifycli.com/commands/validate
1921
const { flags } = await this.parse(Login)
2022

2123
await LoginOrchestrator.run();
24+
console.log(chalk.green('\nSuccessfully logged in!'))
2225

23-
process.exit(0)
26+
process.exit(0);
2427
}
2528
}

src/connect/login-helper.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from 'node:fs/promises';
33
import * as os from 'node:os';
44
import * as path from 'node:path';
55
import { config } from '../config.js';
6+
import chalk from 'chalk';
67

78
interface Credentials {
89
accessToken: string;
@@ -49,7 +50,9 @@ export class LoginHelper {
4950

5051
static async save(accessToken: string) {
5152
const credentialsPath = path.join(os.homedir(), '.codify', 'credentials.json');
52-
console.log(`Saving credentials to ${credentialsPath}`);
53+
console.log(chalk.green(`Saving credentials to ${credentialsPath}`));
54+
55+
await fs.mkdir(path.dirname(credentialsPath), { recursive: true });
5356
await fs.writeFile(credentialsPath, JSON.stringify({ accessToken }));
5457
}
5558

src/orchestrators/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class ConnectOrchestrator {
4040
}
4141

4242
if (openBrowser) {
43-
open(`http://localhost:3000/connection/success?code=${connectionSecret}`)
43+
open(`${config.dashboardUrl}/connection/success?code=${connectionSecret}`)
4444
console.log(`Open browser window to store code.
4545
4646
If unsuccessful manually enter the code:

src/orchestrators/login.ts

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import chalk from 'chalk';
12
import cors from 'cors';
23
import express, { json } from 'express';
34
import open from 'open';
@@ -14,7 +15,7 @@ const schema = {
1415
}
1516
},
1617
additionalProperties: false,
17-
required: ['accessToken', 'email', 'userId', 'expiry'],
18+
required: ['accessToken'],
1819
}
1920

2021
interface Credentials {
@@ -29,27 +30,49 @@ export class LoginOrchestrator {
2930
const app = express();
3031

3132
app.use(cors({ origin: config.corsAllowedOrigins }))
32-
app.use(json())
33+
app.use(json());
3334

34-
const [, server] = await Promise.all([
35-
new Promise<void>((resolve) => {
35+
const server = app.listen(config.loginServerPort, (error) => {
36+
if (error) {
37+
console.error(chalk.red('Something went wrong. Only a single instance of codify login can be run at the same time. Please terminate the other process and try again.'));
38+
process.exit(1);
39+
}
40+
41+
console.log(
42+
`Opening CLI auth page...
43+
Manually open it here: ${config.dashboardUrl}/auth/cli`
44+
)
45+
open(`${config.dashboardUrl}/auth/cli`);
46+
})
47+
48+
await Promise.race([
49+
new Promise<void>((resolve, reject) => {
3650
app.post('/', async (req, res) => {
37-
const body = req.body as Credentials;
51+
try {
52+
const body = req.body as Credentials;
3853

39-
// if (!ajv.validate(schema, body)) {
40-
// console.error('Received invalid credentials', body)
41-
// return res.status(400).send({ message: ajv.errorsText() })
42-
// }
54+
if (!ajv.validate(schema, body)) {
55+
console.error(chalk.red('Received invalid credentials. Please submit a support ticket'))
56+
return res.status(400).send({ message: ajv.errorsText() })
57+
}
4358

44-
await LoginHelper.save(body.accessToken);
45-
res.sendStatus(200);
59+
console.log(chalk.green('\nSuccessfully received sign-in credentials...'))
4660

47-
resolve();
61+
await LoginHelper.save(body.accessToken);
62+
res.sendStatus(200);
63+
64+
resolve();
65+
} catch (error) {
66+
console.error(error);
67+
reject(error);
68+
}
4869
});
4970
}),
50-
app.listen(config.loginServerPort, () => {
51-
console.log('Opening CLI auth page...')
52-
open('http://localhost:3000/auth/cli');
71+
new Promise<void>((resolve) => {
72+
setTimeout(() => {
73+
console.error(chalk.red('Did not receive sign-in credentials in 5 minutes, please re-run the command'));
74+
resolve();
75+
}, 5 * 60 * 1000);
5376
})
5477
])
5578

0 commit comments

Comments
 (0)