puter-cli 1.6.0 → 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 +13 -0
- package/bin/index.js +9 -5
- package/package.json +1 -1
- package/src/commands/auth.js +19 -1
- package/src/commands/files.js +2 -2
- package/src/commands/sites.js +10 -6
- package/src/commands/subdomains.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,8 +4,21 @@ 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
|
+
|
|
12
|
+
#### [v1.6.1](https://github.com/HeyPuter/puter-cli/compare/v1.6.0...v1.6.1)
|
|
13
|
+
|
|
14
|
+
> 16 February 2025
|
|
15
|
+
|
|
16
|
+
- fix: set subdomain when creating a site [`6329ed1`](https://github.com/HeyPuter/puter-cli/commit/6329ed1c766b8eb722ac8c03c9ffe61dbba4a66c)
|
|
17
|
+
|
|
7
18
|
#### [v1.6.0](https://github.com/HeyPuter/puter-cli/compare/v1.5.7...v1.6.0)
|
|
8
19
|
|
|
20
|
+
> 16 February 2025
|
|
21
|
+
|
|
9
22
|
- feat: improve init command [`2bd51ee`](https://github.com/HeyPuter/puter-cli/commit/2bd51ee01d0636b7979a9f55d3c746287c3b512a)
|
|
10
23
|
- chore: improve error message [`46fb3b0`](https://github.com/HeyPuter/puter-cli/commit/46fb3b063c1c74d0006138cd400b6ad207e784d9)
|
|
11
24
|
- chore: update package repo [`f6960ed`](https://github.com/HeyPuter/puter-cli/commit/f6960ed6f8e6fb793a6b8340476ab22778b44c14)
|
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
|
}
|
package/src/commands/files.js
CHANGED
|
@@ -402,8 +402,8 @@ export async function deleteFolder(folderPath, skipConfirmation = false) {
|
|
|
402
402
|
});
|
|
403
403
|
|
|
404
404
|
const deleteData = await deleteResponse.json();
|
|
405
|
-
if (deleteResponse.ok) {
|
|
406
|
-
console.log(chalk.green(`Successfully deleted all contents
|
|
405
|
+
if (deleteResponse.ok && Object.keys(deleteData).length == 0) {
|
|
406
|
+
console.log(chalk.green(`Successfully deleted all contents from: ${chalk.cyan(folderPath)}`));
|
|
407
407
|
} else {
|
|
408
408
|
console.log(chalk.red('Failed to delete folder. Please check your input.'));
|
|
409
409
|
}
|
package/src/commands/sites.js
CHANGED
|
@@ -192,12 +192,16 @@ export async function infoSite(args = []) {
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
subdomain
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
195
|
+
}
|
|
196
|
+
// else {
|
|
197
|
+
// console.log(chalk.yellow(`The subdomain: "${subdomain}" is already taken, so let's generate a new random one:`));
|
|
198
|
+
// subdomain = generateAppName(); // Generate a random subdomain
|
|
199
|
+
// console.log(chalk.cyan(`New generated subdomain: "${subdomain}" will be used.`));
|
|
200
|
+
// }
|
|
201
|
+
|
|
202
|
+
// Use the chosen "subdomain"
|
|
203
|
+
console.log(chalk.cyan(`New generated subdomain: "${subdomain}" will be used if its not already in use.`));
|
|
204
|
+
|
|
201
205
|
// Step 3: Host the current directory under the subdomain
|
|
202
206
|
console.log(chalk.cyan(`Hosting app "${appName}" under subdomain "${subdomain}"...`));
|
|
203
207
|
const site = await createSubdomain(subdomain, remoteDir);
|
|
@@ -93,6 +93,7 @@ export async function createSubdomain(subdomain, remoteDir) {
|
|
|
93
93
|
const data = await response.json();
|
|
94
94
|
if (!data.success || !data.result) {
|
|
95
95
|
if (data.error?.code === 'already_in_use') {
|
|
96
|
+
// data.error?.status===409
|
|
96
97
|
console.log(chalk.yellow(`Subdomain already taken!\nMessage: ${data?.error?.message}`));
|
|
97
98
|
return false;
|
|
98
99
|
}
|