diff --git a/.github/PULL_REQUEST_TEMPATE.md b/.github/PULL_REQUEST_TEMPATE.md index 622e729..bd84c0d 100644 --- a/.github/PULL_REQUEST_TEMPATE.md +++ b/.github/PULL_REQUEST_TEMPATE.md @@ -1,14 +1,19 @@ ## Description + ### What's included? + + - One - Two - Three #### Test Steps + + - [ ] `npm ci` - [ ] In `proxy.conf.js` file, change serverUrl to `https://appcenter.ux.ac.uda.io` - [ ] `npm run serve` diff --git a/karma.conf.js b/karma.conf.js index 3f8f613..213d5de 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,7 +1,7 @@ // Karma configuration file, see link for more information // https://karma-runner.github.io/0.13/config/configuration-file.html -module.exports = function(config) { +module.exports = function (config) { config.set({ basePath: '.', frameworks: ['jasmine', '@angular-devkit/build-angular'], diff --git a/package.json b/package.json index 772b257..c53806e 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "test": "ng test ui-platform --code-coverage --source-map=false --watch=false", "coveralls": "cat ./coverage/lcov.info | node ./node_modules/coveralls/bin/coveralls.js", "build:lib": "bash scripts/build-release && gulp version-placeholder", + "test:schematics": "tsc -p src/lib/schematics/tsconfig.spec.json && jasmine src/lib/schematics/**/*.spec.js", "release:start": "bash scripts/start-release", "release:finish": "bash scripts/finish-release", "generate:changelog": "./node_modules/.bin/conventional-changelog -i docs/CHANGELOG.md -s -p angular", diff --git a/protractor.conf.js b/protractor.conf.js index a222ca3..68c9a35 100644 --- a/protractor.conf.js +++ b/protractor.conf.js @@ -16,15 +16,15 @@ exports.config = { jasmineNodeOpts: { showColors: true, defaultTimeoutInterval: 30000, - print: function() {}, + print: function () {}, }, useAllAngular2AppRoots: true, - beforeLaunch: function() { + beforeLaunch: function () { require('ts-node').register({ project: 'e2e', }); }, - onPrepare: function() { + onPrepare: function () { jasmine.getEnv().addReporter(new SpecReporter()); }, }; diff --git a/scripts/bump-version.js b/scripts/bump-version.js index e8921d9..fb1ec04 100644 --- a/scripts/bump-version.js +++ b/scripts/bump-version.js @@ -12,7 +12,7 @@ var knownOptions = { var options = minimist(process.argv.slice(2), knownOptions); -gulp.task('bump-version', function() { +gulp.task('bump-version', function () { if (!options.ver) { throw '--ver is required'; } diff --git a/scripts/schematics/update-schematics.sh b/scripts/schematics/update-schematics.sh new file mode 100644 index 0000000..0de9b66 --- /dev/null +++ b/scripts/schematics/update-schematics.sh @@ -0,0 +1,25 @@ +# Run test and linter +npm run test:schematics +npm run tslint + +# Link project +cd ../../src/lib +npm link + +# Create Angular base project +cd /tmp +rm -rf testxyz +ng new testxyz +cd testxyz +ng add @angular/material @angular-devkit/schematics @angular/cdk +ng add @covalent/core + +# Run covalent schematics +cd testxyz +git add .; git commit -m 'fix(update): commit updated'; +npm link @td-vantage/ui-platform +ng update @td-vantage/ui-platform --migrate-only --from=0.0.0 --to=3.0.1 + +# Check generated files +git status +npm i \ No newline at end of file diff --git a/scripts/version-placeholders.js b/scripts/version-placeholders.js index 5d92a97..d7b43ac 100644 --- a/scripts/version-placeholders.js +++ b/scripts/version-placeholders.js @@ -8,7 +8,7 @@ var gulp = require('gulp'); const buildConfig = require('../build.conf'); const packageJson = require('../package.json'); -gulp.task('version-placeholder', function(cb) { +gulp.task('version-placeholder', function (cb) { replaceVersionPlaceholders(buildConfig.deployed, packageJson.version); cb(); }); diff --git a/src/lib/auth/config/vantageLoginProxyConfig.js b/src/lib/auth/config/vantageLoginProxyConfig.js index 6271b6b..c4fb5fd 100644 --- a/src/lib/auth/config/vantageLoginProxyConfig.js +++ b/src/lib/auth/config/vantageLoginProxyConfig.js @@ -2,11 +2,11 @@ function VantageLoginProxyConfig({ serverUrl, localUrl, localProto }) { return { '/start-login': { target: serverUrl, - bypass: function(req, res, proxyOptions) { + bypass: function (req, res, proxyOptions) { req.headers['X-Orig-Host'] = localUrl; req.headers['X-Orig-Proto'] = localProto; }, - pathRewrite: function(path) { + pathRewrite: function (path) { return path.replace(/^(\/start-login)/, '') || '/'; }, secure: false, diff --git a/src/lib/package-lock.json b/src/lib/package-lock.json new file mode 100644 index 0000000..93dcfca --- /dev/null +++ b/src/lib/package-lock.json @@ -0,0 +1,5 @@ +{ + "name": "@td-vantage/ui-platform", + "version": "0.0.0-PLATFORM", + "lockfileVersion": 1 +} diff --git a/src/lib/package.json b/src/lib/package.json index c337996..202407c 100644 --- a/src/lib/package.json +++ b/src/lib/package.json @@ -10,6 +10,9 @@ }, "license": "MIT", "author": "Teradata UI Team", + "ng-update": { + "migrations": "./schematics/migration.json" + }, "peerDependencies": { "@angular/common": "^0.0.0-NG", "@angular/core": "^0.0.0-NG", diff --git a/src/lib/schematics/.gitignore b/src/lib/schematics/.gitignore new file mode 100644 index 0000000..205f7c2 --- /dev/null +++ b/src/lib/schematics/.gitignore @@ -0,0 +1,4 @@ +# Outputs +**/*.js +**/*.js.map +**/*.d.ts \ No newline at end of file diff --git a/src/lib/schematics/migration.json b/src/lib/schematics/migration.json new file mode 100644 index 0000000..00f57e3 --- /dev/null +++ b/src/lib/schematics/migration.json @@ -0,0 +1,9 @@ +{ + "schematics": { + "covalent-migration-01": { + "description": "Upgrade to latest version", + "version": "3.0.1", + "factory": "./update/index#updateDependencies" + } + } +} diff --git a/src/lib/schematics/tsconfig.json b/src/lib/schematics/tsconfig.json new file mode 100644 index 0000000..72fa685 --- /dev/null +++ b/src/lib/schematics/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "rootDir": ".", + "baseUrl": ".", + "declaration": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "outDir": "../../../../deploy/ui-platform/schematics", + "lib": ["es2018", "dom"], + "moduleResolution": "node", + "sourceMap": true, + "target": "es6", + "typeRoots": ["./../../../../node_modules/@types"], + "noUnusedParameters": false, + "noUnusedLocals": false, + "allowUnreachableCode": false, + "pretty": true, + "importHelpers": true + }, + "include": ["**/*"], + "exclude": ["**/*.spec.ts", "**/files/**/*"] +} diff --git a/src/lib/schematics/tsconfig.spec.json b/src/lib/schematics/tsconfig.spec.json new file mode 100644 index 0000000..67de28c --- /dev/null +++ b/src/lib/schematics/tsconfig.spec.json @@ -0,0 +1,12 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "baseUrl": ".", + "outDir": "./update", + "lib": ["es6", "dom"], + "module": "commonjs", + "types": ["jasmine", "hammerjs", "node"] + }, + "include": ["**/*", "**/*.spec.ts"], + "exclude": ["*/files/**/*", "*/files/**/**/*"] +} diff --git a/src/lib/schematics/update/index.spec.ts b/src/lib/schematics/update/index.spec.ts new file mode 100644 index 0000000..d23d2fd --- /dev/null +++ b/src/lib/schematics/update/index.spec.ts @@ -0,0 +1,56 @@ +import { Tree } from '@angular-devkit/schematics'; +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; +import * as path from 'path'; + +import { Schema as WorkspaceOptions } from '@schematics/angular/workspace/schema'; +import { Schema as ApplicationOptions } from '@schematics/angular/application/schema'; +import chalk from 'chalk'; + +const green: any = chalk.green; +const yellow: any = chalk.yellow; + +const migrationPath: string = require.resolve('../migration.json'); +const packagePath: string = '/package.json'; + +function setup(): UnitTestTree { + const tree: UnitTestTree = Tree.empty() as UnitTestTree; + tree.create( + packagePath, + `{ + "dependencies": { + "@covalent/core": "1.0.0" + } + }`, + ); + + return tree; +} +describe('ng-update schematic', () => { + const testRunner: SchematicTestRunner = new SchematicTestRunner('rocket', migrationPath); + let appTree: UnitTestTree; + + beforeEach(async () => { + appTree = setup(); + }); + + it('should print console messages', async () => { + // tslint:disable-next-line: no-console + console.log = jasmine.createSpy('log'); + const tree: any = testRunner.runSchematic('covalent-migration-01', {}, appTree); + const pkg: any = JSON.parse(tree.readContent(packagePath)); + expect(pkg.dependencies['@covalent/core']).toBe(`latest`); + // tslint:disable-next-line: no-console + expect(console.log).toHaveBeenCalledWith(); + // tslint:disable-next-line + expect(console.log).toHaveBeenCalledWith(green(' ✓ Updated Covalent to latest')); + // tslint:disable-next-line + expect(console.log).toHaveBeenCalledWith(); + // tslint:disable-next-line + expect(console.log).toHaveBeenCalledWith( + yellow( + ' ⚠ Breaking changes are not applied automatically! Please refer the docs' + + '(https://github.com/Teradata/covalent/wiki) and fix the issues manually', + ), + ); + }); +}); diff --git a/src/lib/schematics/update/index.ts b/src/lib/schematics/update/index.ts new file mode 100644 index 0000000..99fe354 --- /dev/null +++ b/src/lib/schematics/update/index.ts @@ -0,0 +1,65 @@ +import { Rule, SchematicContext, Tree, SchematicsException } from '@angular-devkit/schematics'; +import chalk from 'chalk'; +import { TargetVersion } from './target-version'; + +const green: any = chalk.green; +const yellow: any = chalk.yellow; + +export interface IPackage { + dependencies?: object; +} + +export function updateDependencies(): Rule { + return (tree: Tree, context: SchematicContext) => { + context.logger.info('Running covalent update schematic ...'); + const pkgPath: string = '/package.json'; + const buffer: Buffer = tree.read(pkgPath); + if (buffer === undefined) { + throw new SchematicsException('Could not read package.json'); + } + const content: string = buffer.toString(); + const pkg: IPackage = JSON.parse(content); + + if (pkg === null || typeof pkg !== 'object' || Array.isArray(pkg)) { + throw new SchematicsException('Error reading package.json'); + } + + if (!pkg.dependencies) { + pkg.dependencies = {}; + } + + const packagesUpdated: boolean = updateCovalentPackage(pkg, tree, pkgPath); + if (packagesUpdated) { + onMigrationComplete(); + } + + return tree; + }; + + function updateCovalentPackage(pkg: IPackage, tree: Tree, pkgPath: string): boolean { + let isCovalentUpdated: boolean = false; + if (pkg.dependencies !== {} && Object.keys(pkg.dependencies) && Object.keys(pkg.dependencies).length !== 0) { + Object.keys(pkg.dependencies).forEach((key: string) => { + if (key.includes('@covalent')) { + pkg.dependencies[key] = TargetVersion.VERSION; + tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2)); + isCovalentUpdated = true; + } + }); + } + return isCovalentUpdated; + } + + function onMigrationComplete(): void { + // tslint:disable: no-console + console.log(); + console.log(green(` ✓ Updated Covalent to ${TargetVersion.VERSION}`)); + console.log(); + console.log( + yellow( + ' ⚠ Breaking changes are not applied automatically! Please refer the docs' + + '(https://github.com/Teradata/covalent/wiki) and fix the issues manually', + ), + ); + } +} diff --git a/src/lib/schematics/update/target-version.ts b/src/lib/schematics/update/target-version.ts new file mode 100644 index 0000000..2ece7f8 --- /dev/null +++ b/src/lib/schematics/update/target-version.ts @@ -0,0 +1,3 @@ +export enum TargetVersion { + VERSION = 'latest', +}