Skip to content

Commit eeafc64

Browse files
author
Yael Brodsky
authored
allow configuration file to be specified in the command (#15)
* allow configuration file to be specified in the command * readme
1 parent e050ced commit eeafc64

File tree

4 files changed

+1132
-4
lines changed

4 files changed

+1132
-4
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Additionally, you can add it to your build scripts
4444
"name": "myproject",
4545
"version": "0.1.0",
4646
"scripts": {
47-
"dev": "etsc"
47+
"dev": "etsc"
4848
}
4949
}
5050
```
@@ -122,7 +122,15 @@ module.exports = {
122122
};
123123
```
124124

125-
All of the above fields are optional
125+
All of the above fields are optional.
126+
127+
If you want to use different config files for different types of builds you can do so using the param `--config`. Example:
128+
129+
```
130+
"scripts": {
131+
"build": "etsc --config=etsc.config.build.js"
132+
}
133+
```
126134

127135
## License
128136

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
"devDependencies": {
2525
"@types/node": "^14.6.4",
2626
"@types/rimraf": "^3.0.0",
27+
"@types/yargs": "^16.0.1",
2728
"typescript": "^4.0.2"
2829
},
2930
"dependencies": {
3031
"cpy": "^8.1.1",
3132
"esbuild": "^0.8.34",
32-
"rimraf": "^3.0.2"
33+
"rimraf": "^3.0.2",
34+
"yargs": "^16.2.0"
3335
},
3436
"peerDependencies": {
3537
"typescript": "*"

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import { build } from "esbuild";
55
import cpy from "cpy";
66
import path from "path";
77
import rimraf from "rimraf";
8+
import yargs from 'yargs/yargs';
9+
import { hideBin } from 'yargs/helpers';
10+
import { Argv } from 'yargs';
811
import { Config, readUserConfig } from "./config";
912

1013
const cwd = process.cwd();
14+
const { argv } = yargs(hideBin(process.argv));
1115

1216
function getTSConfig(_tsConfigFile = "tsconfig.json") {
1317
const tsConfigFile = ts.findConfigFile(cwd, ts.sys.fileExists, _tsConfigFile);
@@ -104,7 +108,9 @@ async function copyNonSourceFiles({
104108
}
105109

106110
async function main() {
107-
const config = await readUserConfig(path.resolve(cwd, "etsc.config.js"));
111+
const configFilename = <string>argv?.config || 'etsc.config.js';
112+
113+
const config = await readUserConfig(path.resolve(cwd, configFilename));
108114

109115
const { outDir, esbuildOptions, assetsOptions } = getBuildMetadata(config);
110116

0 commit comments

Comments
 (0)