-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into 'master'
Preparing for publication. See merge request desionlab/fastpanel/packages/console!5
- Loading branch information
Showing
47 changed files
with
17,656 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,20 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
sourceType: 'module' | ||
}, | ||
plugins: ['@typescript-eslint/eslint-plugin'], | ||
extends: ['plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended', 'prettier'], | ||
root: true, | ||
env: { | ||
node: true, | ||
jest: true | ||
}, | ||
rules: { | ||
'@typescript-eslint/interface-name-prefix': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/ban-types': 'off' | ||
} | ||
}; |
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,42 @@ | ||
name: Publish package | ||
on: | ||
release: | ||
types: [created] | ||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
- run: npm ci | ||
- run: npm run test | ||
publish-npm: | ||
needs: tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
registry-url: https://registry.npmjs.org/ | ||
- run: npm ci | ||
- run: npm run build | ||
- run: npm publish --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} | ||
publish-gpr: | ||
needs: tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
registry-url: https://npm.pkg.github.com/ | ||
- run: npm ci | ||
- run: npm run build | ||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
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,33 @@ | ||
# NPM Config | ||
.npmrc | ||
|
||
# Compiled and dependencies | ||
dist | ||
node_modules | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# OS | ||
.DS_Store | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json |
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,28 @@ | ||
# | ||
# CI Settings. | ||
# | ||
|
||
image: node:12 | ||
|
||
stages: | ||
- test | ||
- publish | ||
|
||
before_script: | ||
- npm config set registry=https://npmjs.desionlab.net/ | ||
- npm config set '//npmjs.desionlab.net/:_authToken' "$NPM_TOKEN" | ||
|
||
jobTest: | ||
stage: test | ||
script: | ||
- npm ci | ||
- npm run test | ||
|
||
jobPublishToDevelop: | ||
stage: publish | ||
script: | ||
- npm ci | ||
- npm run build | ||
- npm publish --access public | ||
only: | ||
- tags |
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 @@ | ||
_ |
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 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npm run format | ||
npm run lint |
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,11 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"printWidth": 120, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": true, | ||
"quoteProps": "as-needed", | ||
"bracketSpacing": true, | ||
"arrowParens": "avoid" | ||
} |
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,10 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [1.0.0] | ||
### Added | ||
- First published build. |
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 @@ | ||
# Contributor Covenant Code of Conduct |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 - 2021 Desionlab | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,137 @@ | ||
# fastPanel [console] | ||
Create console (cli) application in NestJS framework context. | ||
|
||
> The a wrapper "[caporal](https://caporal.io/)" lib for use in "[nestjs](https://nestjs.com/)" framework. | ||
## Install | ||
|
||
### Stable | ||
```bash | ||
npm i @fastpanel/console | ||
``` | ||
|
||
### Develop | ||
```bash | ||
npm i @fastpanel/console --registry https://npmjs.desionlab.net | ||
``` | ||
|
||
## Usage | ||
|
||
1. Add command providers. | ||
|
||
```typescript | ||
/** | ||
* pizza.commands.ts | ||
*/ | ||
|
||
import { Injectable } from '@nestjs/common'; | ||
import { Console, Command, Argument, Option } from '@fastpanel/console'; | ||
|
||
@Console({ name: 'pizza' }) | ||
@Injectable() | ||
export class PizzaCommands { | ||
@Command({ name: 'order', description: 'Order a pizza' }) | ||
@Argument({ synopsis: '<type>', description: 'Type of pizza' }) | ||
@Option({ synopsis: '-e, --extra-ingredients <ingredients>', description: 'Extra ingredients' }) | ||
public async orderAction({ logger, args, options }) { | ||
logger.info('Order received: %s', args.type); | ||
|
||
if (options.extraIngredients) { | ||
logger.info('Extra: %s', options.extraIngredients); | ||
} | ||
} | ||
|
||
@Command({ name: 'cancel', description: 'Cancel an order' }) | ||
@Argument({ synopsis: '<order-id>', description: 'Order id' }) | ||
public async cancelAction({ logger, args }) { | ||
logger.info('Order canceled: %s', args.orderId); | ||
} | ||
} | ||
``` | ||
|
||
2. Add console module and command providers to app module. | ||
|
||
```typescript | ||
/** | ||
* app.module.ts | ||
*/ | ||
|
||
import { Module } from '@nestjs/common'; | ||
import { ConsoleModule } from '@fastpanel/console'; | ||
import { PizzaCommands } from './pizza.commands.ts'; | ||
|
||
@Module({ | ||
imports: [ | ||
ConsoleModule.forRoot({ | ||
name: 'my-test-app', | ||
version: '1.0.0', | ||
description: 'My test app' | ||
}) | ||
], | ||
providers: [PizzaCommands] | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
||
3. Create application context. | ||
|
||
```typescript | ||
/** | ||
* cli.ts | ||
*/ | ||
|
||
import { NestFactory } from '@nestjs/core'; | ||
import { ConsoleService } from '@fastpanel/console'; | ||
import { AppModule } from './app.module'; | ||
|
||
async function bootstrap() { | ||
/* Create app instant. */ | ||
const app = await NestFactory.createApplicationContext(AppModule, { | ||
logger: false | ||
}); | ||
|
||
/* Get console service. */ | ||
const consoleService = app.get<ConsoleService>(ConsoleService); | ||
|
||
/* Add default help command. */ | ||
consoleService.getHandler.action(async ({ program }) => { | ||
await program.exec(['help']); | ||
}); | ||
|
||
/* Run cli handler. */ | ||
await consoleService.run(); | ||
|
||
/* End app. */ | ||
await app.close(); | ||
} | ||
|
||
/* Run app. */ | ||
bootstrap(); | ||
``` | ||
|
||
4. Add scripts to package.json | ||
|
||
```json | ||
{ | ||
"scripts": { | ||
"console": "node dist/cli.js", | ||
"console:dev": "ts-node -r tsconfig-paths/register src/cli.ts" | ||
} | ||
} | ||
``` | ||
|
||
5. Use in terminal. | ||
|
||
```bash | ||
# Run in development mode | ||
npm run console:dev -- help | ||
npm run console:dev -- command-name | ||
|
||
# Run in prod or build mode | ||
npm run console -- help | ||
npm run console -- command-name | ||
``` | ||
|
||
## License | ||
|
||
[MIT licensed](LICENSE). |
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,24 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint/eslint-plugin'], | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:prettier/recommended', | ||
], | ||
root: true, | ||
env: { | ||
node: true, | ||
jest: true, | ||
}, | ||
ignorePatterns: ['.eslintrc.js'], | ||
rules: { | ||
'@typescript-eslint/interface-name-prefix': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
}, | ||
}; |
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,34 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# OS | ||
.DS_Store | ||
|
||
# Tests | ||
/coverage | ||
/.nyc_output | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json |
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,4 @@ | ||
{ | ||
"collection": "@nestjs/schematics", | ||
"sourceRoot": "src" | ||
} |
Oops, something went wrong.