1.0.10 • Published 10 months ago

@vts-kit/nx-angular v1.0.10

Weekly downloads
-
License
Viettel Solutions
Repository
github
Last release
10 months ago

VTS Kit Angular NX Plugin

VTS Kit Angular NX Plugin is a collection of generators to be integrated with Nx Workspace. This library aims to provide a quick way to start a new Angular Project and maintain code structure with least effort.

Requirement

  • Node: 12+
  • Npm: 6+ (included in Node installation)
  • Npx: 6+ (included in Node installation)

Intergrated Features

Quickstart

  • Create a new workspace using VTS Kit Angular NX Plugin:
npx @vts-kit/nx-angular@latest

Structure

.
└── <workspace_name>/
    ├── apps/
    │   └── <app_name>/
    │       ├── src/
    │       │   ├── app/
    │       │   │   ├── app.module.ts           // Root component
    │       │   │   ├── app.component.ts        // Root component, bootstrap
    │       │   │   ├── app.component.spec.ts   // Root component, test
    │       │   │   ├── app.component.html      // Root component, outlet
    │       │   │   ├── configs.ts              // Provider, import configs
    │       │   │   └── routes.ts               // RouterModule config, lazy load to feature libraries
    │       │   ├── assets/                     // Public assets
    │       │   │   └── locale/                 // Translation dictionary
    │       │   │       ├── en.json             // JSON dictionary
    │       │   │       └── vi.json             // JSON dictionary
    │       │   ├── environments/               // Environment config
    │       │   |    ├── environment.ts         // Environment profile
    │       │   |    └── environment.prod.ts    // Environment profile
    │       │   └── styles/                     // Global styles
    │       ├── webpack/                        // Webpack config
    │       │   ├── webpack.config.js           // Webpack profile
    │       │   └── webpack.config.prod.js      // Webpack profile
    │       ├── project.json                    // Nx Project configuration
    │       ├── tsconfig(.|lib|spec).json       // Tsconfig
    │       ├── favicon.ico                     // Angular starter files
    │       ├── index.html                      // Angular starter files
    │       ├── main.ts                         // Angular starter files
    │       ├── polyfills.ts                    // Angular starter files
    │       └── test.ts                         // Angular starter files
    ├── libs/                                   // Shared modules and feature modules
    │   ├── layout/                             // Feature group, layout
    │   │   ├── ui/                             // Library (generatable)
    │   │   │   ├── src/
    │   │   │   │   ├── index.ts                // Automatically exporter on generating
    │   │   │   │   └── lib/
    │   │   │   │       ├── <topbar>            // Standalone UI components, unit (generatable)
    │   │   │   │       └── <sider>             // Standalone UI components, unit (generatable)
    │   │   │   ├── project.json                // NX Project configuration
    │   │   │   └── tsconfig(.|lib|spec).json   // Tsconfig
    │   │   ├── feature/                        // Library (generatable)
    │   │   │   ├── src/
    │   │   │   │   ├── index.ts                // Automatically exporter on generating
    │   │   │   │   └── lib/
    │   │   │   │       ├── <dasboard_layout>   // Standalone UI components, container (ultilize units in template)
    │   │   │   │       ├── <home_layout>       // Standalone UI components, container (ultilize units in template)
    │   │   │   │       ├── routes.ts           // RouterModule config, lazy load
    │   │   │   │       └── *.module.ts
    │   │   │   ├── project.json                // NX Project configuration
    │   │   │   └── tsconfig(.|lib|spec).json   // Tsconfig
    │   │   └── data-access/                    // Library (generatable)
    │   │       ├── src/
    │   │       │   ├── index.ts                // Automatically exporter on generating
    │   │       │   └── lib/
    │   │       │       └── <store_1>           // State management, store
    │   │       ├── project.json                // NX Project configuration
    │   │       └── tsconfig(.|lib|spec).json   // Tsconfig
    │   ├── <feature_product>/                  // Feature group (generatable)
    │   │   ├── ui/                             // Library (generatable)
    │   │   │   ├── src/
    │   │   │   │   ├── index.ts                // Automatically exporter on generating
    │   │   │   │   └── lib/
    │   │   │   │       ├── <product_form>      // Standalone UI components, unit (generatable)
    │   │   │   │       └── <product_table>     // Standalone UI components, unit (generatable)
    │   │   │   ├── project.json                // NX Project configuration
    │   │   │   └── tsconfig(.|lib|spec).json   // Tsconfig
    │   │   ├── feature/                        // Library (generatable)
    │   │   │   ├── src/
    │   │   │   │   ├── index.ts                // Automatically exporter on generating
    │   │   │   │   └── lib/
    │   │   │   │       ├── <list_screen>       // Standalone UI components, container (ultilize units in template)
    │   │   │   │       ├── <detail_screen>     // Standalone UI components, container (ultilize units in template)
    │   │   │   │       ├── routes.ts           // RouterModule config, lazy load
    │   │   │   │       └── *.module.ts
    │   │   │   ├── project.json                // NX Project configuration
    │   │   │   └── tsconfig(.|lib|spec).json   // Tsconfig
    │   │   └── data-access/                    // Library (generatable)
    │   │       ├── src/
    │   │       │   ├── index.ts                // Automatically exporter on generating
    │   │       │   └── lib/
    │   │       │       ├── <item_state>        // State management, store
    │   │       │       └── <filter_state>      // State management, store
    │   │       ├── project.json                // NX Project configuration
    │   │       └── tsconfig(.|lib|spec).json   // Tsconfig
    │   └── share/
    │       └── guards/                         // Library, publishable (generatable)
    │       ├── interceptors/                   // Library, publishable (generatable)
    │       ├── data-access/                    // Library, publishable (generatable)
    │       ├── pipes/                          // Library, publishable (generatable)
    │       ├── services/                       // Library, publishable (generatable)
    │       ├── ui/                             // Library, publishable (generatable)
    │       ├── utils/                          // Library, publishable (generatable)
    │       └── validators/                     // Library, publishable (generatable)
    ├── package.json
    ├── nx.json                                 // NX Workspace configuration
    └── tsconfig.base.json                      // Tsconfig, automatically update project alias

Using NX generators to generate necessary items and keep structure sync.

Generators

Schematics

NoNameDescription
1LibraryCreates an Angular library.
2Feature GroupGenerate an Angular Feature group.
3ComponentGenerate an Angular Component.
4DirectiveGenerate an Angular Directive.
5PipeGenerate an Angular Pipe.
6ServiceGenerate an Angular Service.
7ClassGenerate an Angular Class.
8InterfaceGenerate an Angular Interface.
9EnumGenerate an Angular Enum.
10GuardGenerate an Angular Guard.
11InterceptorGenerate an Angular Interceptor.
12ResolverGenerate an Angular Resolver.
13ValidatorGenerate an Angular Validator.
14TemplateGenerate a feature group template.

Usage

Using Nx CLI

  • Make sure NX CLI has been installed.
npm i -g nx
  • Using VTS Kit generators.
nx g @vts-kit/nx-angular:<generator_name> <generator_args>

Using Nx Console (GUI)

  • Install Nx Console in VSCode
  • Using generator:

    • Option 1: Select generate Nx Console Tab and select a generator

      • Option 2: Right click on a library and select nx generate in context menu
  • Fill in options

  • Preview changes
  • Press Run to make changes

Generator: Library

NoNameDescriptionTypeRequireDefault
1nameThe name of the library.string
2directoryA directory where the library is placed.stringfalse
3publishableGenerate a publishable library. Must specify importPath for other projects be able to import it.booleanfalse
4importPathThe library name used to import it, like @organize/lib-name. Must be a valid npm name.string
5buildableGenerate a buildable library.booleanfalse
6skipPackageJsonDo not add dependencies to package.json.booleanfalse
7skipTsConfigDo not update tsconfig.json for development experience.booleanfalse
8tagAdd tags to the library (used for linting)string
9unitTestRunnerTest runner to use for unit tests.karma jest nonejest
10strictCreate a library with stricter type checking and build optimization options.booleantrue
11linterThe tool to use for running lint checks.eslint noneeslint
12compilationModeSpecifies the compilation mode to use. If not specified, it will default to partial for publishable libraries and to full for buildable libraries. The full value can not be used for publishable libraries.full partialdepend
13featureGenerate additional NgModule and Routing config with library. Every component generated inside feature library will automatically create a route to it.booleanfalse
14appRoutingProject(Only work with feature library) The name of the app where feature will be imported for routing. Only projects of application are validstringdefaultProject

Generator: Feature Group

NoNameDescriptionTypeRequireDefault
1nameThe name of the feature group.string
2appRoutingProject(Only work with feature library) The name of the app where feature will be imported for routing. Only projects of application are validstringdefaultProject

Generator: Component

NoNameDescriptionTypeRequireDefault
1pathThe path at which to create the component file, relative to the selected project (\/src\/(lib|app)\/\<relative_path>) or relative to workspace (\<root_workspace>\/\<relative_path>).string
2projectThe name of the project.stringdefaultProject
3nameThe name of the component.string
4displayBlockSpecifies if the style will contain :host { display: block; }.booleanfalse
5inlineStyleInclude styles inline in the component.ts file. Only CSS styles can be included inline. By default, an external styles file is created and referenced in the component.ts file.booleanfalse
6inlineTemplateInclude template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file.booleanfalse
7viewEncapsulationThe view encapsulation strategy to use in the new component.Emulated None ShadowDom
8changeDetectionThe change detection strategy to use in the new component.Default OnPushDefault
9styleThe file extension or preprocessor to use for style files, or none to skip generating the style file.scss css lessscss
10skipTestsDo not create spec.ts test files for the new component.booleanfalse
11skipImportDo not import this component into the owning NgModule.booleanfalse
12skipSelectorSpecifies if the component should have a selector or not.booleanfalse
13selectorThe HTML selector to use for this component.string

Generator: Directive

NoNameDescriptionTypeRequireDefault
1pathThe path at which to create the directive file, relative to the selected project (\/src\/(lib|app)\/\<relative_path>) or relative to workspace (\<root_workspace>\/\<relative_path>).string
2projectThe name of the project.stringdefaultProject
3nameThe name of the directive.string
4prefixA prefix to apply to generated selectors.string
5skipTestsDo not create spec.ts test files for the new directive.booleanfalse
6selectorThe HTML selector to use for this directive.string

Generator: Pipe

NoNameDescriptionTypeRequireDefault
1pathThe path at which to create the pipe file, relative to the selected project (\/src\/(lib|app)\/\<relative_path>) or relative to workspace (\<root_workspace>\/\<relative_path>).string
2projectThe name of the project.stringdefaultProject
3nameThe name of the pipe.string
4skipTestsDo not create spec.ts test files for the new pipe.booleanfalse

Generator: Service

NoNameDescriptionTypeRequireDefault
1pathThe path at which to create the service file, relative to the selected project (\/src\/(lib|app)\/\<relative_path>) or relative to workspace (\<root_workspace>\/\<relative_path>).string
2projectThe name of the project.stringdefaultProject
3nameThe name of the service.string
4skipTestsDo not create spec.ts test files for the new service.booleanfalse

Generator: Class

NoNameDescriptionTypeRequireDefault
1pathThe path at which to create the service file, relative to the selected project (\/src\/(lib|app)\/\<relative_path>) or relative to workspace (\<root_workspace>\/\<relative_path>).string
2projectThe name of the project.stringdefaultProject
3nameThe name of the class.string
4skipTestsDo not create spec.ts test files for the new class.booleanfalse
5typeAdds a developer-defined type to the filename, in the format \"name..ts\".string

Generator: Interface

NoNameDescriptionTypeRequireDefault
1pathThe path at which to create the interface file, relative to the selected project (\/src\/(lib|app)\/\<relative_path>) or relative to workspace (\<root_workspace>\/\<relative_path>).string
2projectThe name of the project.stringdefaultProject
3nameThe name of the interface.string
4typeAdds a developer-defined type to the filename, in the format \"name..ts\".string
5prefixPrefix to be added before interface namestring

Generator: Enum

NoNameDescriptionTypeRequireDefault
1pathThe path at which to create the enum file, relative to the selected project (\/src\/(lib|app)\/\<relative_path>) or relative to workspace (\<root_workspace>\/\<relative_path>).string
2projectThe name of the project.stringdefaultProject
3nameThe name of the enum.string
4typeAdds a developer-defined type to the filename, in the format \"name..ts\".string

Generator: Guard

NoNameDescriptionTypeRequireDefault
1pathThe path at which to create the guard file, relative to the selected project (\/src\/(lib|app)\/\<relative_path>) or relative to workspace (\<root_workspace>\/\<relative_path>).string
2projectThe name of the project.stringdefaultProject
3nameThe name of the guard.string
4skipTestsDo not create spec.ts test files for the new guard.booleanfalse
5implementsSpecifies which route guards to implement (hold Ctrl to multiselect).Multiple choice "CanActivate", "CanActivateChild", "CanDeactivate", "CanLoad""CanActivate"

Generator: Interceptor

NoNameDescriptionTypeRequireDefault
1pathThe path at which to create the interceptor file, relative to the selected project (\/src\/(lib|app)\/\<relative_path>) or relative to workspace (\<root_workspace>\/\<relative_path>).string
2projectThe name of the project.stringdefaultProject
3nameThe name of the interceptor.string
4skipTestsDo not create spec.ts test files for the new interceptor.booleanfalse

Generator: Resolver

NoNameDescriptionTypeRequireDefault
1pathThe path at which to create the resolver file, relative to the selected project (\/src\/(lib|app)\/\<relative_path>) or relative to workspace (\<root_workspace>\/\<relative_path>).string
2projectThe name of the project.stringdefaultProject
3nameThe name of the resolver.string
4skipTestsDo not create spec.ts test files for the new resolver.booleanfalse

Generator: Validator

NoNameDescriptionTypeRequireDefault
1pathThe path at which to create the validator file, relative to the selected project (\/src\/(lib|app)\/\<relative_path>) or relative to workspace (\<root_workspace>\/\<relative_path>).string
2projectThe name of the project.stringdefaultProject
3nameThe name of the validator.string
4skipTestsDo not create spec.ts test files for the new validator.booleanfalse
5typeSpecifies type of validator."sync", "async"
6formSpecifies type of Angular form in which validator be used (Reactive form / Template-driven form)."reactive", "template"

Generator: Template

NoNameDescriptionTypeRequireDefault
1nameName of feature groupstring
2typeType of template which will be created"ErrorTemplate-NoLayout", "AuthenticationTemplate-WithLayout", "LandingTemplate-WithLayout"
3layoutNameName of layout feature will be generated in feature-group layout. Only neccessary if template type require a layout, check template descriptionstring

Feature Guideline

Feature: Custom webpack

Custom webpack unlock the ability to enhance web builder process.
VTS Kit Angular provides 2 profile of webpack on generating project. You find these files under app/<app_name>/webpack.config.<profile>.js.
You can also add another profile, but take note to register profile in app/<app_name>/project.json

Feature: UI Component

Please see full guideline in https://design.atviettelsolutions.com/uikit/

Feature: Localization

Translation dictionary can be found under app/<app_name>/src/assets/locale/. By default, VTS Kit generate 2 translation files which are Vietnamese and English. If you want to add new language, just create new JSON file under this folder and use TranslateService to use new language.

Config (Already declared on generating, maybe be overwritten)

Translation config is localed in app/<app_name>/src/app/configs.ts.

// configs.ts

import { TranslateLoader, TranslateModuleConfig } from '@ngx-translate/core';

class TranslateHttpLoader extends TranslateLoader {
  getTranslation(lang: string): Observable<any> {
    return from(fetch(`./assets/locale/${lang}.json`).then((d) => d.json()));
  }
}

export const TRANSLATE_MODULE_CONFIG: TranslateModuleConfig = {
  defaultLanguage: 'vi',
  loader: {
    provide: TranslateLoader,
    useClass: TranslateHttpLoader,
  },
};

By default, translation module is configured to use HTTP loader to load translation file from assets and use vi language.

Import (Already imported on generating)

// app.module.ts
@NgModule({
  imports: [
    TranslateModule.forRoot(TRANSLATE_MODULE_CONFIG)
  ]
})

Usage

  • Switch language
constructor(private translateService: TranslateService) {
  this.translateService.use('en')
}
  • Get current language:
this.translateService.currentLang;
  • Get translate:

Example dictionary

{
  "hello": {
    "world": "Xin chào {{name}}"
  }
}

Get translation using service

// Return value of string => Xin chào A
// Note: instant() require the TranslateModule has been loaded, if you're unsure about this, use get() or pipe
this.translateService.instant('hello.world', { name: 'A' });

// Return Observable of value of string
this.translateService
  .get('hello.world', { name: 'A' })
  .subscribe((d) => console.log(d)); // d = 'Xin chào A'

Get translation using pipe

// Will render paragraph of "Xin chào A"
<p>{{ 'hello.world' | translate:{name: 'A'} }}

Feature: Network

VTS KIT provides easy-to-config RestClient to interactive with RESTful API and some other network utilities.

Config (Already declared on generating, maybe be overwritten)

Network config is localed in app/<app_name>/src/app/configs.ts.

// configs.ts
import {
  RestClientOptions,
  VtsRestModuleConfig,
} from '@vts-kit/angular-network';

const NETWORK_MODULE_CONFIG: VtsRestModuleConfig = {
  defaultConfig: new RestClientOptions()
    .setBaseUrl('https://<base_api_url>')
    .setHeader('key', 'value')
    .setParam('key', 'value')
    .setRetry(3),
};

Import (Already imported on generating)

// app.module.ts
@NgModule({
  imports: [
    TranslateModule.forRoot(TRANSLATE_MODULE_CONFIG),
  ]
})

Usage

Pattern

client
  .setHeader("key", "value")
  .setTimeout(60000)
  ... // More builder
  .obserseBody() // or obserseEvents() or obserseResponse()
  .get("<path or url>") // or post, patch, put, options, delete
  .subscribe(...)

Example

// name.any.ts
import { RestClient } from '@vts-kit/angular-network';

@Injectable({
  providedIn: 'root',
})
export class Service {
  constructor(private client: RestClient) {}

  callApi() {
    this.client
      .obserseBody()
      .get<Post[]>('/posts')
      .subscribe({
        next: (d) => console.log(d[0].title),
        error: (e) => console.log(e),
      });
  }
}

Feature: Validation

VTS KIT provides common validation function to be used combine with Angular Validator to make form validation easier.

List of validator

NoNameFromDescription
1requiredAngular ValidatorsWhether input is required
2requiredTrueAngular ValidatorsWhether input is required to be true
3emailAngular ValidatorsWhether input is a valid email format
4minAngular ValidatorsWhether input value to be greater than or equal to the provided number
5maxAngular ValidatorsWhether input value to be less than or equal to the provided number
6minLengthAngular ValidatorsWhether input length to be greater than or equal to the provided number
7maxLengthAngular ValidatorsWhether input length to be less than or equal to the provided number
8patternAngular ValidatorsWhether input value is matched a RegExe pattern
9viettelMailVTS Kit ValidatorsWhether input value is valid Viettel Email
10ipAddressVTS Kit ValidatorsWhether input value is valid ip address
11ipAddressPortVTS Kit ValidatorsWhether input value is valid ip address and port (\<ip>:\<port>)
12urlVTS Kit ValidatorsWhether input value is valid url
13[number]VTS Kit ValidatorsWhether input can be convert to number
14[number][numberType]VTS Kit ValidatorsWhether input number is specific type (float, integer, any)
15[number][larger]VTS Kit ValidatorsWhether input number is greater than provided number
16[number][largerOrEqual]VTS Kit ValidatorsWhether input number is greater than or equal to provided number
17[number][smaller]VTS Kit ValidatorsWhether input number is less than provided number
18[number][smallerOrEqual]VTS Kit ValidatorsWhether input number is less than or equal to provided number

Usage

For template-driven form:

// *.ts
import { VtsValidatorModule } from '@vts-kit/angular-validator';

@(NgModule | Component | ...)({
    imports: [VtsValidatorModule]
})

// *.html
<input ngModel url  />
<input number [larger]="5" [smallerOrEqual]="10" #control="ngModel">

// You can see raise errors here
{{ control.errors | json }}

For reactive form:

// *.ts
import { VTSValidators } from '@vts-kit/angular-validator';

export class Component ... {
  // Use with 'validators' property of FormControl, FormGroup, FormBuilder, ...
  control1 = new FormBuilder().control('', {
      validators: [VTSValidators.url]
  })

  control2 = new FormBuilder().control('', {
    validators: [
        VTSValidators.number({
          larger: 5,
          smallerOrEqual: 10
        })
    ]
  })
}

// *.html
<input [formControl]="control1" />
<input [formControl]="control2" />

// You can see raise errors here
{{ control1.errors | json }}
{{ control2.errors | json }}

Feature: Common

VTS KIT provides common utility function to help code faster.

Date

NoFunction NameDescriptionOutput
1distanceReturn a distance between two dates in milisecondsnumber
2isGreaterReturn whether date1 is greater than date2boolean
3isGreaterOrEqualReturn whether date1 is greater than or equal to date2boolean
4isSmallerReturn whether date1 is smaller than date2boolean
5isSmallerOrEqualReturn whether date1 is smaller than or equal to date2boolean

String

NoFunction NameDescriptionOutput
1isNullOrEmptyReturn whether a string is null or emptyboolean
2defaultValueReturn defaultValue if value is null or empty, else return valuestring
3upperFirstReturn value with first character is setted to be uppercasestring
4lowerFirstReturn value with first character is setted to be lowercasestring
5camelCaseConverts value to camel casestring
6pascalCaseConverts value to pascal casestring
7kebabCaseConverts value to kebab casestring
8snakeCaseConverts value to snake casestring
9capitalizeConverts the first character of first word in value to upper case and the remaining to lower casestring
10capitalizeAllConverts the first character of each word in value to upper case and the remaining to lower casestring

Path

NoFunction NameDescriptionOutput
1getExtNameReturn extension of the pathstring
2getDirNameReturn dir of the pathstring
3getBaseNameReturn last portion of the pathstring

Feature: Bundle Analyzer

VTS KIT integrated bundle analyzer to help auditing overall bundle size.

Config (Already declared on generating, maybe be overwritten)

Webpack bundle analyzer config is localed in app/<app_name>/webpack/webpack.configs(.prod).ts.

const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

module.exports = (config, context) => {
  return merge(config, {
    plugins: [
      // Other plugins
      ...(process.env.ANALYZE
        ? [
            new BundleAnalyzerPlugin({
              analyzerMode: 'server',
              analyzerHost: '127.0.0.1',
              analyzerPort: 8001,
            }),
          ]
        : []),
    ]
  })

By default, webpack bundle analyzer will serve a web report at http://127.0.0.1:8001. You can check out more options for webpack bundle analyzer here

Usage

Either use VTS Kit script inside package.json or custom your own.

// package.json
  ...
  scripts: {
    "start:analyze": "cross-env ANALYZE=1 npm run start",
    "build:analyze": "cross-env ANALYZE=1 npm run build"
  }

Using start:analyzer to start analyzing on Development Environment or build:analyzer to analyze on Production Environment

VTS KIT provides Docker config and Jenkin config with dynamic variables, developer can make change at ease.

CICD variables can be found under cicd/jenkinsfile/environment.groovy. Developer have to fill out all required fields to make it work in jenkine pipeline.

/** Pipeline options **/
env.flag_sonar = ""                                         // OPTIONAL, Enable sonar scan (set to 'yes' to enable)
env.flag_security = ""                                      // OPTIONAL, Enable fortify scan (set to 'yes' to enable)

/** Application information **/
env.appName = "demo"                                        // REQUIRED
                                                            // Determine docker image name (<harborServer>/<harborProject>/<appName>:<version>_<buildNumber>)
                                                            // and deployment/service name


/** Kubernetes profile **/

// Development profile
env.devKubeConfigFileSecret = "dev-k8s-config"              // REQUIRED, Secret file credential stored on Jenkin, give in fileID
env.devNamespace = ""                                       // REQUIRED, Kubernetes namespace to deploy
env.devPort = "80"                                          // REQUIRED, Should be nginx port
env.devTargetPort = "80"                                    // REQUIRED, Container port, should be nginx port
env.devNodePort = ""                                        // REQUIRED, Exposal port for external access
env.devImagePullSecrets = "default"                         // REQUIRED, Docker secret to pull image

// Production profile
env.prodKubeConfigFileSecret = "prod-k8s-config"            // REQUIRED, Secret file credential stored on Jenkin, give in fileID
env.prodNamespace = ""                                      // REQUIRED, Kubernetes namespace to deploy
env.prodPort = "80"                                         // REQUIRED, Should be nginx port
env.prodTargetPort = "80"                                   // REQUIRED, Container port, should be nginx port
env.prodNodePort = ""                                       // REQUIRED, Exposal port for external access
env.prodImagePullSecrets = "default"                        // REQUIRED, Docker secret to pull image


/** Docker harbor configuration **/
env.pullRegistry = ""                                       // REQUIRED, Harbor registry to pull base images
env.harborProject = ""                                      // REQUIRED, Harbor folder to store image


/** Git information **/
env.gitTokenSecret = ""                                     // REQUIRED, Secret token credential stored on Jenkin, give in secretID
env.stagingBranch = ""                                      // OPTIONAL, Staging branch won't trigger merge build pipeline


/** Sonar config **/
env.maximumAllowedBugs = 0
env.maximumAllowedVunerabilities = 0
env.maximumAllowedCodeSmell = 0


/** Build prefix for building report **/
env.pushBuildPrefix = "JENKINS-PUSH"
env.mrBuildPrefix = "JENKINS-MERGE"
env.acceptCloseMRBuildPrefix = "JENKINS-ACCEPT-CLOSE"

Feature: Dynamic Environment

VTS KIT provides ability to use environment from container. All system environment which are started with VTS_KIT_ will be collected and injected into Web Server on running. Developer can reference to these environment inside window.env.

Ways to make changes to environments:

  • 1. Add environment inside kubernetes YAML deployment
  • 2. Use kubectl to change environment while application is running (require rolloul restart)
  • 3. Set environment on running docker (if deploy as docker)
  1. Add environment inside kubernetes YAML deployment:

For example, make change to development profile, create two environemnt VTS_KIT_ENV1 and VTS_KIT_ENV2. You can find kubernetes YAML under cicd/manifests/dev-deploy-manifest.yaml.

---
apiVersion: v1
kind: Service
metadata:
  name: {{appName}}-svc
  labels:
    app: {{appName}}
  namespace: {{devNamespace}}
spec:
  type: NodePort
  ports:
    - port: {{devPort}}
      name: {{appName}}-external-port
      protocol: TCP
      targetPort: {{devTargetPort}}
      nodePort: {{devNodePort}}
  selector:
    app: {{appName}}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{appName}}-deployment
  labels:
    app: {{appName}}
  namespace: {{devNamespace}}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{appName}}
  template:
    metadata:
      labels:
        app: {{appName}}
    spec:
      containers:
        - name: {{appName}}-container
          image: {{imageName}}
          env:
            - name: VTS_KIT_ENV1
              value: "Hello"
            - name: VTS_KIT_ENV2
              value: "World"
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: {{devTargetPort}}
      imagePullSecrets:
        - name: {{devImagePullSecrets}}
  1. Use kubectl to change environment while application is running (require rolloul restart)

Use kubectl CLI to make change to an applied-deployment.

  // Set new environemtn
  kubectl set env deployment/demo VTS_KIT_ENV1=hello

  // Rollout restart to apply change
  kubectl rollout restart deployment/demo

  // Unset environment (Also need to rollout restart to apply change)
  kubectl set env deployment/demo VTS_KIT_ENV1-
  1. Set environment on running docker (if deploy as docker)

Use docker CLI to set environment on running an image

  docker run -e VTS_KIT_ENV1=hello -t webapp-demo:1.0.0

Feature: 3rd party integration

VTS KIT offers libraries that facilitate the integration of third-party libraries and services with minimal effort.

Check out documentation for more detail.

References

Contribute Guidelines

If you have any ideas, just open an issue and tell us what you think.

If you'd like to contribute, please refer Contributors Guide

License

This code is under the MIT License.

See the LICENSE file for required notices and attributions.

1.0.10

10 months ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.6-beta3

1 year ago

1.0.6-beta2

1 year ago

1.0.6-beta1

1 year ago

1.0.6-beta

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.1

2 years ago