-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from IKatsuba/feature-platform
feat(ngx-ssr-platform): create the platform package
- Loading branch information
Showing
23 changed files
with
510 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"extends": ["../../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts"], | ||
"extends": [ | ||
"plugin:@nrwl/nx/angular", | ||
"plugin:@angular-eslint/template/process-inline-templates" | ||
], | ||
"parserOptions": { | ||
"project": ["libs/ngx-ssr/platform/tsconfig.*?.json"] | ||
}, | ||
"rules": { | ||
"@angular-eslint/directive-selector": [ | ||
"error", | ||
{ "type": "attribute", "prefix": "ngxSsr", "style": "camelCase" } | ||
], | ||
"@angular-eslint/component-selector": [ | ||
"error", | ||
{ "type": "element", "prefix": "ngx-ssr", "style": "kebab-case" } | ||
] | ||
} | ||
}, | ||
{ | ||
"files": ["*.html"], | ||
"extends": ["plugin:@nrwl/nx/angular-template"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# @ngx-ssr/platform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = { | ||
displayName: 'ngx-ssr-platform', | ||
preset: '../../../jest.preset.js', | ||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'], | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: '<rootDir>/tsconfig.spec.json', | ||
stringifyContentPathRegex: '\\.(html|svg)$', | ||
astTransformers: { | ||
before: [ | ||
'jest-preset-angular/build/InlineFilesTransformer', | ||
'jest-preset-angular/build/StripStylesTransformer', | ||
], | ||
}, | ||
}, | ||
}, | ||
coverageDirectory: '../../../coverage/libs/ngx-ssr/platform', | ||
snapshotSerializers: [ | ||
'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js', | ||
'jest-preset-angular/build/AngularSnapshotSerializer.js', | ||
'jest-preset-angular/build/HTMLCommentSerializer.js', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json", | ||
"dest": "../../../dist/libs/ngx-ssr/platform", | ||
"lib": { | ||
"entryFile": "src/index.ts" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "@ngx-ssr/platform", | ||
"version": "0.0.0-development", | ||
"keywords": [ | ||
"angular", | ||
"angulae ssr", | ||
"universal", | ||
"angular/universal", | ||
"ssr", | ||
"platform", | ||
"is-server", | ||
"is-browser" | ||
], | ||
"peerDependencies": { | ||
"@angular/common": "^11.0.6", | ||
"@angular/core": "^11.0.6" | ||
}, | ||
"dependencies": { | ||
"tslib": "^2.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './lib/is-server.directive'; | ||
export * from './lib/is-browser.directive'; | ||
export * from './lib/ngx-ssr-platform.module'; | ||
export * from './lib/tokens'; |
35 changes: 35 additions & 0 deletions
35
libs/ngx-ssr/platform/src/lib/is-browser.directive.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { IsBrowserDirective } from './is-browser.directive'; | ||
import { render, screen } from '@testing-library/angular'; | ||
import { IS_BROWSER_PLATFORM } from './tokens'; | ||
|
||
describe('IsBrowserDirective', () => { | ||
it('should create an element', async () => { | ||
await render(IsBrowserDirective, { | ||
template: '<div *isBrowser>Some text</div>', | ||
providers: [ | ||
{ | ||
provide: IS_BROWSER_PLATFORM, | ||
useValue: true, | ||
}, | ||
], | ||
}); | ||
|
||
expect(screen.getByText('Some text').outerHTML).toStrictEqual( | ||
'<div>Some text</div>' | ||
); | ||
}); | ||
|
||
it('should not create an element', async () => { | ||
await render(IsBrowserDirective, { | ||
template: '<div *isBrowser>Some text</div>', | ||
providers: [ | ||
{ | ||
provide: IS_BROWSER_PLATFORM, | ||
useValue: false, | ||
}, | ||
], | ||
}); | ||
|
||
expect(() => screen.getByText('Some text')).toThrowError(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { | ||
Directive, | ||
Inject, | ||
TemplateRef, | ||
ViewContainerRef, | ||
} from '@angular/core'; | ||
import { IS_BROWSER_PLATFORM } from './tokens'; | ||
|
||
@Directive({ | ||
// eslint-disable-next-line @angular-eslint/directive-selector | ||
selector: '[isBrowser]', | ||
}) | ||
export class IsBrowserDirective { | ||
constructor( | ||
@Inject(IS_BROWSER_PLATFORM) isBrowser: boolean, | ||
templateRef: TemplateRef<any>, | ||
viewContainer: ViewContainerRef | ||
) { | ||
if (isBrowser) { | ||
viewContainer.createEmbeddedView(templateRef); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { IsServerDirective } from './is-server.directive'; | ||
import { render, screen } from '@testing-library/angular'; | ||
import { IS_SERVER_PLATFORM } from './tokens'; | ||
|
||
describe('IsServerDirective', () => { | ||
it('should create an element', async () => { | ||
await render(IsServerDirective, { | ||
template: '<div *isServer>Some text</div>', | ||
providers: [ | ||
{ | ||
provide: IS_SERVER_PLATFORM, | ||
useValue: true, | ||
}, | ||
], | ||
}); | ||
|
||
expect(screen.getByText('Some text').outerHTML).toStrictEqual( | ||
'<div>Some text</div>' | ||
); | ||
}); | ||
|
||
it('should not create an element', async () => { | ||
await render(IsServerDirective, { | ||
template: '<div *isServer>Some text</div>', | ||
providers: [ | ||
{ | ||
provide: IS_SERVER_PLATFORM, | ||
useValue: false, | ||
}, | ||
], | ||
}); | ||
|
||
expect(() => screen.getByText('Some text')).toThrowError(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { | ||
Directive, | ||
Inject, | ||
TemplateRef, | ||
ViewContainerRef, | ||
} from '@angular/core'; | ||
import { IS_SERVER_PLATFORM } from './tokens'; | ||
|
||
@Directive({ | ||
// eslint-disable-next-line @angular-eslint/directive-selector | ||
selector: '[isServer]', | ||
}) | ||
export class IsServerDirective { | ||
constructor( | ||
@Inject(IS_SERVER_PLATFORM) isServer: boolean, | ||
templateRef: TemplateRef<any>, | ||
viewContainer: ViewContainerRef | ||
) { | ||
if (isServer) { | ||
viewContainer.createEmbeddedView(templateRef); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { IsBrowserDirective } from './is-browser.directive'; | ||
import { IsServerDirective } from './is-server.directive'; | ||
|
||
@NgModule({ | ||
imports: [CommonModule], | ||
declarations: [IsBrowserDirective, IsServerDirective], | ||
exports: [IsBrowserDirective, IsServerDirective], | ||
}) | ||
export class NgxSsrPlatformModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { inject, InjectionToken, PLATFORM_ID } from '@angular/core'; | ||
import { isPlatformBrowser, isPlatformServer } from '@angular/common'; | ||
|
||
export const IS_SERVER_PLATFORM = new InjectionToken<boolean>('Is server?', { | ||
factory() { | ||
const platform = inject(PLATFORM_ID); | ||
|
||
return isPlatformServer(platform); | ||
}, | ||
}); | ||
|
||
export const IS_BROWSER_PLATFORM = new InjectionToken<boolean>('Is browser?', { | ||
factory() { | ||
const platform = inject(PLATFORM_ID); | ||
|
||
return isPlatformBrowser(platform); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import 'jest-preset-angular'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.lib.prod.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../../dist/out-tsc", | ||
"target": "es2015", | ||
"declaration": true, | ||
"declarationMap": true, | ||
"inlineSources": true, | ||
"types": [], | ||
"lib": ["dom", "es2018"] | ||
}, | ||
"angularCompilerOptions": { | ||
"skipTemplateCodegen": true, | ||
"strictMetadataEmit": true, | ||
"enableResourceInlining": true | ||
}, | ||
"exclude": ["src/test-setup.ts", "**/*.spec.ts"], | ||
"include": ["**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* To learn more about this file see: https://angular.io/config/tsconfig. */ | ||
{ | ||
"extends": "./tsconfig.lib.json", | ||
"compilerOptions": { | ||
"declarationMap": false | ||
}, | ||
"angularCompilerOptions": { | ||
"enableIvy": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"files": ["src/test-setup.ts"], | ||
"include": ["**/*.spec.ts", "**/*.d.ts"] | ||
} |
Oops, something went wrong.