Skip to content

Commit 4a7a93d

Browse files
authored
feat: support different configuration files for different usecases (#39)
1 parent e67433c commit 4a7a93d

15 files changed

Lines changed: 147 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ npx update-ts-references --help
2323
--createPathMappings Create paths mappings under compilerOptions for a better IDE support. It respects the rootDir if no rootDir available it falls back to "src"
2424
--cwd Set working directory. Default: /Users/john-doe/projects/my-project
2525
--verbose Show verbose output. Default: false
26+
--usecase Use a specific usecase configuration. Default: update-ts-references.yaml
2627
2728
```
2829

@@ -99,7 +100,8 @@ Additional to that you can configure also the following options:
99100

100101
Example configuration see [here](./test-scenarios/ts-options-yaml/update-ts-references.yaml)
101102

102-
103+
### using multiple configurations for different usecases
104+
Executing update-ts-references with different configurations via the parameter `--usecase`.
103105

104106
## FAQ
105107
### Why is my pnpm workspace alias not working?

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "update-ts-references",
3-
"version": "3.2.1",
3+
"version": "3.3.0",
44
"description": "Updates TypeScript references automatically while using workspaces",
55
"bin": "src/index.js",
66
"scripts": {

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
h = defaultOptions.help,
1515
check = defaultOptions.check,
1616
createPathMappings = defaultOptions.createPathMappings,
17+
usecase = defaultOptions.usecase
1718
} = minimist(process.argv.slice(2));
1819
if (help || h) {
1920
console.log(`
@@ -27,6 +28,7 @@ if (help || h) {
2728
--createPathMappings Create paths mappings under compilerOptions for a better IDE support. It respects the rootDir if no rootDir available it falls back to "src"
2829
--cwd Set working directory. Default: ${defaultOptions.cwd}
2930
--verbose Show verbose output. Default: ${defaultOptions.verbose}
31+
--usecase The use case for the script. Default: ${defaultOptions.usecase}
3032
`);
3133
process.exit(0);
3234
}
@@ -40,7 +42,8 @@ const run = async () => {
4042
configName,
4143
rootConfigName,
4244
createTsConfig,
43-
createPathMappings
45+
createPathMappings,
46+
usecase
4447
});
4548

4649
if (check && changesCount > 0) {

src/update-ts-references.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ const defaultOptions = {
2121
verbose: false,
2222
help: false,
2323
check: false,
24-
createPathMappings: false
24+
createPathMappings: false,
25+
usecase: 'update-ts-references.yaml'
2526
};
2627

2728
const getAllPackageJsons = async (workspaces, cwd) => {
@@ -230,6 +231,7 @@ const execute = async ({
230231
cwd, createTsConfig,
231232
verbose,
232233
check,
234+
usecase,
233235
...configurable
234236
}) => {
235237
let changesCount = 0;
@@ -260,9 +262,9 @@ const execute = async ({
260262
createPathMappings
261263
} = configurable
262264

263-
if (fs.existsSync(path.join(cwd, 'update-ts-references.yaml'))) {
265+
if (fs.existsSync(path.join(cwd, usecase))) {
264266
const yamlConfig = yaml.load(
265-
fs.readFileSync(path.join(cwd, 'update-ts-references.yaml'))
267+
fs.readFileSync(path.join(cwd, usecase))
266268
);
267269
configName = yamlConfig.configName ?? configName
268270
rootConfigName = yamlConfig.rootConfigName ?? rootConfigName
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "ts-ref-yaml-workspace",
3+
"version": "0.0.1",
4+
"private": true,
5+
"workspaces": [
6+
"workspace-b",
7+
"shared/*",
8+
"utils/**/"
9+
],
10+
"devDependencies": {
11+
"typescript": "latest"
12+
}
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"files": [],
3+
"compilerOptions": {
4+
/* Basic Options */
5+
// "allowJs": true,
6+
"composite": true
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
configName: 'tsconfig.dev.json'
2+
rootConfigName: 'tsconfig.root.json'
3+
createPathMappings: true
4+
packages:
5+
# all packages in subdirs of packages/ and components/
6+
- 'workspace-a'
7+
# exclude packages that are inside test directories
8+
- '!**/tests/**'
9+
- '!workspace-ignore'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "workspace-a",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"workspace-b": "1.0.0"
6+
}
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "dist",
4+
"rootDir": "src"
5+
}
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "workspace-b",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"cross-env": "5.0.5"
6+
},
7+
"devDependencies": {
8+
"foo-b": "1.0.0"
9+
}
10+
}

0 commit comments

Comments
 (0)