mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 02:03:39 +00:00
feat(nx): add basic-lib generator for streamlined library creation (#14992)
* feat(nx): add basic-lib generator for streamlined library creation This adds a new nx-plugin library with a generator for creating "common" type Bitwarden libs. It is set up to accept a lib name, description, team, and directory. It then - Creates a folder in the directory (default to libs) - Sets up complete library scaffolding: - README with team ownership - Build, lint and test task configuration - Test infrastructure - Configures TypeScript path mapping - Updates CODEOWNERS with team ownership - Runs npm i This will make library creation more consistent and reduce manual boilerplate setup. The plugin design itself was generated by `npx nx g plugin`. This means we used a plugin to generate a plugin that exports generators. To create our generator generator, we first needed a generator. * fix(dirt/card): correct tsconfig path in jest configuration Fix the relative path to tsconfig.base in the dirt/card library's Jest config. The path was incorrectly using four parent directory traversals (../../../../) when only three (../../../) were needed to reach the project root. * chore(codeowners): clarify some nx ownership stuff
This commit is contained in:
4
libs/nx-plugin/src/generators/files/README.md__tmpl__
Normal file
4
libs/nx-plugin/src/generators/files/README.md__tmpl__
Normal file
@@ -0,0 +1,4 @@
|
||||
# <%= name %>
|
||||
Owned by: <%= team %>
|
||||
|
||||
<%= description %>
|
||||
@@ -0,0 +1,3 @@
|
||||
import baseConfig from "<%= offsetFromRoot %>eslint.config.mjs";
|
||||
|
||||
export default [...baseConfig];
|
||||
10
libs/nx-plugin/src/generators/files/jest.config.js__tmpl__
Normal file
10
libs/nx-plugin/src/generators/files/jest.config.js__tmpl__
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
displayName: '<%= name %>',
|
||||
preset: '<%= offsetFromRoot %>jest.preset.js',
|
||||
testEnvironment: 'node',
|
||||
transform: {
|
||||
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
|
||||
},
|
||||
moduleFileExtensions: ['ts', 'js', 'html'],
|
||||
coverageDirectory: '<%= offsetFromRoot %>coverage/libs/<%= name %>',
|
||||
};
|
||||
11
libs/nx-plugin/src/generators/files/package.json__tmpl__
Normal file
11
libs/nx-plugin/src/generators/files/package.json__tmpl__
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "@bitwarden/<%= name %>",
|
||||
"version": "0.0.1",
|
||||
"description": "<%= description %>",
|
||||
"private": true,
|
||||
"type": "commonjs",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"license": "GPL-3.0",
|
||||
"author": "<%= team %>"
|
||||
}
|
||||
33
libs/nx-plugin/src/generators/files/project.json__tmpl__
Normal file
33
libs/nx-plugin/src/generators/files/project.json__tmpl__
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "<%= name %>",
|
||||
"$schema": "<%= offsetFromRoot %>node_modules/nx/schemas/project-schema.json",
|
||||
"sourceRoot": "libs/<%= name %>/src",
|
||||
"projectType": "library",
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@nx/js:tsc",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"options": {
|
||||
"outputPath": "dist/libs/<%= name %>",
|
||||
"main": "libs/<%= name %>/src/index.ts",
|
||||
"tsConfig": "libs/<%= name %>/tsconfig.lib.json",
|
||||
"assets": ["libs/<%= name%>/*.md"]
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/eslint:lint",
|
||||
"outputs": ["{options.outputFile}"],
|
||||
"options": {
|
||||
"lintFilePatterns": ["libs/<%= name %>/**/*.ts"]
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nx/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"options": {
|
||||
"jestConfig": "libs/<%= name %>/jest.config.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as lib from './index';
|
||||
|
||||
describe('<%= name %>', () => {
|
||||
// This test will fail until something is exported from index.ts
|
||||
it('should work', () => {
|
||||
expect(lib).toBeDefined();
|
||||
});
|
||||
});
|
||||
13
libs/nx-plugin/src/generators/files/tsconfig.json__tmpl__
Normal file
13
libs/nx-plugin/src/generators/files/tsconfig.json__tmpl__
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "<%= offsetFromRoot %>tsconfig.base.json",
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.lib.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.spec.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
||||
"declaration": true,
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
"exclude": ["jest.config.js", "src/**/*.spec.ts"]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "<%= offsetFromRoot %>/dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node10",
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user