Skip to content

Commit

Permalink
feat: introduce cli-api, cli-pipe, some refactoring (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
oljekechoro authored Dec 8, 2020
1 parent 9983bf3 commit 13a90a2
Show file tree
Hide file tree
Showing 44 changed files with 551 additions and 58 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ wrapper.deprecate('foo', '<1.2.0', 'foo <1.2.0 contains critical bugs')
## [@qiwi/npm-batch-cli](https://github.com/qiwi/npm-batch-action/tree/master/packages/cli)
CLI utility for performing batched npm actions.
```shell script
@qiwi/npm-batch-cli --config=config.json
npx @qiwi/npm-batch-cli --config=config.json
```
`config.json`:
```json
Expand All @@ -48,4 +48,18 @@ CLI utility for performing batched npm actions.
]
}
```
## [@qiwi/npm-batch-cli-pipe](https://github.com/qiwi/npm-batch-action/tree/master/packages/cli-pipe)
The same as `@qiwi/npm-batch-cli`, but with configuring via a pipeline.
```shell script
cat config.json | npx @qiwi/npm-batch-cli-pipe
```

## [@qiwi/npm-batch-cli-api](https://github.com/qiwi/npm-batch-action/tree/master/packages/cli-api)
API for npm-batch CLI utilities.
```typescript
import { readConfigAndRun } from '@qiwi/npm-batch-cli-api'

readConfigAndRun({ config: 'config.json' })
.then(() => console.log('Done.'))
```

4 changes: 3 additions & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"collectCoverage": true,
"projects": [
"<rootDir>/packages/client/jest.config.json",
"<rootDir>/packages/cli/jest.config.json"
"<rootDir>/packages/cli/jest.config.json",
"<rootDir>/packages/cli-pipe/jest.config.json",
"<rootDir>/packages/cli-api/jest.config.json"
]
}
7 changes: 7 additions & 0 deletions packages/cli-api/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: [
'eslint-config-qiwi',
'prettier',
'prettier/@typescript-eslint',
],
};
17 changes: 17 additions & 0 deletions packages/cli-api/.releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"branch": "master",
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
[
"@semantic-release/github",
{
"successComment": false,
"failComment": false
}
],
"@semantic-release/git"
]
}
14 changes: 14 additions & 0 deletions packages/cli-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# @qiwi/npm-batch-cli-api
API npm-batch CLI utilities
## Installation
```shell script
npm install @qiwi/npm-batch-cli-api
yarn add @qiwi/npm-batch-cli-api
```
## Usage
```typescript
import { readConfigAndRun } from '@qiwi/npm-batch-cli-api'

readConfigAndRun({ config: 'config.json' })
.then(() => console.log('Done.'))
```
34 changes: 34 additions & 0 deletions packages/cli-api/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"testEnvironment": "node",
"transform": {
"^.+\\.tsx?$": "ts-jest",
"^.+\\.jsx?$": "@swissquote/crafty-preset-jest/src/esm-transformer"
},
"collectCoverage": true,
"coveragePathIgnorePatterns": [
],
"collectCoverageFrom": [
"<rootDir>/src/main/**/*.(j|t)s"
],
"testMatch": [
"<rootDir>/src/test/js/*.js",
"<rootDir>/src/test/ts/**/*.ts"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"preset": "ts-jest",
"globals": {
"ts-jest": {
"tsconfig": "<rootDir>/tsconfig.test.json"
}
}
}
65 changes: 65 additions & 0 deletions packages/cli-api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "@qiwi/npm-batch-cli-api",
"version": "0.0.0",
"private": false,
"publishConfig": {
"access": "public"
},
"description": "API for npm-batch CLI utilities",
"keywords": [
"npm",
"batch",
"deprecate",
"cli"
],
"main": "target/es5/index.js",
"source": "target/ts/index.ts",
"types": "target/es5/index.d.ts",
"typescript": {
"definition": "target/es5/index.d.ts"
},
"files": [
"README.md",
"CHANGELOG.md",
"target",
"typings",
"flow-typed"
],
"scripts": {
"test": "yarn lint && yarn jest",
"jest": "jest -w=1 --config=jest.config.json",
"lint": "eslint src/**/*.ts",
"lint:fix": "yarn lint --fix",
"clean": "rimraf target typings flow-typed buildcache coverage docs",
"build": "yarn build:es5 && yarn build:es6 && yarn build:ts && yarn build:libdef && yarn docs",
"build:es5": "mkdirp target/es5 && tsc -p tsconfig.es5.json",
"build:es6": "mkdirp target/es6 && tsc -p tsconfig.es6.json",
"build:ts": "cpy src/main/ts/ target/ts/",
"build:libdef": "libdefkit --tsconfig=tsconfig.es5.json --tsconfig=tsconfig.es6.json",
"docs": "typedoc --readme README.md --tsconfig tsconfig.es5.json src/main",
"uglify": "for f in $(find target -name '*.js'); do short=${f%.js}; terser -c -m -o $short.js -- $f; done",
"postupdate": "yarn && yarn build && yarn test",
"format": "prettier --write 'src/**/*.ts'"
},
"dependencies": {
"@qiwi/deep-proxy": "^1.8.1",
"@qiwi/npm-batch-client": "1.1.0",
"@qiwi/substrate": "^1.19.5",
"push-it-to-the-limit": "^1.17.1",
"tslib": "^2.0.3"
},
"devDependencies": {
"@qiwi/npm-batch-client-infra": "1.0.0",
"nock": "^13.0.5"
},
"repository": {
"type": "git",
"url": "git+https://github.com/qiwi/npm-batch-action.git"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/qiwi/npm-batch-action/issues"
},
"homepage": "https://github.com/qiwi/npm-batch-action/#readme",
"prettier": "prettier-config-qiwi"
}
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions packages/cli-api/src/main/ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './interfaces'
export * from './runner'
export * from './utils'
export * from './executors'
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { performDeprecation } from './executors'
import { ICliArgs } from './interfaces'
import { readFileToString, validateBaseConfig, validateDeprecationConfig } from './utils'

export const run = (args: ICliArgs): Promise<any[]> => {
const rawConfig = JSON.parse(readFileToString(args.config))
export const run = (configString: string): Promise<any[]> => {
const rawConfig = JSON.parse(configString)
const validatedConfig = validateBaseConfig(rawConfig)
switch (validatedConfig.action) {
case 'deprecate':
Expand All @@ -16,3 +16,7 @@ export const run = (args: ICliArgs): Promise<any[]> => {
}
}

export const readConfigAndRun = (args: ICliArgs): Promise<any[]> => {
const config = readFileToString(args.config)
return run(config)
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IBaseConfig, run } from '../../main/ts'
import { IBaseConfig, readConfigAndRun } from '../../main/ts'
import * as deprecation from '../../main/ts/executors/deprecation'
import * as utils from '../../main/ts/utils/misc'
import * as validators from '../../main/ts/utils/validators'
Expand All @@ -15,12 +15,12 @@ const config: IBaseConfig = {

beforeEach(() => jest.restoreAllMocks())

describe('run', () => {
describe('readConfigAndRun', () => {
it('reads and validates config', () => {
const readSpy = jest.spyOn(utils, 'readFileToString')
.mockImplementation(() => JSON.stringify(config))
const baseValidatorSpy = jest.spyOn(validators, 'validateBaseConfig')
run({ config: 'foo' })
readConfigAndRun({ config: 'foo' })
expect(readSpy).toHaveBeenCalled()
expect(baseValidatorSpy).toHaveBeenCalled()
})
Expand All @@ -29,21 +29,21 @@ describe('run', () => {
jest.spyOn(utils, 'readFileToString')
.mockImplementation(() => JSON.stringify(config))
const spy = jest.spyOn(deprecation, 'performDeprecation')
run({ config: 'foo' })
readConfigAndRun({ config: 'foo' })
expect(spy).toHaveBeenCalled()
})

it('calls performDeprecation for un-deprecate', () => {
jest.spyOn(utils, 'readFileToString')
.mockImplementation(() => JSON.stringify({ ...config, action: 'un-deprecate' }))
const spy = jest.spyOn(deprecation, 'performDeprecation')
run({ config: 'foo' })
readConfigAndRun({ config: 'foo' })
expect(spy).toHaveBeenCalled()
})

it('throws an error when action is not recognized', () => {
jest.spyOn(utils, 'readFileToString')
.mockImplementation(() => JSON.stringify({ ...config, action: 'foo' }))
expect(() => run({ config: 'foo' })).toThrow()
expect(() => readConfigAndRun({ config: 'foo' })).toThrow()
})
})
13 changes: 13 additions & 0 deletions packages/cli-api/tsconfig.es5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "es5",
"outDir": "target/es5"
},
"include": [
"src/main/**/*"
],
"exclude": [
"node_modules"
]
}
13 changes: 13 additions & 0 deletions packages/cli-api/tsconfig.es6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "es6",
"outDir": "target/es6"
},
"include": [
"src/main/**/*"
],
"exclude": [
"node_modules"
]
}
16 changes: 16 additions & 0 deletions packages/cli-api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../packages/infra/tsconfig.compiler.json",
"compilerOptions": {
"rootDir": "./src/main/ts/",
"baseUrl": "./src/main/ts/",
"target": "es5",
"outDir": "target/es5",
"tsBuildInfoFile": "./buildcache/.tsbuildinfo"
},
"include": [
"src/main/**/*"
],
"exclude": [
"node_modules"
]
}
9 changes: 9 additions & 0 deletions packages/cli-api/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
]
}
15 changes: 15 additions & 0 deletions packages/cli-api/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@qiwi/npm-batch-cli-api",
"mode": "file",
"out": "./docs",
"target": "ES6",
"exclude": ["test", "node_modules", "paralleljs"],
"externalPattern": "**/node_modules/**",
"excludePrivate": true,
"excludeNotExported": true,
"moduleResolution": "node",
"module": "commonjs",
"hideGenerator": true,
"readme": "none",
"ignoreCompilerErrors": true
}
7 changes: 7 additions & 0 deletions packages/cli-pipe/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: [
'eslint-config-qiwi',
'prettier',
'prettier/@typescript-eslint',
],
};
17 changes: 17 additions & 0 deletions packages/cli-pipe/.releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"branch": "master",
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
[
"@semantic-release/github",
{
"successComment": false,
"failComment": false
}
],
"@semantic-release/git"
]
}
7 changes: 7 additions & 0 deletions packages/cli-pipe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @qiwi/npm-batch-cli-pipe
The same as `@qiwi/npm-batch-cli`, but with configuring via a pipeline.
## Usage
```shell script
cat config.json | npx @qiwi/npm-batch-cli-pipe
```
See more at [@qiwi/npm-batch-cli](https://github.com/qiwi/npm-batch-action/tree/master/packages/cli) docs.
34 changes: 34 additions & 0 deletions packages/cli-pipe/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"testEnvironment": "node",
"transform": {
"^.+\\.tsx?$": "ts-jest",
"^.+\\.jsx?$": "@swissquote/crafty-preset-jest/src/esm-transformer"
},
"collectCoverage": true,
"coveragePathIgnorePatterns": [
],
"collectCoverageFrom": [
"<rootDir>/src/main/**/*.(j|t)s"
],
"testMatch": [
"<rootDir>/src/test/js/*.js",
"<rootDir>/src/test/ts/**/*.ts"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"preset": "ts-jest",
"globals": {
"ts-jest": {
"tsconfig": "<rootDir>/tsconfig.test.json"
}
}
}
Loading

0 comments on commit 13a90a2

Please sign in to comment.