Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
osvaldopina committed Apr 4, 2019
1 parent 56103e0 commit 049ee9d
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 101 deletions.
29 changes: 29 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
},
{
"name": "ng test",
"type": "chrome",
"request": "launch",
"url": "http://localhost:9876/debug.html",
"webRoot": "${workspaceFolder}",
"sourceMaps": true,
"sourceMapPathOverrides": {
"/./*": "${webRoot}/*",
"/src/*": "${webRoot}/*",
"/*": "*",
"/./~/*": "${webRoot}/node_modules/*"
}
}
]
}
1 change: 1 addition & 0 deletions debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0402/120603.422:ERROR:crash_report_database_win.cc(569)] CreateDirectory C:\Users\DEINF~1.OSV\AppData\Local\Temp\karma-97167760\Crashpad: O sistema n�o pode encontrar o caminho especificado. (0x3)
10 changes: 7 additions & 3 deletions generate-zip.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
var zipFolder = require('zip-folder');

zipFolder('./dist/chrome-plugin', './dist/hal-chrome-plugin.zip', function(err) {
console.log('Could not generate extension zip! ' + err);
process.exit('-1');
zipFolder('./dist/chrome-plugin', './dist/hal-chrome-plugin.zip', function (err) {
if (err) {
console.log('Could not generate extension zip! ', err);
process.exit('-1');
} else {
console.log('Extension zip generated successfully!');
}
});
74 changes: 38 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "hal-render-component",
"version": "0.0.1",
"version": "0.0.4",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build-all-libraries": "ng build tree-model && ng build uri-template-editor && ng build hal-render-component",
"build": "npm run test && npm run build-all-libraries && ng build chrome-plugin --prod --output-hashing none && copyfiles -f projects/chrome-plugin/src/app/manifest.json dist/chrome-plugin",
"build": "npm run build-all-libraries && ng build chrome-plugin && copyfiles -f projects/chrome-plugin/src/app/manifest.json dist/chrome-plugin",
"build_": "npm run test && npm run build-all-libraries && ng build chrome-plugin && copyfiles -f projects/chrome-plugin/src/app/manifest.json dist/chrome-plugin",
"postbuild": "node ./adjust-manifest-version.js && node ./generate-zip.js",
"build-chrome-plugin": "ng build chrome-plugin --main projects/chrome-plugin/src/main.ts && copyfiles -f projects/chrome-plugin/src/app/manifest.json projects/chrome-plugin/src/app/icon.png dist/chrome-plugin",
"test": "ng test tree-model --watch=false && ng test uri-template-editor --watch=false",
Expand All @@ -14,47 +15,48 @@
},
"private": true,
"dependencies": {
"@angular/animations": "~7.1.0",
"@angular/common": "~7.1.0",
"@angular/compiler": "~7.1.0",
"@angular/core": "~7.1.0",
"@angular/forms": "~7.1.0",
"@angular/platform-browser": "~7.1.0",
"@angular/platform-browser-dynamic": "~7.1.0",
"@angular/router": "~7.1.0",
"core-js": "^2.5.4",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"@angular/animations": "~7.2.11",
"@angular/common": "~7.2.11",
"@angular/compiler": "~7.2.11",
"@angular/core": "~7.2.11",
"@angular/forms": "~7.2.11",
"@angular/platform-browser": "~7.2.11",
"@angular/platform-browser-dynamic": "~7.2.11",
"@angular/router": "~7.2.11",
"@webcomponents/custom-elements": "^1.2.2",
"core-js": "^3.0.0",
"rxjs": "~6.4.0",
"tslib": "^1.9.3",
"urijs": "^1.19.1",
"zone.js": "^0.8.16"
"zone.js": "^0.9.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.11.0",
"@angular-devkit/build-ng-packagr": "~0.11.0",
"@angular/cli": "~7.1.4",
"@angular/compiler-cli": "~7.1.0",
"@angular/language-service": "~7.1.0",
"@types/chrome": "0.0.60",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^8.9.5",
"codelyzer": "~4.5.0",
"@angular-devkit/build-angular": "~0.13.7",
"@angular-devkit/build-ng-packagr": "~0.13.7",
"@angular/cli": "~7.3.7",
"@angular/compiler-cli": "~7.2.11",
"@angular/language-service": "~7.2.11",
"@types/chrome": "0.0.81",
"@types/jasmine": "~3.3.12",
"@types/jasminewd2": "~2.0.6",
"@types/node": "^11.13.0",
"codelyzer": "~5.0.0",
"copyfiles": "^2.1.0",
"jasmine-core": "~2.99.1",
"jasmine-core": "~3.3.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.1",
"karma": "~4.0.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"ng-packagr": "^4.2.0",
"protractor": "~5.4.0",
"karma-coverage-istanbul-reporter": "~2.0.5",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"ng-packagr": "^5.0.1",
"protractor": "~5.4.2",
"replace-in-file": "^3.4.4",
"ts-node": "~7.0.0",
"tsickle": ">=0.29.0",
"tslib": "^1.9.0",
"tslint": "~5.11.0",
"typescript": "~3.1.6",
"ts-node": "~8.0.3",
"tsickle": ">=0.34.3",
"tslib": "^1.9.3",
"tslint": "~5.15.0",
"typescript": "^3.2.4",
"zip-folder": "^1.0.0"
}
}
2 changes: 1 addition & 1 deletion projects/chrome-plugin/src/app/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"64": "assets/hal_64.png"
},
"content_scripts": [
{ "matches": ["<all_urls>"], "js": ["main.js", "polyfills.js", "runtime.js"], "run_at": "document_start" }
{ "matches": ["<all_urls>"], "js": ["main.js", "polyfills.js", "runtime.js", "vendor.js"], "run_at": "document_start" }
],
"permissions":["*://*/*", "<all_urls>"]
}
3 changes: 2 additions & 1 deletion projects/chrome-plugin/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'core-js/es6/reflect';
// import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
Expand Down
2 changes: 1 addition & 1 deletion projects/chrome-plugin/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import '@webcomponents/custom-elements'; // Custom Elements Polyfill
import 'zone.js/dist/zone'; // Included with Angular CLI.
import 'core-js/es7/reflect';

/***************************************************************************************************
* APPLICATION IMPORTS
*/
6 changes: 2 additions & 4 deletions projects/hal-render-component/src/lib/hal-render.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input } from '@angular/core';
import { buildHalJsonTree, JsonElementNode } from 'tree-model';
import { buildHalJsonTree, JsonElementNode, Curies } from 'tree-model';

enum CurrentView {
RAW,
Expand All @@ -24,7 +24,7 @@ export class HalRenderComponent {

if (value && value.length > 0) {
this.json = value;
this.root = buildHalJsonTree(JSON.parse(value));
this.root = buildHalJsonTree(JSON.parse(value), new Curies(), true);
this.expandAll();
}
}
Expand Down Expand Up @@ -59,10 +59,8 @@ export class HalRenderComponent {

public versionFromChromeManifest() {
if (chrome && chrome.runtime && chrome.runtime.getManifest) {
console.log('buscarndo do manifest');
return chrome.runtime.getManifest().version;
} else {
console.log('buscarndo FORA do manifest');
return '(not running as chrome plugin!)';
}
}
Expand Down
142 changes: 102 additions & 40 deletions projects/tree-model/src/lib/tree-model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
buildHalJsonTree,
buildHalEmbeddedJsonTree,
getCurieName,
Curie
Curie,
Curies
} from './tree-model';

describe('buildJsonTree', () => {
Expand Down Expand Up @@ -314,8 +315,19 @@ describe('buildHalEmbeddedJsonTree', () => {
], false)
);
});
it('buildHalEmbeddedJsonTree for an array links rel ', () => {

it('buildHalEmbeddedJsonTree for an array _embedded rel', () => {
console.log(buildHalEmbeddedJsonTree({
'_embedded': {
'first-rel': [
{
'first-property': 'first property value'
},
{
'second-property': 'second property value'
}
]
}
}));
expect(
buildHalEmbeddedJsonTree({
'_embedded': {
Expand All @@ -341,6 +353,54 @@ describe('buildHalEmbeddedJsonTree', () => {
], true),
], false));
});
it('buildHalEmbeddedJsonTree for embedded array with _links', () => {
expect(
buildHalEmbeddedJsonTree({
'_embedded': {
'rel': [{
'_links': {
'self': { 'href': '/orders/123' }
}
}]
}
})
).toEqual(

jsonNodeElementFactory('_embedded', JsonElementType.Object, null, [
halNodeElementFactory('rel', JsonElementType.Array, HalElementType.LinkRel, null, [
jsonNodeElementFactory(null, JsonElementType.Object, null, [
jsonNodeElementFactory('_links', JsonElementType.Object, null, [
halNodeElementFactory('self', JsonElementType.Object, HalElementType.LinkRel, null, [
halNodeElementFactory('href', JsonElementType.String, HalElementType.LinkHref, '/orders/123', [], true)
], true)
], true),
], true),
], true),
], false));
});
it('buildHalEmbeddedJsonTree for embedded object with _links', () => {
expect(
buildHalEmbeddedJsonTree({
'_embedded': {
'rel': {
'_links': {
'self': { 'href': '/orders/123' }
}
}
}
})
).toEqual(

jsonNodeElementFactory('_embedded', JsonElementType.Object, null, [
halNodeElementFactory('rel', JsonElementType.Object, HalElementType.LinkRel, null, [
jsonNodeElementFactory('_links', JsonElementType.Object, null, [
halNodeElementFactory('self', JsonElementType.Object, HalElementType.LinkRel, null, [
halNodeElementFactory('href', JsonElementType.String, HalElementType.LinkHref, '/orders/123', [], true)
], true)
], true),
], true),
], false));
});
});
describe('buildHalJsonTree', () => {
it('buildHalJsonTree for an complete hal object', () => {
Expand Down Expand Up @@ -388,46 +448,48 @@ describe('buildHalJsonTree', () => {
'a-sub-object': {
'a-sub-object-property': 'a sub object property value'
}
})
).toEqual(
jsonNodeElementFactory('root', JsonElementType.Root, null, [
jsonNodeElementFactory('string-property', JsonElementType.String, 'string property value', [], false),
jsonNodeElementFactory('boolean-property', JsonElementType.Boolean, 'true', [], false),
jsonNodeElementFactory('array-property', JsonElementType.Array, null, [
jsonNodeElementFactory(null, JsonElementType.String, 'first-array-item', [], false),
jsonNodeElementFactory(null, JsonElementType.Boolean, 'false', [], false),
jsonNodeElementFactory(null, JsonElementType.Number, '123', [], true),
], false),
jsonNodeElementFactory('a-sub-object', JsonElementType.Object, null, [
jsonNodeElementFactory('a-sub-object-property', JsonElementType.String, 'a sub object property value', [], true),
], false),
jsonNodeElementFactory('_links', JsonElementType.Object, null, [
halNodeElementFactory('curie-name:curie-parameter', JsonElementType.Object, HalElementType.LinkRel, null, [
halNodeElementFactory('href', JsonElementType.String, HalElementType.LinkHref, 'http://self-url', [], true)
], false, new Curie('curie-name', 'http://curie-href', true)),
halNodeElementFactory('an-array-link-rel', JsonElementType.Array, HalElementType.LinkRel, null, [
jsonNodeElementFactory(null, JsonElementType.Object, null, [
halNodeElementFactory('href', JsonElementType.String, HalElementType.LinkHref, 'http://one-array-link-rel-url', [], true)
], false),
jsonNodeElementFactory(null, JsonElementType.Object, null, [
halNodeElementFactory('href', JsonElementType.String, HalElementType.LinkHref, 'http://other-array-link-rel-url', [], true)
},
new Curies(),
true)
).toEqual(
jsonNodeElementFactory('root', JsonElementType.Root, null, [
jsonNodeElementFactory('string-property', JsonElementType.String, 'string property value', [], false),
jsonNodeElementFactory('boolean-property', JsonElementType.Boolean, 'true', [], false),
jsonNodeElementFactory('array-property', JsonElementType.Array, null, [
jsonNodeElementFactory(null, JsonElementType.String, 'first-array-item', [], false),
jsonNodeElementFactory(null, JsonElementType.Boolean, 'false', [], false),
jsonNodeElementFactory(null, JsonElementType.Number, '123', [], true),
], false),
jsonNodeElementFactory('a-sub-object', JsonElementType.Object, null, [
jsonNodeElementFactory('a-sub-object-property', JsonElementType.String, 'a sub object property value', [], true),
], false),
jsonNodeElementFactory('_links', JsonElementType.Object, null, [
halNodeElementFactory('curie-name:curie-parameter', JsonElementType.Object, HalElementType.LinkRel, null, [
halNodeElementFactory('href', JsonElementType.String, HalElementType.LinkHref, 'http://self-url', [], true)
], false, new Curie('curie-name', 'http://curie-href', true)),
halNodeElementFactory('an-array-link-rel', JsonElementType.Array, HalElementType.LinkRel, null, [
jsonNodeElementFactory(null, JsonElementType.Object, null, [
halNodeElementFactory('href', JsonElementType.String, HalElementType.LinkHref, 'http://one-array-link-rel-url', [], true)
], false),
jsonNodeElementFactory(null, JsonElementType.Object, null, [
halNodeElementFactory('href', JsonElementType.String, HalElementType.LinkHref, 'http://other-array-link-rel-url', [], true)
], true)
], true)
], true)
], false),
jsonNodeElementFactory('_embedded', JsonElementType.Object, null, [
halNodeElementFactory('a-embedded-rel', JsonElementType.Object, HalElementType.LinkRel, null, [
jsonNodeElementFactory('a-property', JsonElementType.String, 'a property value', [], true),
], false),
halNodeElementFactory('curie-name:other-embedded-rel', JsonElementType.Array, HalElementType.LinkRel, null, [
jsonNodeElementFactory(null, JsonElementType.Object, null, [
jsonNodeElementFactory('first-property', JsonElementType.String, 'first property value', [], true)
jsonNodeElementFactory('_embedded', JsonElementType.Object, null, [
halNodeElementFactory('a-embedded-rel', JsonElementType.Object, HalElementType.LinkRel, null, [
jsonNodeElementFactory('a-property', JsonElementType.String, 'a property value', [], true),
], false),
jsonNodeElementFactory(null, JsonElementType.Object, null, [
jsonNodeElementFactory('second-property', JsonElementType.String, 'second property value', [], true)
], true),
], true, new Curie('curie-name', 'http://curie-href', true))
], true)
], true));
halNodeElementFactory('curie-name:other-embedded-rel', JsonElementType.Array, HalElementType.LinkRel, null, [
jsonNodeElementFactory(null, JsonElementType.Object, null, [
jsonNodeElementFactory('first-property', JsonElementType.String, 'first property value', [], true)
], false),
jsonNodeElementFactory(null, JsonElementType.Object, null, [
jsonNodeElementFactory('second-property', JsonElementType.String, 'second property value', [], true)
], true),
], true, new Curie('curie-name', 'http://curie-href', true))
], true)
], true));
});
});
describe('isCuriedRel', () => {
Expand Down
Loading

0 comments on commit 049ee9d

Please sign in to comment.