Skip to content

Commit a49502d

Browse files
authored
chore: Initial code with checks
2 parents f990086 + 8d1e6bd commit a49502d

69 files changed

Lines changed: 22558 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/deploy.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Deployment
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
env:
10+
CI: false
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
node-version: [16.x]
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
- name: Install Dependencies
24+
run: |
25+
npm install
26+
npm install --save-dev karma-junit-reporter karma-coverage karma-sonarqube-unit-reporter
27+
- name: Run Tests
28+
run: npm run test:ci
29+
- name: Upload Test Results
30+
if: always()
31+
uses: actions/upload-artifact@v2
32+
with:
33+
name: test-results
34+
path: |
35+
reports/junit/test-results.xml
36+
coverage/lcov/lcov.info
37+
coverage/cobertura.xml
38+
39+
build:
40+
needs: test
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v2
44+
- name: Use Node.js 16.x
45+
uses: actions/setup-node@v1
46+
with:
47+
node-version: 16.x
48+
- name: Install Dependencies
49+
run: npm install
50+
- name: Build
51+
run: npm run build
52+
- name: Upload Build Artifacts
53+
uses: actions/upload-artifact@v2
54+
with:
55+
name: build-output
56+
path: ./build
57+
58+
deploy:
59+
needs: build
60+
runs-on: ubuntu-latest
61+
if: github.ref == 'refs/heads/master'
62+
steps:
63+
- uses: actions/checkout@v2
64+
- name: Download Build Artifacts
65+
uses: actions/download-artifact@v2
66+
with:
67+
name: build-output
68+
path: ./build
69+
- name: Deploy to gh-pages
70+
uses: peaceiris/actions-gh-pages@v3
71+
with:
72+
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
73+
publish_dir: ./build

angular.json

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"projects": {
5+
"vf-angular-boilerplate": {
6+
"projectType": "application",
7+
"root": "",
8+
"sourceRoot": "src",
9+
"prefix": "app",
10+
"architect": {
11+
"build": {
12+
"builder": "@angular-devkit/build-angular:browser",
13+
"options": {
14+
"outputPath": "dist/vf-angular-boilerplate",
15+
"index": "src/index.html",
16+
"main": "src/main.ts",
17+
"polyfills": "src/polyfills.ts",
18+
"tsConfig": "tsconfig.json",
19+
"aot": true,
20+
"assets": [
21+
"src/favicon.ico",
22+
"src/assets"
23+
],
24+
"styles": [
25+
"src/styles.scss"
26+
],
27+
"scripts": []
28+
},
29+
"configurations": {
30+
"production": {
31+
"fileReplacements": [
32+
{
33+
"replace": "src/environments/environment.ts",
34+
"with": "src/environments/environment.prod.ts"
35+
}
36+
],
37+
"optimization": true,
38+
"outputHashing": "all",
39+
"sourceMap": false,
40+
"extractCss": true,
41+
"namedChunks": false,
42+
"extractLicenses": true,
43+
"vendorChunk": false,
44+
"buildOptimizer": true,
45+
"budgets": [
46+
{
47+
"type": "initial",
48+
"maximumWarning": "2mb",
49+
"maximumError": "5mb"
50+
}
51+
]
52+
},
53+
"development": {
54+
"fileReplacements": [
55+
{
56+
"replace": "src/environments/environment.ts",
57+
"with": "src/environments/environment.dev.ts"
58+
}
59+
],
60+
"optimization": false,
61+
"outputHashing": "none",
62+
"sourceMap": true,
63+
"extractCss": false,
64+
"namedChunks": true,
65+
"extractLicenses": false,
66+
"vendorChunk": true,
67+
"buildOptimizer": false
68+
}
69+
}
70+
},
71+
"serve": {
72+
"builder": "@angular-devkit/build-angular:dev-server",
73+
"options": {
74+
"browserTarget": "vf-angular-boilerplate:build"
75+
},
76+
"configurations": {
77+
"production": {
78+
"browserTarget": "vf-angular-boilerplate:build:production"
79+
},
80+
"development": {
81+
"browserTarget": "vf-angular-boilerplate:build:development"
82+
}
83+
}
84+
},
85+
"test": {
86+
"builder": "@angular-devkit/build-angular:karma",
87+
"options": {
88+
"main": "src/test.ts",
89+
"polyfills": "src/polyfills.ts",
90+
"tsConfig": "tsconfig.spec.json",
91+
"karmaConfig": "karma.conf.js",
92+
"assets": [
93+
"src/favicon.ico",
94+
"src/assets"
95+
],
96+
"styles": [
97+
"src/styles.scss"
98+
],
99+
"scripts": []
100+
}
101+
}
102+
}
103+
}
104+
}
105+
}

gulpfile.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
const gulp = require('gulp');
2+
const { exec } = require('child_process');
3+
const shell = require('gulp-shell');
4+
5+
// Helper function to run Angular CLI commands
6+
function runNgTest(options = []) {
7+
return new Promise((resolve, reject) => {
8+
const command = `ng test ${options.join(' ')}`;
9+
const child = exec(command);
10+
11+
child.stdout.on('data', (data) => {
12+
process.stdout.write(data);
13+
});
14+
15+
child.stderr.on('data', (data) => {
16+
process.stderr.write(data);
17+
});
18+
19+
child.on('close', (code) => {
20+
if (code === 0) {
21+
resolve();
22+
} else {
23+
reject(new Error(`ng test failed with code ${code}`));
24+
}
25+
});
26+
});
27+
}
28+
29+
// Task to run all tests in CI mode
30+
gulp.task('test:ci', async () => {
31+
try {
32+
await runNgTest([
33+
'--no-watch',
34+
'--browsers=ChromeHeadless',
35+
'--code-coverage',
36+
'--source-map=true',
37+
'--progress=false',
38+
'--reporters=junit,coverage',
39+
'--karma-config=karma.conf.ci.js'
40+
]);
41+
} catch (error) {
42+
console.error('CI Test execution failed:', error);
43+
process.exit(1); // Ensure pipeline fails on test errors
44+
}
45+
});
46+
47+
// Task to run all tests including VF components
48+
gulp.task('test:all', async () => {
49+
try {
50+
await runNgTest([
51+
'--watch=false',
52+
'--browsers=ChromeHeadless',
53+
'--code-coverage',
54+
'--source-map=true'
55+
]);
56+
} catch (error) {
57+
console.error('Test execution failed:', error);
58+
throw error;
59+
}
60+
});
61+
62+
// Task to run tests for a specific VF component
63+
gulp.task('test:vf-component', async () => {
64+
const componentArg = process.argv.find(arg => arg.startsWith('--component='));
65+
if (!componentArg) {
66+
throw new Error('Please specify a component: gulp test:vf-component --component=vf-badge');
67+
}
68+
69+
const componentName = componentArg.split('=')[1];
70+
const testFile = `node_modules/@visual-framework/${componentName}/${componentName}.angular/**/*.spec.ts`;
71+
72+
try {
73+
await runNgTest([
74+
'--no-watch',
75+
'--browsers=ChromeHeadless',
76+
`--include=${testFile}`
77+
]);
78+
} catch (error) {
79+
console.error('Test execution failed:', error);
80+
throw error;
81+
}
82+
});
83+
84+
// Task to run tests in watch mode (development only)
85+
gulp.task('test:watch', async () => {
86+
try {
87+
await runNgTest(['--browsers=Chrome']);
88+
} catch (error) {
89+
console.error('Test execution failed:', error);
90+
throw error;
91+
}
92+
});
93+
94+
// Watch folders for changes
95+
gulp.task('watch', shell.task([
96+
'ng build --watch --configuration development'
97+
]));
98+
99+
// run ng in build mode
100+
gulp.task('build', shell.task([
101+
'ng build'
102+
]));
103+
104+
// run ng in dev mode
105+
gulp.task('dev', shell.task([
106+
'ng serve'
107+
]));
108+
109+
// Just build the assets, CSS and JS for VF components
110+
gulp.task('build-vf-assets', gulp.series(
111+
'build'
112+
));
113+
114+
// Build and watch things during dev
115+
gulp.task('dev', gulp.series(
116+
gulp.parallel('dev', 'watch')
117+
));

karma.conf.ci.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const baseConfig = require('./karma.conf.js');
2+
3+
module.exports = function(config) {
4+
baseConfig(config);
5+
6+
config.set({
7+
// Override base configuration for CI
8+
browsers: ['ChromeHeadless'],
9+
autoWatch: false,
10+
singleRun: true,
11+
plugins: [
12+
require('karma-jasmine'),
13+
require('karma-chrome-launcher'),
14+
require('karma-jasmine-html-reporter'),
15+
require('karma-coverage'),
16+
require('karma-junit-reporter'),
17+
require('karma-sonarqube-unit-reporter'),
18+
require('@angular-devkit/build-angular/plugins/karma')
19+
],
20+
reporters: ['progress', 'junit', 'coverage', 'sonarqube'],
21+
junitReporter: {
22+
outputDir: 'reports/junit',
23+
outputFile: 'test-results.xml',
24+
useBrowserName: false,
25+
nameFormatter: undefined,
26+
classNameFormatter: undefined,
27+
properties: {}
28+
},
29+
coverageReporter: {
30+
dir: 'coverage',
31+
reporters: [
32+
{ type: 'lcov', subdir: 'lcov' },
33+
{ type: 'text-summary' },
34+
{ type: 'cobertura', subdir: '.', file: 'cobertura.xml' }
35+
]
36+
},
37+
sonarqubeReporter: {
38+
outputFile: 'reports/sonarqube/report.xml',
39+
useBrowserName: false
40+
}
41+
});
42+
};

0 commit comments

Comments
 (0)