Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions packages/pipes-angular/.build/generator.script.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* angular - pipes
* --------------------------------------
* This script reads the pipes.json and creates
* out of this information the pipess.ts file, which
* adds the pipes to the angular framework.
*/

const path = require('path')
const file = require('../../../.build/file')
const { title } = require('../../../.build/log')
const utilities = require('../../../.build/utilities')

const run = async () => {
await title('angular : pipes')
const files = await utilities.read({ fileName: 'pipes' })
const pipes = files.map(f => f.functions[0])

const functions = pipes.map(f => f.name)
const utilPipes = pipes.map(f => ` ${f.name.charAt(0).toUpperCase() + f.name.slice(1)}Pipe`)
const utilPipesClass = pipes.map(f =>
[
'@Pipe({',
` name: '${f.name}'`,
'})',
`export class ${f.name.charAt(0).toUpperCase() + f.name.slice(1)}Pipe implements PipeTransform {`,
` transform = ${f.name}`,
'}',
'',
].join('\n'),
)

const content = [
'// generated file by .build/generator.script.js',
'',
`import { Pipe, PipeTransform } from '@angular/core';`,
`import {`,
` ${functions.join(',\n ')}`,
`} from '@baloise/web-app-pipes'`,
'',
utilPipesClass.join('\n'),
'export const PIPES = [',
utilPipes.join(',\n'),
']',
].join('\n')

await file.save(path.join(__dirname, '../src/pipes.ts'), content)
}

run()
20 changes: 16 additions & 4 deletions packages/pipes-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"banner": "node ../../.build/banner.js pipes-angular",
"update:registry": "sed -i -e \"s#nexus.balgroupit.com/repository/npm#registry.npmjs.org#g\" package-lock.json\n",
"build": "npm run banner && npm run clean && npm run build:generator && npm run build:compile",
"build:generator": "node .build/generator.script.js",
"build:generator": "node .build/generator.script.cjs",
"build:compile": "ng-packagr -p ng-package.json",
"clean": "rimraf src/pipes.ts && rimraf dist"
},
Expand Down Expand Up @@ -55,11 +55,23 @@
"files": [
"dist/"
],
"main": "dist/fesm2020/baloise-web-app-pipes-angular.mjs",
"module": "dist/fesm2015/baloise-web-app-pipes-angular.js",
"type": "module",
"main": "dist/fesm2022/baloise-web-app-pipes-angular.mjs",
"module": "dist/fesm2022/baloise-web-app-pipes-angular.mjs",
"es2015": "dist/fesm2015/baloise-web-app-pipes-angular.mjs",
"es2020": "dist/fesm2020/baloise-web-app-pipes-angular.mjs",
"esm2020": "dist/esm2020/baloise-web-app-pipes-angular.mjs",
Comment thread
lazaki marked this conversation as resolved.
"typings": "dist/index.d.ts",
"sideEffects": false
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"esm2022": "./dist/esm2022/baloise-web-app-pipes-angular.mjs",
"esm": "./dist/esm2022/baloise-web-app-pipes-angular.mjs",
"default": "./dist/fesm2022/baloise-web-app-pipes-angular.mjs"
},
"./package.json": {
"default": "./package.json"
}
}
}
46 changes: 46 additions & 0 deletions packages/validators-angular/.build/generator.script.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const path = require('path')
const file = require('../../../.build/file')
const { title } = require('../../../.build/log')
const utilities = require('../../../.build/utilities')

const run = async () => {
await title('angular : validators')
const files = await utilities.read({ fileName: 'validators' })
const validators = files
.reduce((acc, f) => {
return [...acc, ...f.functions]
}, [])
.map(v => {
const params = v.parameters.map(p => `${p.name}: ${p.type}`)
params.push(`errorName = '${v.name}'`)
return `
export function ${v.name}(${params.join(', ')}): ValidatorFn {
return (control: AbstractControl): { [key: string]: any } | null => {
return validate(BalValidators.${v.name}(${v.parameters.map(p => p.name).join(', ')})(control.value), errorName, control)
}
}`
})

const content = [
'// generated file by .build/generator.script.js',
'',
`import { AbstractControl, ValidatorFn } from '@angular/forms';`,
`import { BalValidators, BalValidatorFn } from '@baloise/web-app-validators'`,
`
function createError(key: string, control: AbstractControl) {
return {
[\`\${key}\`]: { value: control.value },
}
}

function validate(result: boolean, key: string, control: AbstractControl) {
return result === undefined || result === true ? null : createError(key, control)
}`,
validators.join('\n'),
'',
].join('\n')

await file.save(path.join(__dirname, '../src/validators.ts'), content)
}

run()
20 changes: 16 additions & 4 deletions packages/validators-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"banner": "node ../../.build/banner.js validators-angular",
"update:registry": "sed -i -e \"s#nexus.balgroupit.com/repository/npm#registry.npmjs.org#g\" package-lock.json\n",
"build": "npm run banner && npm run clean && npm run build:generator && npm run build:compile",
"build:generator": "node .build/generator.script.js",
"build:generator": "node .build/generator.script.cjs",
"build:compile": "ng-packagr -p ng-package.json",
"clean": "rimraf src/validators.ts && rimraf dist"
},
Expand Down Expand Up @@ -56,11 +56,23 @@
"files": [
"dist/"
],
"main": "dist/fesm2020/baloise-web-app-validators-angular.mjs",
"module": "dist/fesm2015/baloise-web-app-validators-angular.js",
"type": "module",
"main": "dist/fesm2022/baloise-web-app-validators-angular.mjs",
"module": "dist/fesm2022/baloise-web-app-validators-angular.mjs",
"es2015": "dist/fesm2015/baloise-web-app-validators-angular.mjs",
"es2020": "dist/fesm2020/baloise-web-app-validators-angular.mjs",
"esm2020": "dist/esm2020/baloise-web-app-validators-angular.mjs",
Comment thread
lazaki marked this conversation as resolved.
"typings": "dist/index.d.ts",
"sideEffects": false
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"esm2022": "./dist/esm2022/baloise-web-app-validators-angular.mjs",
"esm": "./dist/esm2022/baloise-web-app-validators-angular.mjs",
"default": "./dist/fesm2022/baloise-web-app-validators-angular.mjs"
},
"./package.json": {
"default": "./package.json"
}
}
}
Loading