puter-cli 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/bin/index.js +9 -5
- package/package.json +1 -1
- package/src/commands/auth.js +19 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,8 +4,15 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
+
#### [v1.7.0](https://github.com/HeyPuter/puter-cli/compare/v1.6.1...v1.7.0)
|
|
8
|
+
|
|
9
|
+
- feat: save auth token when login [`55b32b7`](https://github.com/HeyPuter/puter-cli/commit/55b32b7feca050902f4470f06af38f81d3299e6a)
|
|
10
|
+
- fix: create app from host shell [`30e5028`](https://github.com/HeyPuter/puter-cli/commit/30e5028d831d26349e3ae2fc8e34921693b5702c)
|
|
11
|
+
|
|
7
12
|
#### [v1.6.1](https://github.com/HeyPuter/puter-cli/compare/v1.6.0...v1.6.1)
|
|
8
13
|
|
|
14
|
+
> 16 February 2025
|
|
15
|
+
|
|
9
16
|
- fix: set subdomain when creating a site [`6329ed1`](https://github.com/HeyPuter/puter-cli/commit/6329ed1c766b8eb722ac8c03c9ffe61dbba4a66c)
|
|
10
17
|
|
|
11
18
|
#### [v1.6.0](https://github.com/HeyPuter/puter-cli/compare/v1.5.7...v1.6.0)
|
package/bin/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
|
+
import chalk from 'chalk';
|
|
3
4
|
import { login, logout } from '../src/commands/auth.js';
|
|
4
5
|
import { init } from '../src/commands/init.js';
|
|
5
6
|
import { startShell } from '../src/commands/shell.js';
|
|
6
7
|
import { PROJECT_NAME, getLatestVersion } from '../src/commons.js';
|
|
8
|
+
import { createApp } from '../src/commands/apps.js';
|
|
7
9
|
|
|
8
10
|
async function main() {
|
|
9
11
|
const version = await getLatestVersion(PROJECT_NAME);
|
|
@@ -17,6 +19,7 @@ async function main() {
|
|
|
17
19
|
program
|
|
18
20
|
.command('login')
|
|
19
21
|
.description('Login to Puter account')
|
|
22
|
+
.option('-s, --save', 'Save authentication token in .env file', '')
|
|
20
23
|
.action(login);
|
|
21
24
|
|
|
22
25
|
program
|
|
@@ -37,23 +40,24 @@ async function main() {
|
|
|
37
40
|
|
|
38
41
|
// App commands
|
|
39
42
|
program
|
|
40
|
-
.command('app:create
|
|
43
|
+
.command('app:create')
|
|
41
44
|
.description('Create a new Puter application')
|
|
42
45
|
.argument('<name>', 'Name of the application')
|
|
43
|
-
.argument('[
|
|
44
|
-
.option('-d, --description
|
|
46
|
+
.argument('[remoteDir]', 'Remote directory path')
|
|
47
|
+
.option('-d, --description [description]', 'Application description', '')
|
|
45
48
|
.option('-u, --url <url>', 'Application URL', 'https://dev-center.puter.com/coming-soon.html')
|
|
46
|
-
.action(async (name,
|
|
49
|
+
.action(async (name, remoteDir, options) => {
|
|
47
50
|
try {
|
|
48
51
|
await createApp({
|
|
49
52
|
name,
|
|
50
|
-
directory:
|
|
53
|
+
directory: remoteDir || '',
|
|
51
54
|
description: options.description || '',
|
|
52
55
|
url: options.url
|
|
53
56
|
});
|
|
54
57
|
} catch (error) {
|
|
55
58
|
console.error(chalk.red(error.message));
|
|
56
59
|
}
|
|
60
|
+
process.exit(0);
|
|
57
61
|
});
|
|
58
62
|
|
|
59
63
|
if (process.argv.length === 2) {
|
package/package.json
CHANGED
package/src/commands/auth.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
1
2
|
import inquirer from 'inquirer';
|
|
2
3
|
import chalk from 'chalk';
|
|
3
4
|
import Conf from 'conf';
|
|
@@ -10,7 +11,7 @@ const config = new Conf({ projectName: PROJECT_NAME });
|
|
|
10
11
|
* Login user
|
|
11
12
|
* @returns void
|
|
12
13
|
*/
|
|
13
|
-
export async function login() {
|
|
14
|
+
export async function login(args = {}) {
|
|
14
15
|
const answers = await inquirer.prompt([
|
|
15
16
|
{
|
|
16
17
|
type: 'input',
|
|
@@ -80,6 +81,23 @@ export async function login() {
|
|
|
80
81
|
spinner.succeed(chalk.green('Successfully logged in to Puter!'));
|
|
81
82
|
}
|
|
82
83
|
console.log(chalk.dim(`Token: ${data.token.slice(0, 5)}...${data.token.slice(-5)}`));
|
|
84
|
+
// Save token
|
|
85
|
+
if (args.save){
|
|
86
|
+
const localEnvFile = '.env';
|
|
87
|
+
try {
|
|
88
|
+
// Check if the file exists, if so then delete it before writing.
|
|
89
|
+
if (fs.existsSync(localEnvFile)) {
|
|
90
|
+
console.log(chalk.yellow(`File "${localEnvFile}" already exists... Adding token.`));
|
|
91
|
+
fs.appendFileSync(localEnvFile, `\nPUTER_API_KEY="${data.token}"`, 'utf8');
|
|
92
|
+
} else {
|
|
93
|
+
console.log(chalk.cyan(`Saving token to ${chalk.green(localEnvFile)} file.`));
|
|
94
|
+
fs.writeFileSync(localEnvFile, `PUTER_API_KEY="${data.token}"`, 'utf8');
|
|
95
|
+
}
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error(chalk.red(`Cannot save token to .env file. Error: ${error.message}`));
|
|
98
|
+
console.log(chalk.cyan(`PUTER_API_KEY="${data.token}"`));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
83
101
|
} else {
|
|
84
102
|
spinner.fail(chalk.red('Login failed. Please check your credentials.'));
|
|
85
103
|
}
|