taskforge-cli 0.0.1 → 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/LICENCE +21 -21
- package/README.md +83 -83
- package/dist/bin/index.js +164 -112
- package/dist/exports/{config.d.cts → config.d.ts} +2 -1
- package/package.json +11 -4
- package/dist/exports/config.d.mts +0 -60
package/LICENCE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Nirvik Purkait
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Nirvik Purkait
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
# Why `taskforge-cli`
|
|
2
|
-
|
|
3
|
-
Have you ever been frustrated of changing `env` variable for stanalone projects, where no build tools are used, or doesnot support loading `env` variables out of the box, and you Have to use packages like `dotenv`.
|
|
4
|
-
|
|
5
|
-
One down side is that for each mode (development / test / production), you have to keep changing the values according to the mode. Well `taskforge-cli` lets you do that out of the box.
|
|
6
|
-
|
|
7
|
-
You can achieve this with the help of a config file `tf.config.ts|js`, and as well as cli options.
|
|
8
|
-
|
|
9
|
-
## Config file
|
|
10
|
-
|
|
11
|
-
In config file you can `defult` export an `Config` object or a `defineConfig()` function which takes an object as a parameter or a function that returns an object as a parameter.
|
|
12
|
-
|
|
13
|
-
## How to use it
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
// package.json
|
|
17
|
-
|
|
18
|
-
...
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tf build", // predefined script dev | build | test
|
|
21
|
-
"foo": "tf
|
|
22
|
-
"bar": "tf
|
|
23
|
-
"bazz": "tf
|
|
24
|
-
},
|
|
25
|
-
...
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
```ts
|
|
29
|
-
export default defineConfig({
|
|
30
|
-
scripts: {
|
|
31
|
-
build: {
|
|
32
|
-
execute: "node index.ts", // loads production env
|
|
33
|
-
},
|
|
34
|
-
foo: {
|
|
35
|
-
execute: "node foo.ts", // loads ".env" by default unless specified
|
|
36
|
-
},
|
|
37
|
-
bar: {
|
|
38
|
-
execute: "node bar.ts", // loads ".env.bar"
|
|
39
|
-
envFile: "./env/.env.bar",
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## Options:
|
|
46
|
-
|
|
47
|
-
### Config:
|
|
48
|
-
|
|
49
|
-
**cli option**: `--config`
|
|
50
|
-
|
|
51
|
-
**alias**: `-c`
|
|
52
|
-
|
|
53
|
-
**type**: `string`
|
|
54
|
-
|
|
55
|
-
**defult**:
|
|
56
|
-
|
|
57
|
-
If your config file is not at the root of your project, provide a relative path to the config file.
|
|
58
|
-
|
|
59
|
-
### Env file:
|
|
60
|
-
|
|
61
|
-
**cli option**: `--envFile`
|
|
62
|
-
|
|
63
|
-
**type**: `string`
|
|
64
|
-
|
|
65
|
-
Pass a specific env file for that script.
|
|
66
|
-
|
|
67
|
-
### Env directory:
|
|
68
|
-
|
|
69
|
-
**cli option**: `--envDir`
|
|
70
|
-
|
|
71
|
-
**type**: `string`
|
|
72
|
-
|
|
73
|
-
Pass a directory where your env files lives. It will load preferred `env` file depending on the script type.
|
|
74
|
-
|
|
75
|
-
If script is predefined i.e: dev | build | test, it will laod related `env` file, and if the script is custom it will load defult `.env` file.
|
|
76
|
-
|
|
77
|
-
### Executing command:
|
|
78
|
-
|
|
79
|
-
**cli option**: `--exec`
|
|
80
|
-
|
|
81
|
-
**type**: `string`
|
|
82
|
-
|
|
83
|
-
Pass a command that should execute for that script.
|
|
1
|
+
# Why `taskforge-cli`
|
|
2
|
+
|
|
3
|
+
Have you ever been frustrated of changing `env` variable for stanalone projects, where no build tools are used, or doesnot support loading `env` variables out of the box, and you Have to use packages like `dotenv`.
|
|
4
|
+
|
|
5
|
+
One down side is that for each mode (development / test / production), you have to keep changing the values according to the mode. Well `taskforge-cli` lets you do that out of the box.
|
|
6
|
+
|
|
7
|
+
You can achieve this with the help of a config file `tf.config.ts|js`, and as well as cli options.
|
|
8
|
+
|
|
9
|
+
## Config file
|
|
10
|
+
|
|
11
|
+
In config file you can `defult` export an `Config` object or a `defineConfig()` function which takes an object as a parameter or a function that returns an object as a parameter.
|
|
12
|
+
|
|
13
|
+
## How to use it
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
// package.json
|
|
17
|
+
|
|
18
|
+
...
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tf build", // predefined script dev | build | test
|
|
21
|
+
"foo": "tf run foo", // custom script needs a "run" keyword
|
|
22
|
+
"bar": "tf run bar", // custom script needs a "run" keyword
|
|
23
|
+
"bazz": "tf run bazz --envFile ./.env.bazz", // custom script, loads ".env.bazz"
|
|
24
|
+
},
|
|
25
|
+
...
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
export default defineConfig({
|
|
30
|
+
scripts: {
|
|
31
|
+
build: {
|
|
32
|
+
execute: "node index.ts", // loads production env
|
|
33
|
+
},
|
|
34
|
+
foo: {
|
|
35
|
+
execute: "node foo.ts", // loads ".env" by default unless specified
|
|
36
|
+
},
|
|
37
|
+
bar: {
|
|
38
|
+
execute: "node bar.ts", // loads ".env.bar"
|
|
39
|
+
envFile: "./env/.env.bar",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Options:
|
|
46
|
+
|
|
47
|
+
### Config file location:
|
|
48
|
+
|
|
49
|
+
**cli option**: `--config`
|
|
50
|
+
|
|
51
|
+
**alias**: `-c`
|
|
52
|
+
|
|
53
|
+
**type**: `string`
|
|
54
|
+
|
|
55
|
+
**defult**: `./tf.config.js|cjs|mjs|ts`
|
|
56
|
+
|
|
57
|
+
If your config file is not at the root of your project, provide a relative path to the config file. i.e: `../config/tf.config.ts`
|
|
58
|
+
|
|
59
|
+
### Env file:
|
|
60
|
+
|
|
61
|
+
**cli option**: `--envFile`
|
|
62
|
+
|
|
63
|
+
**type**: `string`
|
|
64
|
+
|
|
65
|
+
Pass a specific env file for that script.
|
|
66
|
+
|
|
67
|
+
### Env directory:
|
|
68
|
+
|
|
69
|
+
**cli option**: `--envDir`
|
|
70
|
+
|
|
71
|
+
**type**: `string`
|
|
72
|
+
|
|
73
|
+
Pass a directory where your env files lives. It will load preferred `env` file depending on the script type.
|
|
74
|
+
|
|
75
|
+
If script is predefined i.e: dev | build | test, it will laod related `env` file, and if the script is custom it will load defult `.env` file.
|
|
76
|
+
|
|
77
|
+
### Executing command:
|
|
78
|
+
|
|
79
|
+
**cli option**: `--exec`
|
|
80
|
+
|
|
81
|
+
**type**: `string`
|
|
82
|
+
|
|
83
|
+
Pass a command that should execute for that script.
|
package/dist/bin/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var jiti = require('jiti');
|
|
5
|
-
var node_process = require('node:process');
|
|
6
|
-
var dotenv = require('dotenv');
|
|
7
4
|
var path = require('node:path');
|
|
8
5
|
var node_fs = require('node:fs');
|
|
9
6
|
var config = require('../config-qD-eCtlL.js');
|
|
7
|
+
var jiti = require('jiti');
|
|
8
|
+
var node_process = require('node:process');
|
|
9
|
+
var dotenv = require('dotenv');
|
|
10
10
|
var node_child_process = require('node:child_process');
|
|
11
11
|
require('zod');
|
|
12
12
|
|
|
@@ -35,165 +35,217 @@ const testEnvFileLoadingOrder = [
|
|
|
35
35
|
".env.local",
|
|
36
36
|
".env"
|
|
37
37
|
];
|
|
38
|
+
const defaultEnvFileLoadingOrder = [
|
|
39
|
+
//
|
|
40
|
+
".env.local",
|
|
41
|
+
".env"
|
|
42
|
+
];
|
|
38
43
|
|
|
39
|
-
|
|
40
|
-
function identifyScript() {
|
|
44
|
+
function identifyScript(passedArguments) {
|
|
41
45
|
if (passedArguments.includes("dev")) {
|
|
42
46
|
return "dev";
|
|
43
47
|
} else if (passedArguments.includes("build")) {
|
|
44
48
|
return "build";
|
|
45
49
|
} else if (passedArguments.includes("test")) {
|
|
46
50
|
return "test";
|
|
47
|
-
} else if (passedArguments.includes("
|
|
48
|
-
return passedArguments[passedArguments.findIndex((value) => value === "
|
|
51
|
+
} else if (passedArguments.includes("run")) {
|
|
52
|
+
return passedArguments[passedArguments.findIndex((value) => value === "run") + 1];
|
|
49
53
|
} else
|
|
50
54
|
throw new Error(
|
|
51
|
-
'No script is passed.\nIf you have a custom scripts other than predefined scripts use "tf
|
|
55
|
+
'No script is passed.\nIf you have a custom scripts other than predefined scripts use "tf run <script-name>".\nRemember, the script name must be next to the `run` keyword'
|
|
52
56
|
);
|
|
53
57
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
);
|
|
62
|
-
if (finalConfig?.scripts?.dev?.envFile) {
|
|
63
|
-
envFilePath = finalConfig.scripts.dev.envFile;
|
|
58
|
+
function availableEnvFile({
|
|
59
|
+
scriptName,
|
|
60
|
+
scanningDir
|
|
61
|
+
}) {
|
|
62
|
+
if (!scanningDir) {
|
|
63
|
+
if (scriptName === "dev") {
|
|
64
|
+
return resolveEnvFile(developmentEnvFileLoadingOrder, "");
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
productionEnvFileLoadingOrder,
|
|
68
|
-
finalConfig?.envDir ?? finalConfig?.scripts?.build?.envDir ?? process.cwd()
|
|
69
|
-
);
|
|
70
|
-
if (finalConfig?.scripts?.build?.envFile) {
|
|
71
|
-
envFilePath = finalConfig.scripts.build.envFile;
|
|
66
|
+
if (scriptName === "build") {
|
|
67
|
+
return resolveEnvFile(productionEnvFileLoadingOrder, "");
|
|
72
68
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
testEnvFileLoadingOrder,
|
|
76
|
-
finalConfig?.envDir ?? finalConfig?.scripts?.test?.envDir ?? process.cwd()
|
|
77
|
-
);
|
|
78
|
-
if (finalConfig?.scripts?.test?.envFile) {
|
|
79
|
-
envFilePath = finalConfig.scripts.test.envFile;
|
|
80
|
-
}
|
|
81
|
-
} else {
|
|
82
|
-
envFilePath = path.join(
|
|
83
|
-
finalConfig?.envDir ?? finalConfig?.scripts?.[scriptName]?.envDir ?? process.cwd(),
|
|
84
|
-
".env"
|
|
85
|
-
);
|
|
86
|
-
if (finalConfig?.scripts?.[scriptName]?.envFile) {
|
|
87
|
-
envFilePath = finalConfig.scripts?.[scriptName].envFile;
|
|
69
|
+
if (scriptName === "test") {
|
|
70
|
+
return resolveEnvFile(testEnvFileLoadingOrder, "");
|
|
88
71
|
}
|
|
72
|
+
return resolveEnvFile(defaultEnvFileLoadingOrder, "");
|
|
89
73
|
}
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
74
|
+
if (scriptName === "dev") {
|
|
75
|
+
return resolveEnvFile(developmentEnvFileLoadingOrder, scanningDir);
|
|
76
|
+
}
|
|
77
|
+
if (scriptName === "build") {
|
|
78
|
+
return resolveEnvFile(productionEnvFileLoadingOrder, scanningDir);
|
|
79
|
+
}
|
|
80
|
+
if (scriptName === "test") {
|
|
81
|
+
return resolveEnvFile(testEnvFileLoadingOrder, scanningDir);
|
|
82
|
+
}
|
|
83
|
+
return resolveEnvFile(defaultEnvFileLoadingOrder, scanningDir);
|
|
84
|
+
function resolveEnvFile(fileOrder, dir) {
|
|
85
|
+
for (const file of fileOrder) {
|
|
86
|
+
const fullPath = path.join(dir, file);
|
|
87
|
+
if (node_fs.existsSync(fullPath)) {
|
|
88
|
+
return fullPath;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
94
92
|
}
|
|
95
|
-
process.env.NODE_ENV = scriptName === "dev" ? "development" : scriptName === "build" ? "production" : scriptName === "test" ? "test" : void 0;
|
|
96
|
-
dotenv.config({ path: envFilePath, quiet: true, override: true });
|
|
97
|
-
}
|
|
98
|
-
function availableFile(fileOrder, scanningDir) {
|
|
99
|
-
return fileOrder.map((f) => path.join(scanningDir, f)).find((f) => node_fs.existsSync(f));
|
|
100
93
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
94
|
+
function extractCliOptions(passedArguments) {
|
|
95
|
+
const arbitaryCliArgumets = [];
|
|
96
|
+
const scriptName = identifyScript(passedArguments);
|
|
97
|
+
let shouldSkipNextArgument = false;
|
|
98
|
+
let cliOptions = {};
|
|
104
99
|
passedArguments.forEach((arg, idx) => {
|
|
105
|
-
if (!(arg === scriptName || arg === "
|
|
106
|
-
|
|
100
|
+
if (!(arg === scriptName || arg === "run")) {
|
|
101
|
+
arbitaryCliArgumets.push(arg);
|
|
102
|
+
if (shouldSkipNextArgument) {
|
|
103
|
+
arbitaryCliArgumets.pop();
|
|
104
|
+
shouldSkipNextArgument = !shouldSkipNextArgument;
|
|
105
|
+
}
|
|
107
106
|
}
|
|
108
107
|
if (arg === "-c" || arg === "--config") {
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
cliOptions.configFileLocation = passedArguments[idx + 1];
|
|
109
|
+
arbitaryCliArgumets.pop();
|
|
110
|
+
shouldSkipNextArgument = true;
|
|
111
111
|
}
|
|
112
112
|
if (arg.startsWith("-c=") || arg.startsWith("--config=")) {
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
cliOptions.configFileLocation = arg.split("=")[1];
|
|
114
|
+
arbitaryCliArgumets.pop();
|
|
115
115
|
}
|
|
116
116
|
if (arg === "--envFile") {
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
cliOptions.envFile = passedArguments[idx + 1];
|
|
118
|
+
arbitaryCliArgumets.pop();
|
|
119
|
+
shouldSkipNextArgument = true;
|
|
119
120
|
}
|
|
120
121
|
if (arg.startsWith("--envFile=")) {
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
cliOptions.envFile = arg.split("=")[1];
|
|
123
|
+
arbitaryCliArgumets.pop();
|
|
123
124
|
}
|
|
124
125
|
if (arg === "--envDir") {
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
cliOptions.envDir = passedArguments[idx + 1];
|
|
127
|
+
arbitaryCliArgumets.pop();
|
|
128
|
+
shouldSkipNextArgument = true;
|
|
127
129
|
}
|
|
128
130
|
if (arg.startsWith("--envDir=")) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
cliOptions.envDir = arg.split("=")[1];
|
|
132
|
+
arbitaryCliArgumets.pop();
|
|
131
133
|
}
|
|
132
134
|
if (arg === "--exec") {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
cliOptions.execute = passedArguments[idx + 1];
|
|
136
|
+
arbitaryCliArgumets.pop();
|
|
137
|
+
shouldSkipNextArgument = true;
|
|
135
138
|
}
|
|
136
139
|
if (arg.startsWith("--exec=")) {
|
|
137
|
-
|
|
138
|
-
|
|
140
|
+
cliOptions.execute = arg.split("=")[1];
|
|
141
|
+
arbitaryCliArgumets.pop();
|
|
142
|
+
}
|
|
143
|
+
if (arg === "--shell") {
|
|
144
|
+
const passedArgument = passedArguments[idx + 1];
|
|
145
|
+
if (passedArgument === "false") cliOptions.shell = false;
|
|
146
|
+
if (passedArgument === "true") cliOptions.shell = true;
|
|
147
|
+
cliOptions.execute = passedArgument;
|
|
148
|
+
arbitaryCliArgumets.pop();
|
|
149
|
+
shouldSkipNextArgument = true;
|
|
150
|
+
}
|
|
151
|
+
if (arg.startsWith("--shell=")) {
|
|
152
|
+
const passedArgument = arg.split("=")[1];
|
|
153
|
+
if (passedArgument === "false") cliOptions.shell = false;
|
|
154
|
+
if (passedArgument === "true") cliOptions.shell = true;
|
|
155
|
+
cliOptions.execute = passedArgument;
|
|
156
|
+
arbitaryCliArgumets.pop();
|
|
139
157
|
}
|
|
140
158
|
});
|
|
141
|
-
if (Object.keys(
|
|
142
|
-
return void 0;
|
|
159
|
+
if (Object.keys(cliOptions).length === 0) {
|
|
160
|
+
return { cliOptions: void 0, arbitaryCliArgumets };
|
|
143
161
|
}
|
|
144
|
-
return
|
|
162
|
+
return { cliOptions, arbitaryCliArgumets };
|
|
163
|
+
}
|
|
164
|
+
function extractScriptRelatedCliOptions(passedArguments) {
|
|
165
|
+
const { cliOptions: cliOptionsPassedThroughScript } = extractCliOptions(passedArguments);
|
|
166
|
+
const scriptRelatedCliOptions = { ...cliOptionsPassedThroughScript };
|
|
167
|
+
delete scriptRelatedCliOptions?.configFileLocation;
|
|
168
|
+
const scriptName = identifyScript(passedArguments);
|
|
169
|
+
const configurationFromCliOption = {
|
|
170
|
+
[scriptName]: { ...scriptRelatedCliOptions }
|
|
171
|
+
};
|
|
172
|
+
return configurationFromCliOption;
|
|
145
173
|
}
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
function executeConfigFile() {
|
|
150
|
-
const determinedConfigFileLocation = cliOptions?.configFileLocation ?? availableFile(validConfigFilesOrder, process.cwd());
|
|
174
|
+
function executeConfigFile(passedArguments) {
|
|
175
|
+
const { cliOptions } = extractCliOptions(passedArguments);
|
|
176
|
+
const determinedConfigFileLocation = cliOptions?.configFileLocation ?? resolveConfigFile(validConfigFilesOrder, process.cwd());
|
|
151
177
|
if (!determinedConfigFileLocation) {
|
|
152
|
-
console.
|
|
178
|
+
console.error("No config file found");
|
|
153
179
|
return;
|
|
154
180
|
}
|
|
155
181
|
const jiti$1 = jiti.createJiti((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('bin/index.js', document.baseURI).href)), {
|
|
156
182
|
interopDefault: true
|
|
157
183
|
});
|
|
158
184
|
const moduleFromConfigFile = jiti$1(path.resolve(determinedConfigFileLocation));
|
|
159
|
-
const
|
|
160
|
-
const parsedConfig = config.configSchema.safeParse(
|
|
185
|
+
const config$1 = moduleFromConfigFile?.default ?? moduleFromConfigFile;
|
|
186
|
+
const parsedConfig = config.configSchema.safeParse(config$1);
|
|
161
187
|
if (!parsedConfig.success) {
|
|
162
188
|
throw new Error("Something is wrong with config file. Please correct it");
|
|
163
189
|
}
|
|
164
190
|
return parsedConfig.data;
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
...scriptRelatedCliOptions
|
|
191
|
+
function resolveConfigFile(fileOrder, dir) {
|
|
192
|
+
for (const file of fileOrder) {
|
|
193
|
+
const fullPath = path.join(dir, file);
|
|
194
|
+
if (node_fs.existsSync(fullPath)) {
|
|
195
|
+
return fullPath;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
174
199
|
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
};
|
|
200
|
+
}
|
|
201
|
+
function finalizedConfigFromAllSources(passedArguments) {
|
|
202
|
+
const configFromConfigFile = executeConfigFile(passedArguments);
|
|
203
|
+
const scriptRelatedCliOptions = extractScriptRelatedCliOptions(passedArguments);
|
|
204
|
+
const scriptsDetailsFromConfigFile = configFromConfigFile && configFromConfigFile.scripts || {};
|
|
205
|
+
const scriptName = identifyScript(passedArguments);
|
|
206
|
+
const mergedScriptDetails = {
|
|
207
|
+
...scriptsDetailsFromConfigFile,
|
|
208
|
+
[scriptName]: {
|
|
209
|
+
...scriptsDetailsFromConfigFile[scriptName] || {},
|
|
210
|
+
...scriptRelatedCliOptions
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
const finalConfig = {
|
|
214
|
+
...configFromConfigFile,
|
|
215
|
+
scripts: { ...mergedScriptDetails }
|
|
216
|
+
};
|
|
217
|
+
return finalConfig;
|
|
218
|
+
}
|
|
180
219
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
});
|
|
190
|
-
process.stdout.on("data", (chunk) => {
|
|
191
|
-
console.log(chunk.toString());
|
|
192
|
-
});
|
|
193
|
-
process.stderr.on("data", (chunk) => {
|
|
194
|
-
console.error(chunk.toString());
|
|
220
|
+
const passedArguments = node_process.argv.slice(2);
|
|
221
|
+
(() => {
|
|
222
|
+
const scriptName = identifyScript(passedArguments);
|
|
223
|
+
const finalConfig = finalizedConfigFromAllSources(passedArguments);
|
|
224
|
+
const { arbitaryCliArgumets } = extractCliOptions(passedArguments);
|
|
225
|
+
const envFileToLoad = availableEnvFile({
|
|
226
|
+
scriptName,
|
|
227
|
+
scanningDir: finalConfig.envDir
|
|
195
228
|
});
|
|
196
|
-
|
|
197
|
-
console.
|
|
229
|
+
if (!envFileToLoad) {
|
|
230
|
+
console.error("No env file is provided");
|
|
231
|
+
}
|
|
232
|
+
dotenv.config({
|
|
233
|
+
path: path.join(node_process.cwd(), envFileToLoad || ""),
|
|
234
|
+
quiet: true
|
|
198
235
|
});
|
|
199
|
-
|
|
236
|
+
if (finalConfig?.scripts?.[scriptName]?.execute) {
|
|
237
|
+
const executableCommand = finalConfig.scripts[scriptName].execute.split(",");
|
|
238
|
+
const executable = executableCommand[0];
|
|
239
|
+
const commandArgs = executableCommand.slice(1).concat(arbitaryCliArgumets);
|
|
240
|
+
const executingProcess = node_child_process.spawn(`${executable} ${commandArgs.join(" ")}`, {
|
|
241
|
+
stdio: "inherit",
|
|
242
|
+
// Use shell mode unless explicitly disabled in config
|
|
243
|
+
shell: finalConfig.scripts[scriptName].shell ?? true
|
|
244
|
+
});
|
|
245
|
+
executingProcess.on("exit", (code, signal) => {
|
|
246
|
+
console.log(`Process exited with code ${code}, signal ${signal}`);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
})();
|
|
250
|
+
|
|
251
|
+
exports.passedArguments = passedArguments;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { CommonSpawnOptions } from 'node:child_process';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
|
|
3
4
|
type ScriptDetails = {
|
|
4
5
|
envFile?: string;
|
|
5
6
|
execute: string;
|
|
6
7
|
envDir?: string;
|
|
7
|
-
}
|
|
8
|
+
} & Partial<Pick<CommonSpawnOptions, "shell">>;
|
|
8
9
|
type Scripts = {
|
|
9
10
|
dev?: ScriptDetails;
|
|
10
11
|
build?: ScriptDetails;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "taskforge-cli",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A cli tool to leverage env related headache",
|
|
5
5
|
"lint-staged": {
|
|
6
6
|
"src/**/*.ts": "pnpm format"
|
|
@@ -9,20 +9,23 @@
|
|
|
9
9
|
"prebuild": "rimraf ./dist",
|
|
10
10
|
"build": "pkgroll",
|
|
11
11
|
"format": "prettier --write src/**/*.ts",
|
|
12
|
-
"test": "
|
|
12
|
+
"test:unit": "vitest",
|
|
13
|
+
"test:unit:coverage": "vitest --coverage.enabled",
|
|
13
14
|
"pre-commit": "lint-staged"
|
|
14
15
|
},
|
|
15
16
|
"bin": {
|
|
16
17
|
"tf": "dist/bin/index.js"
|
|
17
18
|
},
|
|
19
|
+
"types": "./dist/**/*.d.ts",
|
|
18
20
|
"exports": {
|
|
19
21
|
"./config": {
|
|
22
|
+
"types": {
|
|
23
|
+
"default": "./dist/exports/config.d.ts"
|
|
24
|
+
},
|
|
20
25
|
"require": {
|
|
21
|
-
"types": "./dist/exports/config.d.cts",
|
|
22
26
|
"default": "./dist/exports/config.cjs"
|
|
23
27
|
},
|
|
24
28
|
"import": {
|
|
25
|
-
"types": "./dist/exports/config.d.mts",
|
|
26
29
|
"default": "./dist/exports/config.mjs"
|
|
27
30
|
}
|
|
28
31
|
}
|
|
@@ -52,12 +55,16 @@
|
|
|
52
55
|
"dependencies": {
|
|
53
56
|
"dotenv": "^17.2.3",
|
|
54
57
|
"jiti": "^2.6.1",
|
|
58
|
+
"vite-tsconfig-paths": "^6.0.4",
|
|
59
|
+
"vitest": "^4.0.17",
|
|
55
60
|
"zod": "^4.2.1"
|
|
56
61
|
},
|
|
57
62
|
"devDependencies": {
|
|
58
63
|
"@types/node": "^25.0.3",
|
|
64
|
+
"@vitest/coverage-v8": "4.0.17",
|
|
59
65
|
"husky": "^9.1.7",
|
|
60
66
|
"lint-staged": "^16.2.7",
|
|
67
|
+
"memfs": "^4.51.1",
|
|
61
68
|
"pkgroll": "^2.21.4",
|
|
62
69
|
"prettier": "^3.7.4",
|
|
63
70
|
"rimraf": "^6.1.2",
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
type ScriptDetails = {
|
|
4
|
-
envFile?: string;
|
|
5
|
-
execute: string;
|
|
6
|
-
envDir?: string;
|
|
7
|
-
};
|
|
8
|
-
type Scripts = {
|
|
9
|
-
dev?: ScriptDetails;
|
|
10
|
-
build?: ScriptDetails;
|
|
11
|
-
test?: ScriptDetails;
|
|
12
|
-
} & Record<string, ScriptDetails>;
|
|
13
|
-
declare const configSchema: z.ZodOptional<z.ZodObject<{
|
|
14
|
-
envDir: z.ZodOptional<z.ZodString>;
|
|
15
|
-
scripts: z.ZodOptional<z.ZodCustom<Scripts, Scripts>>;
|
|
16
|
-
}, z.core.$strip>>;
|
|
17
|
-
type Config = z.infer<typeof configSchema>;
|
|
18
|
-
/**
|
|
19
|
-
* Defines and validates the CLI configuration.
|
|
20
|
-
*
|
|
21
|
-
* This helper enables strong typing and IDE autocomplete when
|
|
22
|
-
* authoring configuration files. It accepts either a plain
|
|
23
|
-
* configuration object or a factory function that returns one.
|
|
24
|
-
*
|
|
25
|
-
* When a function is provided, it is executed immediately and
|
|
26
|
-
* its return value is used as the final configuration.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* import { defineConfig } from "taskforge/config";
|
|
31
|
-
*
|
|
32
|
-
* export default defineConfig({
|
|
33
|
-
* envDir: ".",
|
|
34
|
-
* scripts: {
|
|
35
|
-
* build: {
|
|
36
|
-
* execute: "tsc"
|
|
37
|
-
* }
|
|
38
|
-
* }
|
|
39
|
-
* });
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* export default defineConfig(() => ({
|
|
45
|
-
* scripts: {
|
|
46
|
-
* dev: "pnpm dev"
|
|
47
|
-
* }
|
|
48
|
-
* }));
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* @param config - Configuration object or a function returning it
|
|
52
|
-
* @returns The resolved configuration object
|
|
53
|
-
*/
|
|
54
|
-
declare function defineConfig(config: Config | (() => Config)): {
|
|
55
|
-
envDir?: string | undefined;
|
|
56
|
-
scripts?: Scripts | undefined;
|
|
57
|
-
} | undefined;
|
|
58
|
-
|
|
59
|
-
export { defineConfig };
|
|
60
|
-
export type { Config };
|