Skip to content

Commit 04c8c11

Browse files
Improve compatibility (#7)
1 parent 9592ed5 commit 04c8c11

File tree

6 files changed

+109
-34
lines changed

6 files changed

+109
-34
lines changed

Diff for: CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 0.3.1
2+
3+
**Compatibility options**
4+
5+
`-D` | `--dev` save as dev dependency
6+
`-E` | `--exact` save exact dependency
7+
`-P` | `--peer`save as peer dependency
8+
19
# 0.2.0
210

311
### New feature

Diff for: README.md

+31-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
[<img alt="npm" src="https://img.shields.io/npm/dt/wksp?logo=npm">](https://npmjs.com/package/wksp)
44
<img alt="Maintained" src="https://img.shields.io/maintenance/yes/2022">
55

6-
yarn workspaces extension
6+
yarn **w**or**ksp**aces extension
7+
8+
> monorepo management tool
79
810
## Table of Contents:
911

@@ -31,7 +33,7 @@ npm i -g wksp
3133
wksp <cmd>
3234
```
3335

34-
> shorthand for: yarn workspace \<cmd>
36+
> shorthand for: yarn **w**or**ksp**ace \<cmd>
3537
3638
> wksp will detect the package name automatically (if run inside the project folder)
3739
@@ -41,9 +43,9 @@ if your current directory is the workspace root you can specify the name
4143
wksp -n my-app <cmd>
4244
```
4345

44-
> shorthand for: yarn workspace \<name> \<cmd>
46+
> shorthand for: yarn **w**or**ksp**ace \<name> \<cmd>
4547
46-
**Variadic arguments**
48+
### Variadic arguments
4749

4850
Variadic arguments are supported, (any arguments for the command)
4951

@@ -52,7 +54,7 @@ wksp add react react-dom react-router
5254
# cli cmd args...
5355
```
5456

55-
**Passing options**
57+
### Passing options
5658

5759
Options that are specific to yarn, require an `--` `--options`
5860

@@ -68,12 +70,28 @@ wksp start -- --port 3002 --watch
6870
# cli cmd -- script options
6971
```
7072

73+
### Compatibility options
74+
75+
`-D` or `--dev` save as dev dependency
76+
77+
`-E` or `--exact` save exact dependency
78+
79+
`-P` or `--peer` save as peer dependency
80+
81+
some terminals doesn't allow passing options `--`
82+
83+
you can use compatibility options directly:
84+
85+
> `wksp add -D typescript`
86+
7187
<!-- ## Features
7288
7389
- alias
7490
7591
- wksp dev -->
7692

93+
---
94+
7795
## Examples
7896

7997
### root
@@ -107,3 +125,11 @@ wksp start
107125

108126
Have a great idea how we can extend yarn workspaces features ?
109127
[suggest here](https://github.com/Andrew-Colman/wksp/issues/new)
128+
129+
<!-- @todo add list command -->
130+
131+
<!-- @todo add run all command -->
132+
133+
<!-- @todo package.json guide -->
134+
135+
<!-- @todo monorepo projects guide -->

Diff for: package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
{
22
"name": "wksp",
3-
"version": "0.2.0",
3+
"version": "0.3.1",
44
"main": "dist/index.js",
55
"source": "./src/index.ts",
66
"repository": "https://github.com/andrew-colman/wksp",
77
"author": {
88
"name": "Andrew Colman"
99
},
10+
"keywords": [
11+
"wksp",
12+
"monorepo management",
13+
"yarn",
14+
"workspaces",
15+
"workspace"
16+
],
1017
"license": "MIT",
1118
"bin": {
1219
"wksp": "dist/index.js"
1320
},
1421
"scripts": {
22+
"prepublishOnly": "npm run build",
1523
"build": "rollup --config rollup.config.js",
1624
"dev": "sucrase-node ./src/index.ts ",
1725
"test": "jest ",
@@ -22,7 +30,7 @@
2230
"@rollup/plugin-node-resolve": "^13.0.4",
2331
"@rollup/plugin-typescript": "^8.2.5",
2432
"@types/jest": "^27.0.1",
25-
"@types/node": "^16.3.1",
33+
"@types/node": "^16.11.2",
2634
"jest": "^27.0.6",
2735
"rollup": "^2.56.2",
2836
"rollup-plugin-preserve-shebang": "^1.0.1",

Diff for: src/program.ts

+11-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
const { Command, Argument } = require('commander');
2-
import { getVersion, Result } from 'nanov';
3-
1+
const { Command } = require('commander');
2+
import { verifyUpdates } from '@utils/verifyUpdates';
43
import { wksp } from './wksp';
54

65
require('jsonc-require');
@@ -12,38 +11,31 @@ const programVersion = 'wksp version: ' + currentVersion;
1211
* (CLI TOOL) wksp
1312
* @description yarn workspaces extension
1413
* @param {string} options - options called from cmd
15-
* @example wksp
14+
* @example wksp --help
1615
* @class Command
1716
*/
1817
const program = new Command();
1918

2019
program
2120
.version(programVersion, '-v|--version')
22-
.command('wksp', { isDefault: true })
2321
.description('yarn workspace extension tool')
24-
22+
//
2523
.option('-n, --name <name> ', 'project name (as in package.json)')
2624
.argument('[command]', "package script you'd like to run")
2725
.argument(
2826
'[variadic...]',
2927
"variadic arguments you'd like to pass to script"
3028
)
31-
29+
//compatibility
30+
.option('-D, --dev', 'save dev dependency')
31+
.option('-P, --peer', 'save peer dependency')
32+
.option('-E, --exact', 'save exact dependency')
33+
//
3234
.action((command: string, variadic: string[], options: any) =>
33-
wksp(command, variadic, options)
35+
wksp({ command, variadic, options })
3436
);
3537

3638
//verify updates
37-
program.hook('postAction', async () => {
38-
const { latestVersion } = (await getVersion('wksp', currentVersion, {
39-
cacheTime: 12,
40-
})) as Result;
41-
42-
if (latestVersion) {
43-
console.log('\n[wksp] new version available, run:');
44-
console.log('npm i -g wksp\n');
45-
console.log('to update');
46-
}
47-
});
39+
program.hook('postAction', async () => verifyUpdates(currentVersion));
4840

4941
export { program };

Diff for: src/utils/verifyUpdates.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { getVersion, Result } from 'nanov';
2+
3+
export const verifyUpdates = async (currentVersion: string) => {
4+
const { latestVersion } = (await getVersion('wksp', currentVersion, {
5+
cacheTime: 12,
6+
})) as Result;
7+
8+
if (latestVersion) {
9+
console.log('\n[wksp] new version available, run:');
10+
console.log('npm i -g wksp\n');
11+
console.log('to update');
12+
}
13+
};

Diff for: src/wksp.ts

+36-8
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,58 @@
11
import path from 'path';
22
const execa = require('execa');
3-
43
require('jsonc-require');
54

6-
export async function wksp(
7-
command: string,
8-
variadic: string[],
9-
options: { name: string }
10-
) {
5+
interface WKSP {
6+
command: string;
7+
variadic: string[];
8+
options: WKSPOptions;
9+
}
10+
11+
type WKSPOptions = {
12+
name?: string;
13+
} & CompatibilityOptions;
14+
15+
type CompatibilityOptions = {
16+
dev?: boolean;
17+
exact?: boolean;
18+
peer?: boolean;
19+
};
20+
21+
export async function wksp({ command, variadic, options }: WKSP) {
22+
//if --list @todo
23+
//if --all @todo
24+
await workspace({ command, variadic, options });
25+
}
26+
27+
async function workspace({ command, variadic, options }: WKSP) {
1128
try {
1229
const name = options.name ?? getPackageName();
1330
const cmd = command ?? '';
1431
const args = variadic ?? '';
32+
const compatibility = getCompatibilityOptions(options);
1533

16-
execa('yarn', ['workspace', name, cmd, ...args], {
34+
execa('yarn', ['workspace', name, cmd, ...args, ...compatibility], {
1735
stdio: 'inherit',
1836
}); //
1937
} catch (error) {
20-
console.log(error.message);
38+
if (error instanceof Error) console.log(error.message);
2139
}
2240
}
2341

42+
//function workspaces(params: any) {}
43+
2444
function getPackageName() {
2545
try {
2646
return require(path.resolve(process.cwd(), './package.json')).name;
2747
} catch (error) {
2848
throw 'cant find package.json';
2949
}
3050
}
51+
52+
function getCompatibilityOptions(options: CompatibilityOptions): string[] {
53+
return [
54+
options.dev && '-D',
55+
options.exact && '-E',
56+
options.peer && '-P',
57+
].filter(Boolean) as string[];
58+
}

0 commit comments

Comments
 (0)