Skip to content

Commit

Permalink
feat: atualização para pipeline b2c
Browse files Browse the repository at this point in the history
  • Loading branch information
raul melo authored and raul melo committed Mar 13, 2024
1 parent 912158a commit 04635fc
Show file tree
Hide file tree
Showing 18 changed files with 444 additions and 353 deletions.
499 changes: 192 additions & 307 deletions angular.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion application-webcomponents/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wizco/schematics-webcomponents",
"version": "17.1.21",
"version": "17.2.0",
"description": "Wizpro angular schematics for module MFE",
"scripts": {
"build": "tsc -p tsconfig.json",
Expand Down
56 changes: 43 additions & 13 deletions application-webcomponents/src/env-b2c/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
*/

import {
apply,
chain,
MergeStrategy,
mergeWith,
move,
Rule,
SchematicContext,
SchematicsException,
Tree,
Tree,
url,
} from '@angular-devkit/schematics';
import { OptionsDefaultModule } from '../types/options.types';

function addPipelineDefault(): Rule {
function addStepb2c(options: OptionsDefaultModule): Rule {
return (tree: Tree, context: SchematicContext) => {

// eslint-disable-next-line no-debugger
debugger
context.logger.info('Adicionando o pipeline default...');
context.logger.info('Adicionando angular.json');
const angularJson = tree.read(`angular.json`)!.toString('utf-8');

if (!angularJson) {
Expand All @@ -28,6 +31,7 @@ function addPipelineDefault(): Rule {

const packageJsonObject = JSON.parse(angularJson.toString());
const projects = packageJsonObject.projects;
const projectsKeys = [];

for (const project in projects) {
if (
Expand All @@ -38,21 +42,29 @@ function addPipelineDefault(): Rule {
projects[project].architect.build.configurations.sandbox
) {
// script para criar o arquivo environment.b2c.ts
const sandboxConfig = projects[project].architect.build.configurations.sandbox;
const sandboxConfig =
projects[project].architect.build.configurations.sandbox;
const local = sandboxConfig['fileReplacements'][0]['with'];
const localSandbox = tree.read(local)!.toString('utf-8');
const localB2CPath = local.replace('environment.sandbox.ts', 'environment.b2c.ts');
if(tree.exists(localB2CPath)) {
const localB2CPath = local.replace(
'environment.sandbox.ts',
'environment.b2c.ts'
);
if (tree.exists(localB2CPath)) {
tree.delete(localB2CPath);
}
projectsKeys.push(` - ${project}`);
tree.create(localB2CPath, localSandbox);
// script para adicionar no angular.json
projects[project].architect.build.configurations['b2c'] = {
...sandboxConfig,
fileReplacements: [
{
replace: sandboxConfig['fileReplacements'][0]['replace'],
with: local.replace('environment.sandbox.ts', 'environment.b2c.ts' ),
with: local.replace(
'environment.sandbox.ts',
'environment.b2c.ts'
),
},
],
};
Expand All @@ -64,15 +76,33 @@ function addPipelineDefault(): Rule {
projects: projects,
};

if (projectsKeys.length > 0) {
context.logger.info('Trocando pipeline de build para b2c');

/// pegando novo template de pipeline
let textPipeline = tree.read(`azure-pipelines.yml`)!.toString('utf-8');
if (textPipeline) {
const templateModules = projectsKeys.join('');
// eslint-disable-next-line no-debugger
textPipeline = textPipeline
.replace(/<%= PROJECTS_NAMES%>/g, templateModules)
.replace(/<%= PRODUCT_NAME%>/g, options.produtoDigital);

tree.overwrite(`azure-pipelines.yml`, textPipeline);
}
}

tree.overwrite(`angular.json`, JSON.stringify(newAngular, null, 2));
return tree
return tree;
};
}

export default function (): Rule {
export default function (options: OptionsDefaultModule): Rule {
return () => {
const templateSource = apply(url('./root-files'), [move('/')]);
return chain([
addPipelineDefault()
mergeWith(templateSource, MergeStrategy.Overwrite),
addStepb2c(options),
]);
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Angular
# Build and test Angular Projects.
# Autor: Zama Bandeira Braga <zamabraga@wiz.co>
# Mais informação: https://wizco.topdesk.net/tas/public/ssp/content/detail/knowledgeitem?unid=e7d0f51ade324ec289891b0892dd0837
# Issues: https://wizco.topdesk.net/tas/public/ssp/content/serviceflow?unid=3cd6a6f61e4a49689212298c0cdbd427&from=86304f95-4cc7-46aa-ae25-1c6af55eafc5&openedFromService=true
# Exemplos: https://dev.azure.com/wizsolucoes/WizPipelines/_git/exemplos

resources:
repositories:
- repository: coretemplate
type: git
name: WizPipelines/core-template
ref: refs/heads/angular-v2

pool:
vmImage: ubuntu-latest

trigger:
batch: 'true'
branches:
exclude: [ 'refs/heads/feature/*' ]
paths:
exclude:
- README.md

extends:
template: angular/modulo.yml@coretemplate
parameters:
produtoDigital: <%= PRODUCT_NAME%>
nodeVersion: "18.x"
modulos:
<%= PROJECTS_NAMES%>
20 changes: 20 additions & 0 deletions application-webcomponents/src/env-b2c/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@
"description": "Generates a new basic application definition in the \"projects\" subfolder of the workspace.",
"additionalProperties": false,
"properties": {
"produtoDigital": {
"description": "Produto digital ? Exemplo: Turbo",
"type": "string",
"enum": [
"Wiz Pro",
"TURBO",
"Converte",
"Automacao",
"Apps Corporativos",
"Financeiro",
"NEXO",
"Operacaoes"
],
"default": "Wiz Pro",
"x-prompt": {
"message": "Selecione o produto digital:",
"type": "list",
"default": "Wiz Pro"
}
},
"inlineStyle": {
"description": "Include styles inline in the root component.ts file. Only CSS styles can be included inline. Default is false, meaning that an external styles file is created and referenced in the root component.ts file.",
"type": "boolean",
Expand Down
20 changes: 20 additions & 0 deletions application-webcomponents/src/ng-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@
"type": "string",
"visible": false
},
"produtoDigital": {
"description": "Produto digital ? Exemplo: Turbo",
"type": "string",
"enum": [
"Wiz Pro",
"TURBO",
"Converte",
"Automacao",
"Apps Corporativos",
"Financeiro",
"NEXO",
"Operacaoes"
],
"default": "Wiz Pro",
"x-prompt": {
"message": "Selecione o produto digital:",
"type": "list",
"default": "Wiz Pro"
}
},
"versionAngular": {
"description": "Versão do Angular",
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@
"type": "string",
"visible": false
},
"produtoDigital": {
"description": "Produto digital ? Exemplo: Turbo",
"type": "string",
"enum": [
"Wiz Pro",
"TURBO",
"Converte",
"Automacao",
"Apps Corporativos",
"Financeiro",
"NEXO",
"Operacaoes"
],
"default": "Wiz Pro",
"x-prompt": {
"message": "Selecione o produto digital:",
"type": "list",
"default": "Wiz Pro"
}
},
"versionAngular": {
"description": "Versão do Angular",
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@
"type": "string",
"visible": false
},
"produtoDigital": {
"description": "Produto digital ? Exemplo: Turbo",
"type": "string",
"enum": [
"Wiz Pro",
"TURBO",
"Converte",
"Automacao",
"Apps Corporativos",
"Financeiro",
"NEXO",
"Operacaoes"
],
"default": "Wiz Pro",
"x-prompt": {
"message": "Selecione o produto digital:",
"type": "list",
"default": "Wiz Pro"
}
},
"versionAngular": {
"description": "Versão do Angular",
"type": "string",
Expand Down
20 changes: 20 additions & 0 deletions application-webcomponents/src/template-mfe/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@
"type": "string",
"visible": false
},
"produtoDigital": {
"description": "Produto digital ? Exemplo: Turbo",
"type": "string",
"enum": [
"Wiz Pro",
"TURBO",
"Converte",
"Automacao",
"Apps Corporativos",
"Financeiro",
"NEXO",
"Operacaoes"
],
"default": "Wiz Pro",
"x-prompt": {
"message": "Selecione o produto digital:",
"type": "list",
"default": "Wiz Pro"
}
},
"versionAngular": {
"description": "Versão do Angular",
"type": "string",
Expand Down
8 changes: 5 additions & 3 deletions application-webcomponents/src/template-pipeline-ci/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import {
} from '@angular-devkit/schematics';
import { OptionsDefaultModule } from '../types/options.types';

function addPipelineDefault(name: string): Rule {
function addPipelineDefault(name: string, produtoDigital: string): Rule {
return (tree: Tree, context: SchematicContext) => {
context.logger.info('Adicionando o pipeline default...');
let textPipeline = tree.read(`azure-pipelines.yml`)!.toString('utf-8');

if (textPipeline) {
textPipeline = textPipeline.replace(/<%= folderName%>/g, name);
textPipeline = textPipeline
.replace(/<%= folderName%>/g, name)
.replace(/<%= PRODUCT_NAME%>/g, produtoDigital);
}

tree.overwrite(`azure-pipelines.yml` , textPipeline);
Expand All @@ -41,7 +43,7 @@ export default function (options: OptionsDefaultModule): Rule {
]);
return chain([
mergeWith(templateSource, MergeStrategy.Overwrite),
addPipelineDefault(options.name)
addPipelineDefault(options.name, options.produtoDigital)
]);
};
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
# Node.js with Angular
# Build a Node.js project that uses Angular.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
# YAML reference:
# https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema
# Angular
# Build and test Angular Projects.
# Autor: Zama Bandeira Braga <zamabraga@wiz.co>
# Mais informação: https://wizco.topdesk.net/tas/public/ssp/content/detail/knowledgeitem?unid=e7d0f51ade324ec289891b0892dd0837
# Issues: https://wizco.topdesk.net/tas/public/ssp/content/serviceflow?unid=3cd6a6f61e4a49689212298c0cdbd427&from=86304f95-4cc7-46aa-ae25-1c6af55eafc5&openedFromService=true
# Exemplos: https://dev.azure.com/wizsolucoes/WizPipelines/_git/exemplos

resources:
repositories:
- repository: coretemplate
type: git
name: WizPipelines/core-template
ref: refs/heads/equinix
ref: refs/heads/angular-v2

pool:
vmImage: ubuntu-latest

trigger:
batch: 'true'
branches:
exclude: ["refs/heads/feature/*"]
exclude: [ 'refs/heads/feature/*' ]
paths:
exclude: ["README.md"]

pool:
vmImage: "ubuntu-latest"

exclude:
- README.md

extends:
template: main.yml@coretemplate
template: angular/modulo.yml@coretemplate
parameters:
technology: "angular"
deploymentType: "webapp"
azResourceName: "<%= folderName%>"
azSubscriptionUAT: "WX1"
azSubscriptionPRD: "WX1"
instrumentationKey: "c9dd9600-aa5b-4a28-9fd7-5e472cd30899"
npmNodeVersion: '18'
appConfig:
httpPath: "modulo"
httpPathModule: "<%= folderName%>"
produtoDigital: <%= PRODUCT_NAME%>
nodeVersion: "18.x"
modulos:
- <%= folderName%>
20 changes: 20 additions & 0 deletions application-webcomponents/src/template-pipeline-ci/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@
"description": "Generates a new basic application definition in the \"projects\" subfolder of the workspace.",
"additionalProperties": false,
"properties": {
"produtoDigital": {
"description": "Produto digital ? Exemplo: Turbo",
"type": "string",
"enum": [
"Wiz Pro",
"TURBO",
"Converte",
"Automacao",
"Apps Corporativos",
"Financeiro",
"NEXO",
"Operacaoes"
],
"default": "Wiz Pro",
"x-prompt": {
"message": "Selecione o produto digital:",
"type": "list",
"default": "Wiz Pro"
}
},
"projectRoot": {
"description": "The root directory of the new app.",
"type": "string",
Expand Down
Loading

0 comments on commit 04635fc

Please sign in to comment.