@appliance.sh/cli 1.7.0 → 1.9.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/package.json +8 -4
- package/src/appliance-configure.ts +41 -1
- package/src/appliance.ts +2 -2
- package/src/utils/common.ts +37 -0
- package/src/wizards/appliance.ts +12 -0
- package/tsconfig.json +3 -0
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appliance.sh/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Shell for installing, running, and developing applications on the Appliance platform",
|
|
5
5
|
"repository": "https://github.com/appliance-sh/appliance.sh",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Eliot Lim",
|
|
8
|
-
"type": "
|
|
8
|
+
"type": "module",
|
|
9
9
|
"main": "index.js",
|
|
10
10
|
"bin": {
|
|
11
11
|
"appliance": "dist/appliance.js"
|
|
@@ -17,11 +17,15 @@
|
|
|
17
17
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@appliance.sh/sdk": "1.
|
|
20
|
+
"@appliance.sh/sdk": "1.9.0",
|
|
21
|
+
"@inquirer/prompts": "^7.10.1",
|
|
21
22
|
"chalk": "^5.4.1",
|
|
22
|
-
"commander": "^14.0.0"
|
|
23
|
+
"commander": "^14.0.0",
|
|
24
|
+
"json-diff": "^1.0.6",
|
|
25
|
+
"random-word-slugs": "^0.1.7"
|
|
23
26
|
},
|
|
24
27
|
"devDependencies": {
|
|
28
|
+
"@types/json-diff": "^1.0.3",
|
|
25
29
|
"@types/node": "^24.0.1"
|
|
26
30
|
}
|
|
27
31
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { extractApplianceFile } from './utils/common.js';
|
|
3
|
+
import { promptForApplianceName } from './wizards/appliance.js';
|
|
4
|
+
import * as diff from 'json-diff';
|
|
5
|
+
|
|
6
|
+
import * as prompt from '@inquirer/prompts';
|
|
2
7
|
|
|
3
8
|
const program = new Command();
|
|
4
9
|
|
|
@@ -6,4 +11,39 @@ program
|
|
|
6
11
|
.option('-f, --file <file>', 'appliance manifest file', 'appliance.json')
|
|
7
12
|
.option('-d, --directory <directory>', 'appliance directory');
|
|
8
13
|
|
|
9
|
-
program.parse(process.argv);
|
|
14
|
+
const cmd = program.parse(process.argv);
|
|
15
|
+
|
|
16
|
+
const applianceFile = extractApplianceFile(cmd);
|
|
17
|
+
|
|
18
|
+
// If a file or directory was specified, but the file was not found, exit with an error.
|
|
19
|
+
if (
|
|
20
|
+
((cmd.getOptionValue('file') && cmd.getOptionValue('file') !== 'appliance.json') ||
|
|
21
|
+
cmd.getOptionValue('directory')) &&
|
|
22
|
+
!applianceFile.success
|
|
23
|
+
) {
|
|
24
|
+
console.log('The specified file was not found.');
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let updatedApplianceFile = {
|
|
29
|
+
...applianceFile.data,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const name = await promptForApplianceName(applianceFile.data);
|
|
34
|
+
|
|
35
|
+
updatedApplianceFile = {
|
|
36
|
+
name,
|
|
37
|
+
...updatedApplianceFile,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
console.log(diff.colorize(diff.diff(applianceFile, updatedApplianceFile)));
|
|
41
|
+
|
|
42
|
+
const saveChanges = await prompt.confirm({ message: 'Save changes?', default: true });
|
|
43
|
+
if (!saveChanges) {
|
|
44
|
+
console.log('Changes cancelled.');
|
|
45
|
+
process.exit(0);
|
|
46
|
+
}
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error(error);
|
|
49
|
+
}
|
package/src/appliance.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as sdk from '@appliance.sh/sdk';
|
|
6
6
|
|
|
7
7
|
const program = new Command();
|
|
8
8
|
|
|
9
9
|
program
|
|
10
10
|
.name('appliance')
|
|
11
|
-
.version(VERSION)
|
|
11
|
+
.version(sdk.VERSION)
|
|
12
12
|
.command('build', 'builds the appliance in the current working directory')
|
|
13
13
|
.command('configure', 'configures the appliance in the current working directory')
|
|
14
14
|
.command('install [appliance-names...]', 'install one or more appliances')
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import * as fs from 'node:fs';
|
|
4
|
+
import { applianceInput, ApplianceInput, Result } from '@appliance.sh/sdk';
|
|
5
|
+
|
|
6
|
+
export function extractApplianceFile(cmd: Command): Result<ApplianceInput> {
|
|
7
|
+
let filePath;
|
|
8
|
+
if (cmd.getOptionValue('file')) {
|
|
9
|
+
filePath = path.resolve(process.cwd(), cmd.getOptionValue('file'));
|
|
10
|
+
} else if (cmd.getOptionValue('directory')) {
|
|
11
|
+
filePath = path.resolve(process.cwd(), cmd.getOptionValue('directory'), 'appliance.json');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// check if file exists
|
|
15
|
+
if (!filePath) {
|
|
16
|
+
return {
|
|
17
|
+
success: false,
|
|
18
|
+
error: { name: 'File Not Found', message: 'No appliance file found.' },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!filePath.endsWith('.json')) {
|
|
23
|
+
throw new Error('Appliance file must be a JSON file');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const fileBuf = fs.readFileSync(filePath);
|
|
28
|
+
const result = applianceInput.safeParse(fileBuf.toString());
|
|
29
|
+
|
|
30
|
+
return result;
|
|
31
|
+
} catch (err) {
|
|
32
|
+
return {
|
|
33
|
+
success: false,
|
|
34
|
+
error: err as Error,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as prompts from '@inquirer/prompts';
|
|
2
|
+
import { ApplianceInput } from '@appliance.sh/sdk';
|
|
3
|
+
import * as slug from 'random-word-slugs';
|
|
4
|
+
|
|
5
|
+
export const promptForApplianceName = (config?: Partial<ApplianceInput>) => {
|
|
6
|
+
const name = prompts.input({
|
|
7
|
+
message: `What's the name of your appliance?`,
|
|
8
|
+
default: config?.name ?? slug.generateSlug(2, { format: 'kebab' }),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
return name;
|
|
12
|
+
};
|