-
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
Showing
32 changed files
with
217 additions
and
209 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,3 +115,4 @@ dist | |
.idea/ | ||
.vscode/ | ||
tools/dev | ||
.DS_Store |
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,53 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Main Tests can be analyzed for a valid npm package 1`] = ` | ||
Array [ | ||
Object { | ||
"fanIn": 10000, | ||
"fanOut": 1, | ||
"label": "Stable", | ||
"name": "react", | ||
"stability": 0.00009999000099990002, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Main Tests can be analyzed for local packages 1`] = ` | ||
Array [ | ||
Object { | ||
"fanIn": 1, | ||
"fanOut": 0, | ||
"instable": 0, | ||
"label": "Stable", | ||
"name": "a", | ||
}, | ||
Object { | ||
"fanIn": 1, | ||
"fanOut": 1, | ||
"instable": 0.5, | ||
"label": "Normal", | ||
"name": "b", | ||
}, | ||
Object { | ||
"fanIn": 1, | ||
"fanOut": 2, | ||
"instable": 0.6666666666666666, | ||
"label": "Flexible", | ||
"name": "c", | ||
}, | ||
Object { | ||
"fanIn": 1, | ||
"fanOut": 3, | ||
"instable": 0.75, | ||
"label": "Flexible", | ||
"name": "d", | ||
}, | ||
Object { | ||
"fanIn": 1, | ||
"fanOut": 4, | ||
"instable": 0.8, | ||
"label": "Instable", | ||
"name": "e", | ||
}, | ||
] | ||
`; |
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,5 @@ | ||
#!/usr/bin/env node | ||
|
||
import { bootstrap } from '../cli'; | ||
|
||
bootstrap(); |
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,29 @@ | ||
/** | ||
* This is a sample test suite. | ||
* Replace this with your implementation. | ||
*/ | ||
import { bootstrap } from './index'; | ||
|
||
describe('CLI tool Tests', () => { | ||
it('main', async () => { | ||
const spy = jest.spyOn(console, 'log'); | ||
const program = await bootstrap(['node', 'index.js', 'analyze', 'react']); | ||
await expect(program.commands.map((i: any) => i._name)).toEqual(['analyze']); | ||
const result = spy.mock.calls[0][0]; | ||
expect(result).toEqual( | ||
JSON.stringify( | ||
[ | ||
{ | ||
name: 'react', | ||
fanIn: 10000, | ||
fanOut: 1, | ||
stability: 0.00009999000099990002, | ||
label: 'Stable', | ||
}, | ||
], | ||
null, | ||
2, | ||
), | ||
); | ||
}); | ||
}); |
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,24 +1,19 @@ | ||
#!/usr/bin/env node | ||
import { Command } from 'commander'; | ||
import { analyzeNpmPackage, analyzeYarnWorkspaces } from '../index'; | ||
import { isLocalPath } from '../utils/checkLocalPath'; | ||
import { analyze } from '../index'; | ||
|
||
const program = new Command(); | ||
|
||
program.name('sdp-analyzer').description('A cli tool for analyzing package stability').version('1.0.0'); | ||
program | ||
.command('analyze') | ||
.argument('<string>', 'the local package path or a npm package name') | ||
.action(async target => { | ||
let result; | ||
if (isLocalPath(target)) { | ||
// default to yarn workspaces | ||
result = await analyzeYarnWorkspaces(target); | ||
} else { | ||
result = await analyzeNpmPackage(target); | ||
} | ||
console.log(JSON.stringify(result, null, 2)); | ||
process.exit(0); | ||
}); | ||
async function bootstrap(argv = process.argv) { | ||
program.name('sdp-analyzer').description('A cli tool for analyzing package stability').version('1.0.0'); | ||
program | ||
.command('analyze') | ||
.argument('<string>', 'the local package path or a npm package name') | ||
.action(async target => { | ||
const result = await analyze(target); | ||
console.log(JSON.stringify(result, null, 2)); | ||
}); | ||
await program.parseAsync(argv); | ||
return program; | ||
} | ||
|
||
program.parse(); | ||
export { bootstrap }; |
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,14 @@ | ||
/** | ||
* This is a sample test suite. | ||
* Replace this with your implementation. | ||
*/ | ||
import { analyze } from './index'; | ||
|
||
describe('Main Tests', () => { | ||
it('can be analyzed for a valid npm package', async () => { | ||
await expect(analyze('react')).resolves.toMatchSnapshot(); | ||
}); | ||
it('can be analyzed for local packages', async () => { | ||
await expect(analyze('./src/platforms/workspaces/yarn/fixture/valid-packages')).resolves.toMatchSnapshot(); | ||
}); | ||
}); |
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,2 +1,12 @@ | ||
export { analyze as analyzeNpmPackage } from './platforms/npm-package'; | ||
export { analyze as analyzeYarnWorkspaces } from './platforms/workspaces/yarn'; | ||
import { isLocalPath } from './utils/checkLocalPath'; | ||
|
||
import { analyze as analyzeNpmPackage } from './platforms/npm-package'; | ||
import { analyze as analyzeYarnWorkspaces } from './platforms/workspaces/yarn'; | ||
|
||
export function analyze(target: string) { | ||
if (isLocalPath(target)) { | ||
// default to yarn workspaces | ||
return analyzeYarnWorkspaces(target); | ||
} | ||
return analyzeNpmPackage(target); | ||
} |
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 |
---|---|---|
|
@@ -15,13 +15,13 @@ describe('Npm pacakge Tests', () => { | |
{ name: 'loose-envify', version: '^1.1.0' }, | ||
]); | ||
}); | ||
it('should return a dep array for single package', async () => { | ||
it('can be analyzed for single package', async () => { | ||
await expect(analyze('react')).resolves.toMatchSnapshot(); | ||
}); | ||
it('should return a dep array for multiple packages', async () => { | ||
it('can be analyzed for multiple packages', async () => { | ||
await expect(analyze('react,vue')).resolves.toMatchSnapshot(); | ||
}); | ||
it('should return a dep array with the package version', async () => { | ||
it('can be analyzed for multiple packages with the package version', async () => { | ||
await expect(analyze('[email protected],[email protected]')).resolves.toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.