Browse Source

Setup ui library with storybook

pull/332/head
Thomas Kaul 4 years ago
committed by Thomas
parent
commit
735a9453fd
  1. 11
      .storybook/main.js
  2. 10
      .storybook/tsconfig.json
  3. 84
      angular.json
  4. 17
      apps/ui-e2e/.eslintrc.json
  5. 13
      apps/ui-e2e/cypress.json
  6. 4
      apps/ui-e2e/src/fixtures/example.json
  7. 22
      apps/ui-e2e/src/plugins/index.js
  8. 33
      apps/ui-e2e/src/support/commands.ts
  9. 17
      apps/ui-e2e/src/support/index.ts
  10. 10
      apps/ui-e2e/tsconfig.json
  11. 36
      libs/ui/.eslintrc.json
  12. 24
      libs/ui/.storybook/main.js
  13. 0
      libs/ui/.storybook/preview.js
  14. 9
      libs/ui/.storybook/tsconfig.json
  15. 7
      libs/ui/README.md
  16. 20
      libs/ui/jest.config.js
  17. 1
      libs/ui/src/index.ts
  18. 7
      libs/ui/src/lib/ui.module.ts
  19. 1
      libs/ui/src/test-setup.ts
  20. 27
      libs/ui/tsconfig.json
  21. 19
      libs/ui/tsconfig.lib.json
  22. 10
      libs/ui/tsconfig.spec.json
  23. 15
      nx.json
  24. 11
      package.json
  25. 3
      tsconfig.base.json
  26. 4064
      yarn.lock

11
.storybook/main.js

@ -0,0 +1,11 @@
module.exports = {
stories: [],
addons: ['@storybook/addon-essentials']
// uncomment the property below if you want to apply some webpack config globally
// webpackFinal: async (config, { configType }) => {
// // Make whatever fine-grained changes you need that should apply to all storybook configs
// // Return the altered config
// return config;
// },
};

10
.storybook/tsconfig.json

@ -0,0 +1,10 @@
{
"extends": "../tsconfig.base.json",
"exclude": [
"../**/*.spec.js",
"../**/*.spec.ts",
"../**/*.spec.tsx",
"../**/*.spec.jsx"
],
"include": ["../**/*"]
}

84
angular.json

@ -6,13 +6,16 @@
"defaultProject": "api", "defaultProject": "api",
"schematics": { "schematics": {
"@nrwl/angular:application": { "@nrwl/angular:application": {
"linter": "eslint",
"unitTestRunner": "jest", "unitTestRunner": "jest",
"e2eTestRunner": "cypress" "e2eTestRunner": "cypress"
}, },
"@nrwl/angular:library": { "@nrwl/angular:library": {
"linter": "eslint",
"unitTestRunner": "jest" "unitTestRunner": "jest"
}, },
"@nrwl/nest": {} "@nrwl/nest": {},
"@nrwl/angular:component": {}
}, },
"projects": { "projects": {
"api": { "api": {
@ -239,6 +242,85 @@
} }
} }
} }
},
"ui": {
"projectType": "library",
"root": "libs/ui",
"sourceRoot": "libs/ui/src",
"prefix": "ghostfolio",
"architect": {
"test": {
"builder": "@nrwl/jest:jest",
"outputs": ["coverage/libs/ui"],
"options": {
"jestConfig": "libs/ui/jest.config.js",
"passWithNoTests": true
}
},
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": ["libs/ui/src/**/*.ts", "libs/ui/src/**/*.html"]
}
},
"storybook": {
"builder": "@nrwl/storybook:storybook",
"options": {
"uiFramework": "@storybook/angular",
"port": 4400,
"config": {
"configFolder": "libs/ui/.storybook"
}
},
"configurations": {
"ci": {
"quiet": true
}
}
},
"build-storybook": {
"builder": "@nrwl/storybook:build",
"outputs": ["{options.outputPath}"],
"options": {
"uiFramework": "@storybook/angular",
"outputPath": "dist/storybook/ui",
"config": {
"configFolder": "libs/ui/.storybook"
}
},
"configurations": {
"ci": {
"quiet": true
}
}
}
}
},
"ui-e2e": {
"root": "apps/ui-e2e",
"sourceRoot": "apps/ui-e2e/src",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@nrwl/cypress:cypress",
"options": {
"cypressConfig": "apps/ui-e2e/cypress.json",
"devServerTarget": "ui:storybook",
"tsConfig": "apps/ui-e2e/tsconfig.json"
},
"configurations": {
"ci": {
"devServerTarget": "ui:storybook:ci"
}
}
},
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": ["apps/ui-e2e/**/*.{js,ts}"]
}
}
}
} }
} }
} }

17
apps/ui-e2e/.eslintrc.json

@ -0,0 +1,17 @@
{
"extends": ["plugin:cypress/recommended", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["src/plugins/index.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"no-undef": "off"
}
}
]
}

13
apps/ui-e2e/cypress.json

@ -0,0 +1,13 @@
{
"fileServerFolder": ".",
"fixturesFolder": "./src/fixtures",
"integrationFolder": "./src/integration",
"modifyObstructiveCode": false,
"supportFile": "./src/support/index.ts",
"pluginsFile": "./src/plugins/index",
"video": true,
"videosFolder": "../../dist/cypress/apps/ui-e2e/videos",
"screenshotsFolder": "../../dist/cypress/apps/ui-e2e/screenshots",
"chromeWebSecurity": false,
"baseUrl": "http://localhost:4400"
}

4
apps/ui-e2e/src/fixtures/example.json

@ -0,0 +1,4 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io"
}

22
apps/ui-e2e/src/plugins/index.js

@ -0,0 +1,22 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
const { preprocessTypescript } = require('@nrwl/cypress/plugins/preprocessor');
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
// Preprocess Typescript file using Nx helper
on('file:preprocessor', preprocessTypescript(config));
};

33
apps/ui-e2e/src/support/commands.ts

@ -0,0 +1,33 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
login(email: string, password: string): void;
}
}
//
// -- This is a parent command --
Cypress.Commands.add('login', (email, password) => {
console.log('Custom command example: Login', email, password);
});
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

17
apps/ui-e2e/src/support/index.ts

@ -0,0 +1,17 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands';

10
apps/ui-e2e/tsconfig.json

@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"sourceMap": false,
"outDir": "../../dist/out-tsc",
"allowJs": true,
"types": ["cypress", "node"]
},
"include": ["src/**/*.ts", "src/**/*.js"]
}

36
libs/ui/.eslintrc.json

@ -0,0 +1,36 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@nrwl/nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "ghostfolio",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "ghostfolio",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nrwl/nx/angular-template"],
"rules": {}
}
]
}

24
libs/ui/.storybook/main.js

@ -0,0 +1,24 @@
const rootMain = require('../../../.storybook/main');
module.exports = {
...rootMain,
core: { ...rootMain.core, builder: 'webpack5' },
stories: [
...rootMain.stories,
'../src/lib/**/*.stories.mdx',
'../src/lib/**/*.stories.@(js|jsx|ts|tsx)'
],
addons: [...rootMain.addons],
webpackFinal: async (config, { configType }) => {
// apply any global webpack configs that might have been specified in .storybook/main.js
if (rootMain.webpackFinal) {
config = await rootMain.webpackFinal(config, { configType });
}
// add your own webpack tweaks if needed
return config;
}
};

0
libs/ui/.storybook/preview.js

9
libs/ui/.storybook/tsconfig.json

@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"emitDecoratorMetadata": true
},
"exclude": ["../**/*.spec.ts"],
"include": ["../src/**/*", "*.js"]
}

7
libs/ui/README.md

@ -0,0 +1,7 @@
# ui
This library was generated with [Nx](https://nx.dev).
## Running unit tests
Run `nx test ui` to execute the unit tests.

20
libs/ui/jest.config.js

@ -0,0 +1,20 @@
module.exports = {
displayName: 'ui',
preset: '../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$'
}
},
coverageDirectory: '../../coverage/libs/ui',
transform: {
'^.+\\.(ts|js|html)$': 'jest-preset-angular'
},
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment'
]
};

1
libs/ui/src/index.ts

@ -0,0 +1 @@
export * from './lib/ui.module';

7
libs/ui/src/lib/ui.module.ts

@ -0,0 +1,7 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
imports: [CommonModule]
})
export class UiModule {}

1
libs/ui/src/test-setup.ts

@ -0,0 +1 @@
import 'jest-preset-angular/setup-jest';

27
libs/ui/tsconfig.json

@ -0,0 +1,27 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
},
{
"path": "./.storybook/tsconfig.json"
}
],
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"angularCompilerOptions": {
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}

19
libs/ui/tsconfig.lib.json

@ -0,0 +1,19 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"target": "es2015",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": [],
"lib": ["dom", "es2018"]
},
"exclude": [
"src/test-setup.ts",
"**/*.spec.ts",
"**/*.stories.ts",
"**/*.stories.js"
],
"include": ["**/*.ts"]
}

10
libs/ui/tsconfig.spec.json

@ -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"]
}

15
nx.json

@ -17,7 +17,13 @@
"default": { "default": {
"runner": "@nrwl/workspace/tasks-runners/default", "runner": "@nrwl/workspace/tasks-runners/default",
"options": { "options": {
"cacheableOperations": ["build", "lint", "test", "e2e"] "cacheableOperations": [
"build",
"lint",
"test",
"e2e",
"build-storybook"
]
} }
} }
}, },
@ -34,6 +40,13 @@
}, },
"common": { "common": {
"tags": [] "tags": []
},
"ui": {
"tags": []
},
"ui-e2e": {
"tags": [],
"implicitDependencies": ["ui"]
} }
}, },
"targetDependencies": { "targetDependencies": {

11
package.json

@ -30,7 +30,7 @@
"lint": "nx workspace-lint && ng lint", "lint": "nx workspace-lint && ng lint",
"ng": "nx", "ng": "nx",
"nx": "nx", "nx": "nx",
"postinstall": "prisma generate", "postinstall": "prisma generate && ngcc --properties es2015 browser module main",
"replace-placeholders-in-build": "node ./replace.build.js", "replace-placeholders-in-build": "node ./replace.build.js",
"setup:database": "yarn database:push && yarn database:seed", "setup:database": "yarn database:push && yarn database:seed",
"start": "node dist/apps/api/main", "start": "node dist/apps/api/main",
@ -104,6 +104,7 @@
"rxjs": "6.6.7", "rxjs": "6.6.7",
"stripe": "8.156.0", "stripe": "8.156.0",
"svgmap": "2.6.0", "svgmap": "2.6.0",
"tslib": "2.0.0",
"uuid": "8.3.2", "uuid": "8.3.2",
"yahoo-finance": "0.3.6", "yahoo-finance": "0.3.6",
"zone.js": "0.11.4" "zone.js": "0.11.4"
@ -111,6 +112,8 @@
"devDependencies": { "devDependencies": {
"@angular-devkit/build-angular": "12.2.4", "@angular-devkit/build-angular": "12.2.4",
"@angular-eslint/eslint-plugin": "12.3.1", "@angular-eslint/eslint-plugin": "12.3.1",
"@angular-eslint/eslint-plugin-template": "12.3.0",
"@angular-eslint/template-parser": "12.3.0",
"@angular/cli": "12.2.4", "@angular/cli": "12.2.4",
"@angular/compiler-cli": "12.2.4", "@angular/compiler-cli": "12.2.4",
"@angular/language-service": "12.2.4", "@angular/language-service": "12.2.4",
@ -123,8 +126,13 @@
"@nrwl/jest": "12.8.0", "@nrwl/jest": "12.8.0",
"@nrwl/nest": "12.8.0", "@nrwl/nest": "12.8.0",
"@nrwl/node": "12.8.0", "@nrwl/node": "12.8.0",
"@nrwl/storybook": "12.8.0",
"@nrwl/tao": "12.8.0", "@nrwl/tao": "12.8.0",
"@nrwl/workspace": "12.8.0", "@nrwl/workspace": "12.8.0",
"@storybook/addon-essentials": "6.3.0",
"@storybook/angular": "6.3.0",
"@storybook/builder-webpack5": "6.3.0",
"@storybook/manager-webpack5": "6.3.0",
"@types/big.js": "6.1.1", "@types/big.js": "6.1.1",
"@types/cache-manager": "3.4.0", "@types/cache-manager": "3.4.0",
"@types/color": "3.0.2", "@types/color": "3.0.2",
@ -139,6 +147,7 @@
"dotenv": "10.0.0", "dotenv": "10.0.0",
"eslint": "7.28.0", "eslint": "7.28.0",
"eslint-config-prettier": "8.3.0", "eslint-config-prettier": "8.3.0",
"eslint-plugin-cypress": "2.10.3",
"eslint-plugin-import": "2.23.4", "eslint-plugin-import": "2.23.4",
"import-sort-cli": "6.0.0", "import-sort-cli": "6.0.0",
"import-sort-parser-typescript": "6.0.0", "import-sort-parser-typescript": "6.0.0",

3
tsconfig.base.json

@ -18,7 +18,8 @@
"paths": { "paths": {
"@ghostfolio/api/*": ["apps/api/src/*"], "@ghostfolio/api/*": ["apps/api/src/*"],
"@ghostfolio/client/*": ["apps/client/src/app/*"], "@ghostfolio/client/*": ["apps/client/src/app/*"],
"@ghostfolio/common/*": ["libs/common/src/lib/*"] "@ghostfolio/common/*": ["libs/common/src/lib/*"],
"@ghostfolio/ui": ["libs/ui/src/index.ts"]
} }
}, },
"exclude": ["node_modules", "tmp"] "exclude": ["node_modules", "tmp"]

4064
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save