Skip to content

Commit

Permalink
feat: migrate to oss lib
Browse files Browse the repository at this point in the history
  • Loading branch information
kroeder committed May 14, 2024
1 parent 8cd6ca9 commit 9a0b076
Show file tree
Hide file tree
Showing 155 changed files with 13,794 additions and 1,216 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
42 changes: 42 additions & 0 deletions .eslintrc.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nx"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [
{
"sourceTag": "*",
"onlyDependOnLibsWithTags": ["*"]
}
]
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nx/typescript"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nx/javascript"],
"rules": {}
},
{
"files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
"env": {
"jest": true
},
"rules": {}
}
]
}
39 changes: 39 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"ignorePatterns": ["**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [
{
"sourceTag": "*",
"onlyDependOnLibsWithTags": ["*"]
}
]
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
"env": {
"jest": true
},
"rules": {}
}
],
"extends": ["./.eslintrc.base.json"]
}
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Add files here to ignore them from prettier formatting
/dist
/coverage
/.nx/cache
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
28 changes: 28 additions & 0 deletions .verdaccio/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# path to a directory with all packages
storage: ../tmp/local-registry/storage

# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/
maxage: 60m

packages:
'**':
# give all users (including non-authenticated users) full access
# because it is a local registry
access: $all
publish: $all
unpublish: $all

# if package is not available locally, proxy requests to npm registry
proxy: npmjs

# log settings
logs:
type: stdout
format: pretty
level: warn

publish:
allow_offline: true # set offline to true to allow publish offline
4 changes: 2 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"recommendations": [

"nrwl.angular-console",
"esbenp.prettier-vscode"
"esbenp.prettier-vscode",
"firsttris.vscode-jest-runner"
]
}
5 changes: 5 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { getJestProjectsAsync } from '@nx/jest';

export default async () => ({
projects: await getJestProjectsAsync(),
});
3 changes: 3 additions & 0 deletions jest.preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const nxPreset = require('@nx/jest/preset').default;

module.exports = { ...nxPreset };
25 changes: 25 additions & 0 deletions libs/ngx-schematics-buddy/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": ["../../.eslintrc.base.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error"
}
}
]
}
11 changes: 11 additions & 0 deletions libs/ngx-schematics-buddy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ngx-schematics-buddy

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build ngx-schematics-buddy` to build the library.

## Running unit tests

Run `nx test ngx-schematics-buddy` to execute the unit tests via [Jest](https://jestjs.io).
11 changes: 11 additions & 0 deletions libs/ngx-schematics-buddy/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'ngx-schematics-buddy',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/libs/ngx-schematics-buddy',
};
22 changes: 22 additions & 0 deletions libs/ngx-schematics-buddy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "ngx-schematics-buddy",
"version": "0.0.1",
"dependencies": {
"@angular/cli": "^17.3.6",
"@angular/compiler": "^17.3.6",
"@angular-devkit/core": "^17.3.6",
"@angular-devkit/schematics": "^17.3.6",
"@angular-eslint/bundled-angular-compiler": "^17.3.0",
"@phenomnomnominal/tsquery": "^6.1.3",
"ng-morph": "^4.1.2",
"shelljs": "^0.8.5",
"typescript": "^5.4.5",
"tslib": "^2.3.0"
},
"devDependencies": {
"@types/shelljs": "^0.8.15"
},
"type": "commonjs",
"main": "./src/index.js",
"typings": "./src/index.d.ts"
}
32 changes: 32 additions & 0 deletions libs/ngx-schematics-buddy/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "ngx-schematics-buddy",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/ngx-schematics-buddy/src",
"projectType": "library",
"release": {
"version": {
"generatorOptions": {
"packageRoot": "dist/{projectRoot}",
"currentVersionResolver": "git-tag"
}
}
},
"tags": [],
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/ngx-schematics-buddy",
"main": "libs/ngx-schematics-buddy/src/index.ts",
"tsConfig": "libs/ngx-schematics-buddy/tsconfig.lib.json",
"assets": ["libs/ngx-schematics-buddy/*.md"]
}
},
"nx-release-publish": {
"options": {
"packageRoot": "dist/{projectRoot}"
}
}
}
}
1 change: 1 addition & 0 deletions libs/ngx-schematics-buddy/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/ngx-schematics-buddy';
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { getSystemPath, normalize, virtualFs } from '@angular-devkit/core';
import { TempScopedNodeJsSyncHost } from '@angular-devkit/core/node/testing';
import { HostTree } from '@angular-devkit/schematics';
import {
SchematicTestRunner,
UnitTestTree,
} from '@angular-devkit/schematics/testing';
import * as shell from 'shelljs';

export class SchematicTestHelper {
runner!: SchematicTestRunner;
host!: TempScopedNodeJsSyncHost;
tree!: UnitTestTree;

tmpDirPath!: string;
previousWorkingDir!: string;

constructor(
readonly migrationCollectionPath = require.resolve(
'./test-migrations/migration-api-test-collection.json'
)
) {
// TODO refactor
// @ts-ignore
beforeEach(() => {
this.beforeEach();
});

// TODO refactor
// @ts-ignore
afterEach(() => {
this.afterEach();
});
}

beforeEach() {
this.runner = new SchematicTestRunner(
'testCollection',
this.migrationCollectionPath
);
this.host = new TempScopedNodeJsSyncHost();
this.tree = new UnitTestTree(new HostTree(this.host));

this.previousWorkingDir = shell.pwd();
this.tmpDirPath = getSystemPath(this.host.root);

// Switch into the temporary directory path. This allows us to run
// the schematic against our custom unit test tree.
shell.cd(this.tmpDirPath);
}

afterEach() {
shell.cd(this.previousWorkingDir);
shell.rm('-r', this.tmpDirPath);
}

writeFile(filePath: string, contents: string) {
this.host.sync.write(
normalize(filePath),
virtualFs.stringToFileBuffer(contents)
);
}

async runMigration(schematicName: string) {
return this.runner.runSchematic(schematicName, {}, this.tree);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Rule } from '@angular-devkit/schematics';
import { AddAttributeAction } from '../../migrations-api/actions/add-attribute-action';
import { getRules } from '../../migrations-api/get-rules';
import { isNamed } from '../../migrations-api/template-action-condition';

export default function (): Rule {
return getRules([
new AddAttributeAction({
attribute: 'class',
value: 'row',
conditions: [isNamed('div')],
}),
new AddAttributeAction({
attribute: '[value]',
value: `'aString'`,
conditions: [isNamed('input')],
}),
]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Rule } from '@angular-devkit/schematics';
import { AddClassAction } from '../../migrations-api/actions/add-class-action';
import { getRules } from '../../migrations-api/get-rules';
import { isNamed } from '../../migrations-api/template-action-condition';

export default function (): Rule {
return getRules([
new AddClassAction({
className: 'foo',
conditions: [isNamed('div')],
}),
]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Rule } from '@angular-devkit/schematics';
import { AddClosingTagAction } from '../../migrations-api/actions/add-closing-tag-action';
import { getRules } from '../../migrations-api/get-rules';
import { isNamed } from '../../migrations-api/template-action-condition';

export default function (): Rule {
return getRules([
new AddClosingTagAction({
conditions: [isNamed('lib-text-input')],
}),
]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Rule } from '@angular-devkit/schematics';
import { AddMigrationCommentAction } from '../../migrations-api/actions/add-migration-comment-action';
import { getRules } from '../../migrations-api/get-rules';
import { isNamed, or } from '../../migrations-api/template-action-condition';

export const migrationCommentText =
'This is some text that should describe parts where e.g. a full migration is not possible';

export default function (): Rule {
return getRules([
new AddMigrationCommentAction({
migrationCommentVersion: 6,
migrationCommentText,
conditions: [or(isNamed('lib-dropdown'), isNamed('lib-text-input'))],
}),
]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Rule } from '@angular-devkit/schematics';
import { AddPipeToAttributeAction } from '../../migrations-api/actions/add-pipe-to-attribute-action';
import { getRules } from '../../migrations-api/get-rules';
import { isNamed } from '../../migrations-api/template-action-condition';

export default function (): Rule {
return getRules([
new AddPipeToAttributeAction({
attributeName: 'dataKey',
pipeName: 'resolveFieldFn',
conditions: [isNamed('lib-table')],
}),
]);
}
Loading

0 comments on commit 9a0b076

Please sign in to comment.