@fusionfroze/fset 1.0.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/README.md +134 -0
- package/commands/create.js +86 -0
- package/commands/ls.js +48 -0
- package/commands/open.js +54 -0
- package/commands/remove.js +32 -0
- package/index.js +33 -0
- package/package.json +25 -0
package/README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# FSET
|
|
2
|
+
|
|
3
|
+
You use different _applications_ with different _file(s)_ or _tab(s)_ for different _tasks_. Switching between them means closing everything and starting over manually.
|
|
4
|
+
|
|
5
|
+
**fset** does this for you with a single command.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
**Prerequisite:** Node.js v18+
|
|
10
|
+
|
|
11
|
+
**Install globally:**
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
$ npm i -g @fusionfroze/fset
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**For local development:**
|
|
18
|
+
|
|
19
|
+
```shell
|
|
20
|
+
$ npm install
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```shell
|
|
24
|
+
$ npm link
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## How to use it
|
|
28
|
+
|
|
29
|
+
### Setting up a new Environment
|
|
30
|
+
|
|
31
|
+
```shell
|
|
32
|
+
$ fset create demo
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
This will open the input interface
|
|
36
|
+
|
|
37
|
+
```shell
|
|
38
|
+
$ fset create demo
|
|
39
|
+
Application 1
|
|
40
|
+
? Enter the path to the app: "C:\Users\Public\Desktop\Google Chrome.lnk"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Here you have to enter the path that **exactly** points to the location of the application.
|
|
44
|
+
Then you will be asked to enter URL if you need it.
|
|
45
|
+
|
|
46
|
+
```shell
|
|
47
|
+
$ fset create demo
|
|
48
|
+
Application 1
|
|
49
|
+
✔ Enter the path to the app: "C:\Users\Public\Desktop\Google Chrome.lnk"
|
|
50
|
+
Enter URL(s) or file path(s) you want the app to open with.
|
|
51
|
+
Press enter with an empty input to exit the input interface.
|
|
52
|
+
? URL-1: https://clandor.com
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
You can exit the input interface for the current application by pressing **enter** with an **empty input**.
|
|
56
|
+
|
|
57
|
+
```shell
|
|
58
|
+
$ fset create demo
|
|
59
|
+
Application 1
|
|
60
|
+
✔ Enter the path to the app: "C:\Users\Public\Desktop\Google Chrome.lnk"
|
|
61
|
+
Enter URL(s) or file path(s) you want the app to open with.
|
|
62
|
+
Press enter with an empty input to exit the input interface.
|
|
63
|
+
✔ URL-1: https://clandor.com
|
|
64
|
+
✔ URL-2:
|
|
65
|
+
? Add another app? (Y/n)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Now you will be given a choice, you can either add a new application or can exit the interface by entering **n**.
|
|
69
|
+
If you choose **n**, a success message will show that your new environment is set up successfully. Or, alternatively you can continue adding more application requried for the task.
|
|
70
|
+
|
|
71
|
+
```shell
|
|
72
|
+
$ fset create demo
|
|
73
|
+
Application 1
|
|
74
|
+
✔ Enter the path to the app: "C:\Users\Public\Desktop\Google Chrome.lnk"
|
|
75
|
+
Enter URL(s) or file path(s) you want the app to open with.
|
|
76
|
+
Press enter with an empty input to exit the input interface.
|
|
77
|
+
✔ URL-1: https://clandor.com
|
|
78
|
+
✔ URL-2:
|
|
79
|
+
✔ Add another app? No
|
|
80
|
+
|
|
81
|
+
demo created successfully.
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Opening an Environment
|
|
85
|
+
|
|
86
|
+
```shell
|
|
87
|
+
$ fset open demo
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
This command will open all the applications with set URL(s) or file(s) instantly.
|
|
91
|
+
|
|
92
|
+
### Removing an Environment
|
|
93
|
+
|
|
94
|
+
```shell
|
|
95
|
+
$ fset remove demo
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
You will be prompted once to confirm the operation. Once removed the action is irreversible.
|
|
99
|
+
|
|
100
|
+
### List all the Environments set up in your machine
|
|
101
|
+
|
|
102
|
+
```shell
|
|
103
|
+
$ fset ls
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
This will list all the Environments with the applications in each of them.
|
|
107
|
+
Output -
|
|
108
|
+
|
|
109
|
+
```shell
|
|
110
|
+
demo
|
|
111
|
+
--Google Chrome
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
To see detailed list, with application path and URL(s) or file(s) for each application, type this command -
|
|
115
|
+
|
|
116
|
+
```shell
|
|
117
|
+
$ fset ls -l
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
or
|
|
121
|
+
|
|
122
|
+
```shell
|
|
123
|
+
$ fset ls -long
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Output -
|
|
127
|
+
|
|
128
|
+
```shell
|
|
129
|
+
demo
|
|
130
|
+
--Google Chrome
|
|
131
|
+
> App Path: "C:\Users\Public\Desktop\Google Chrome.lnk"
|
|
132
|
+
> URls:
|
|
133
|
+
1: https://clandor.com
|
|
134
|
+
```
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import Conf from "conf";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { input, confirm } from "@inquirer/prompts";
|
|
4
|
+
|
|
5
|
+
const conf = new Conf({ projectName: "fset" });
|
|
6
|
+
|
|
7
|
+
// The styling(theme) of the input interface need to be refined.
|
|
8
|
+
async function createEnv(newEnv) {
|
|
9
|
+
let environments = conf.get();
|
|
10
|
+
|
|
11
|
+
const envNames = Object.keys(environments);
|
|
12
|
+
|
|
13
|
+
if (envNames.length === 0) {
|
|
14
|
+
environments = {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (envNames.includes(newEnv)) {
|
|
18
|
+
console.error(
|
|
19
|
+
chalk.redBright(
|
|
20
|
+
`${newEnv} already exists.\nUse ${chalk.magenta("fset remove <env-name>")} to delete and set a new one of same name.`,
|
|
21
|
+
),
|
|
22
|
+
);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
environments.newEnv = [];
|
|
27
|
+
let gettingNewApplication = true;
|
|
28
|
+
let applicatonNumber = 1;
|
|
29
|
+
|
|
30
|
+
while (gettingNewApplication) {
|
|
31
|
+
console.log(chalk.blue.bold(`Application ${applicatonNumber}`));
|
|
32
|
+
|
|
33
|
+
const appPath = await input({
|
|
34
|
+
message: chalk.greenBright("Enter the path to the app:"),
|
|
35
|
+
required: true,
|
|
36
|
+
});
|
|
37
|
+
let gettingURLs = true;
|
|
38
|
+
let urlNumber = 1;
|
|
39
|
+
const urls = [];
|
|
40
|
+
|
|
41
|
+
console.log(
|
|
42
|
+
chalk.magenta(
|
|
43
|
+
"Enter URL(s) or file path(s) you want the app to open with.\nPress enter with an empty input to exit the input interface.",
|
|
44
|
+
),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
while (gettingURLs) {
|
|
48
|
+
const url = await input({ message: `URL-${urlNumber}:` });
|
|
49
|
+
|
|
50
|
+
if (url.trim()) {
|
|
51
|
+
urls.push(url);
|
|
52
|
+
urlNumber++;
|
|
53
|
+
} else {
|
|
54
|
+
gettingURLs = false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const appObj = {
|
|
59
|
+
app: appPath,
|
|
60
|
+
urls_or_paths: urls,
|
|
61
|
+
};
|
|
62
|
+
environments.newEnv.push(appObj);
|
|
63
|
+
applicatonNumber++;
|
|
64
|
+
|
|
65
|
+
const addMoreApp = await confirm({ message: "Add another app?" });
|
|
66
|
+
if (!addMoreApp) {
|
|
67
|
+
gettingNewApplication = false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
conf.set(newEnv, environments.newEnv);
|
|
72
|
+
|
|
73
|
+
console.log(chalk.bold(`\n${newEnv} created successfully.`));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default async function create(newEnv) {
|
|
77
|
+
try {
|
|
78
|
+
await createEnv(newEnv);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (error instanceof Error && error.name === "ExitPromptError") {
|
|
81
|
+
console.log(chalk.magenta("See you soon 🫡"));
|
|
82
|
+
} else {
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
package/commands/ls.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import Conf from "conf";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
const conf = new Conf({ projectName: "fset" });
|
|
6
|
+
|
|
7
|
+
export default function ls({ long }) {
|
|
8
|
+
const environments = conf.get();
|
|
9
|
+
|
|
10
|
+
const envNames = Object.keys(environments);
|
|
11
|
+
|
|
12
|
+
if (envNames.length === 0) {
|
|
13
|
+
console.log(chalk.blueBright("You don't have any environment set up yet."));
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
for (const env of envNames) {
|
|
18
|
+
console.log(chalk.green.bold(env));
|
|
19
|
+
|
|
20
|
+
const space = environments[env];
|
|
21
|
+
|
|
22
|
+
for (const application of space) {
|
|
23
|
+
const appName = extractAppName(application);
|
|
24
|
+
|
|
25
|
+
console.log(chalk.magentaBright(" -- " + appName));
|
|
26
|
+
|
|
27
|
+
if (long) {
|
|
28
|
+
console.log(
|
|
29
|
+
chalk.bold(" > App Path: ") + chalk.blue(application.app),
|
|
30
|
+
);
|
|
31
|
+
console.log(chalk.bold(" > URls: "));
|
|
32
|
+
|
|
33
|
+
const urls = application.urls_or_paths;
|
|
34
|
+
|
|
35
|
+
urls.forEach((url, index) => {
|
|
36
|
+
console.log(` ${index + 1}: ` + chalk.grey(url));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function extractAppName(application) {
|
|
44
|
+
const appPathWithoutExtention = application.app.split(".")[0];
|
|
45
|
+
const appPathSplit = appPathWithoutExtention.split(path.sep);
|
|
46
|
+
const appName = appPathSplit[appPathSplit.length - 1];
|
|
47
|
+
return appName;
|
|
48
|
+
}
|
package/commands/open.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import Conf from "conf";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { exec } from "node:child_process";
|
|
4
|
+
|
|
5
|
+
const conf = new Conf({ projectName: "fset" });
|
|
6
|
+
|
|
7
|
+
export default function open(env) {
|
|
8
|
+
const environments = conf.get();
|
|
9
|
+
|
|
10
|
+
const envNames = Object.keys(environments);
|
|
11
|
+
|
|
12
|
+
if (envNames.length === 0) {
|
|
13
|
+
console.error(
|
|
14
|
+
chalk.red(
|
|
15
|
+
`\nYou don't have any environment set up yet \n${chalk.white(`Use ${chalk.blue("fset create <env>")} to set up a new environment`)}`,
|
|
16
|
+
),
|
|
17
|
+
);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const toBeOpenedEnvironment = environments[env];
|
|
22
|
+
|
|
23
|
+
if (toBeOpenedEnvironment) {
|
|
24
|
+
console.log(`Opening ${env}\n`);
|
|
25
|
+
|
|
26
|
+
for (const app of toBeOpenedEnvironment) {
|
|
27
|
+
let paths = "";
|
|
28
|
+
|
|
29
|
+
app.urls_or_paths.forEach((urlOrPath) => {
|
|
30
|
+
paths += `"${urlOrPath}" `;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
exec(`start "" ${app.app} ${paths}`, (error, stdout, stderr) => {
|
|
34
|
+
if (error) {
|
|
35
|
+
console.error(`exec error: ${error}`);
|
|
36
|
+
console.log(
|
|
37
|
+
chalk.magenta(
|
|
38
|
+
"Tip: " +
|
|
39
|
+
`Check the App path/name for correctness. \nUse ${chalk.white("fset ls -l")} to see the saved path/name`,
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
console.error(
|
|
48
|
+
chalk.red.bold(
|
|
49
|
+
`Environment with name ${env} is not found, check the spelling for any mistake.`,
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import Conf from "conf";
|
|
3
|
+
import { confirm } from "@inquirer/prompts";
|
|
4
|
+
|
|
5
|
+
const conf = new Conf({ projectName: "fset" });
|
|
6
|
+
|
|
7
|
+
export default async function remove(env) {
|
|
8
|
+
const environments = conf.get();
|
|
9
|
+
|
|
10
|
+
const envNames = Object.keys(environments);
|
|
11
|
+
|
|
12
|
+
if (envNames.length === 0) {
|
|
13
|
+
console.log(chalk.cyan("You don't have any environment set up yet."));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (envNames.includes(env)) {
|
|
18
|
+
const isRemovePermissionGiven = await confirm({
|
|
19
|
+
message: `Are you sure you want to delete ${env}`,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (isRemovePermissionGiven) {
|
|
23
|
+
conf.delete(env);
|
|
24
|
+
console.log(chalk.green(`Deletion of '${env}' completed.`));
|
|
25
|
+
} else {
|
|
26
|
+
console.log(chalk.cyan(`Deletion of '${env}' aborted. Phew.`));
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
console.error(chalk.red(`${env} doesn't exist.`));
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { program } from "commander";
|
|
4
|
+
import open from "./commands/open.js";
|
|
5
|
+
import create from "./commands/create.js";
|
|
6
|
+
import remove from "./commands/remove.js";
|
|
7
|
+
import ls from "./commands/ls.js";
|
|
8
|
+
|
|
9
|
+
program
|
|
10
|
+
.command("open")
|
|
11
|
+
.argument("<env>", "environment to be opened.")
|
|
12
|
+
.description("open your desired environment.")
|
|
13
|
+
.action(open);
|
|
14
|
+
|
|
15
|
+
program
|
|
16
|
+
.command("create")
|
|
17
|
+
.argument("<env>", "name of the new environment.")
|
|
18
|
+
.description("create a new environment in your machine.")
|
|
19
|
+
.action(create);
|
|
20
|
+
|
|
21
|
+
program
|
|
22
|
+
.command("remove")
|
|
23
|
+
.argument("<env>", "name of the environment to be deleted.")
|
|
24
|
+
.description("delete an environment from your machine.")
|
|
25
|
+
.action(remove);
|
|
26
|
+
|
|
27
|
+
program
|
|
28
|
+
.command("ls")
|
|
29
|
+
.option("-l, --long", "display long list of environments")
|
|
30
|
+
.description("list all the environments set up in your machine")
|
|
31
|
+
.action((long) => ls(long));
|
|
32
|
+
|
|
33
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fusionfroze/fset",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Launch your required environment instantly",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "FusionFroze",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"directories": {
|
|
10
|
+
"lib": "lib"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@inquirer/prompts": "^8.3.2",
|
|
17
|
+
"chalk": "^5.6.2",
|
|
18
|
+
"commander": "^14.0.3",
|
|
19
|
+
"conf": "^15.1.0",
|
|
20
|
+
"inquirer": "^13.3.2"
|
|
21
|
+
},
|
|
22
|
+
"bin": {
|
|
23
|
+
"fset": "./index.js"
|
|
24
|
+
}
|
|
25
|
+
}
|