Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Preparing for publication.

See merge request desionlab/fastpanel/packages/console!5
  • Loading branch information
fenixphp committed Apr 20, 2021
2 parents e9311d7 + 0e4b7da commit 9427deb
Show file tree
Hide file tree
Showing 47 changed files with 17,656 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
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
20 changes: 20 additions & 0 deletions .eslintrc.js
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'
}
};
42 changes: 42 additions & 0 deletions .github/workflows/npm-publish.yml
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}}
33 changes: 33 additions & 0 deletions .gitignore
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
28 changes: 28 additions & 0 deletions .gitlab-ci.yml
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
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
5 changes: 5 additions & 0 deletions .husky/pre-commit
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
11 changes: 11 additions & 0 deletions .prettierrc
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"
}
10 changes: 10 additions & 0 deletions CHANGELOG.md
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.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Contributor Covenant Code of Conduct
21 changes: 21 additions & 0 deletions LICENSE
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.
137 changes: 137 additions & 0 deletions README.md
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).
24 changes: 24 additions & 0 deletions demo/sample-pizza/.eslintrc.js
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',
},
};
34 changes: 34 additions & 0 deletions demo/sample-pizza/.gitignore
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
4 changes: 4 additions & 0 deletions demo/sample-pizza/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
Loading

0 comments on commit 9427deb

Please sign in to comment.