-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9592ed5
commit 04c8c11
Showing
6 changed files
with
109 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { getVersion, Result } from 'nanov'; | ||
|
||
export const verifyUpdates = async (currentVersion: string) => { | ||
const { latestVersion } = (await getVersion('wksp', currentVersion, { | ||
cacheTime: 12, | ||
})) as Result; | ||
|
||
if (latestVersion) { | ||
console.log('\n[wksp] new version available, run:'); | ||
console.log('npm i -g wksp\n'); | ||
console.log('to update'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,58 @@ | ||
import path from 'path'; | ||
const execa = require('execa'); | ||
|
||
require('jsonc-require'); | ||
|
||
export async function wksp( | ||
command: string, | ||
variadic: string[], | ||
options: { name: string } | ||
) { | ||
interface WKSP { | ||
command: string; | ||
variadic: string[]; | ||
options: WKSPOptions; | ||
} | ||
|
||
type WKSPOptions = { | ||
name?: string; | ||
} & CompatibilityOptions; | ||
|
||
type CompatibilityOptions = { | ||
dev?: boolean; | ||
exact?: boolean; | ||
peer?: boolean; | ||
}; | ||
|
||
export async function wksp({ command, variadic, options }: WKSP) { | ||
//if --list @todo | ||
//if --all @todo | ||
await workspace({ command, variadic, options }); | ||
} | ||
|
||
async function workspace({ command, variadic, options }: WKSP) { | ||
try { | ||
const name = options.name ?? getPackageName(); | ||
const cmd = command ?? ''; | ||
const args = variadic ?? ''; | ||
const compatibility = getCompatibilityOptions(options); | ||
|
||
execa('yarn', ['workspace', name, cmd, ...args], { | ||
execa('yarn', ['workspace', name, cmd, ...args, ...compatibility], { | ||
stdio: 'inherit', | ||
}); // | ||
} catch (error) { | ||
console.log(error.message); | ||
if (error instanceof Error) console.log(error.message); | ||
} | ||
} | ||
|
||
//function workspaces(params: any) {} | ||
|
||
function getPackageName() { | ||
try { | ||
return require(path.resolve(process.cwd(), './package.json')).name; | ||
} catch (error) { | ||
throw 'cant find package.json'; | ||
} | ||
} | ||
|
||
function getCompatibilityOptions(options: CompatibilityOptions): string[] { | ||
return [ | ||
options.dev && '-D', | ||
options.exact && '-E', | ||
options.peer && '-P', | ||
].filter(Boolean) as string[]; | ||
} |