diff --git a/.github/workflows/npmpub.yml b/.github/workflows/npmpub.yml index 745a2de..0938800 100644 --- a/.github/workflows/npmpub.yml +++ b/.github/workflows/npmpub.yml @@ -13,11 +13,10 @@ jobs: steps: - uses: actions/checkout@v2 - - run: npm install - run: npm run pack - - run: cp README.md ./src/lib/dist/README.md + - run: cp README.md ./dist/lib/README.md - uses: JS-DevTools/npm-publish@v1 with: token: ${{ secrets.NPM_TOKEN }} - package: './src/lib/dist/package.json' + package: './dist/lib/package.json' diff --git a/angular.json b/angular.json index 55d1dff..ff96c94 100644 --- a/angular.json +++ b/angular.json @@ -5,7 +5,15 @@ "projects": { "dev": { "projectType": "application", - "schematics": {}, + "schematics": { + "@schematics/angular:component": { + "style": "scss", + "prefix": "app" + }, + "@schematics/angular:directive": { + "prefix": "app" + } + }, "root": "", "sourceRoot": "src", "prefix": "app", @@ -20,7 +28,6 @@ "zone.js" ], "tsConfig": "tsconfig.app.json", - "aot": true, "assets": [ "src/favicon.ico", "src/assets" @@ -38,27 +45,27 @@ "with": "src/environments/environment.prod.ts" } ], - "optimization": true, "outputHashing": "all", - "sourceMap": false, - "namedChunks": false, - "extractLicenses": true, - "vendorChunk": false, - "buildOptimizer": true, "budgets": [ { "type": "initial", - "maximumWarning": "2mb", - "maximumError": "5mb" + "maximumWarning": "500kb", + "maximumError": "1mb" }, { "type": "anyComponentStyle", - "maximumWarning": "6kb", - "maximumError": "10kb" + "maximumWarning": "2kb", + "maximumError": "4kb" } ] + }, + "development": { + "optimization": false, + "extractLicenses": false, + "sourceMap": true } - } + }, + "defaultConfiguration": "production" }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", @@ -68,15 +75,12 @@ "configurations": { "production": { "buildTarget": "dev:build:production" + }, + "development": { + "buildTarget": "dev:build:development" } } }, - "extract-i18n": { - "builder": "@angular-devkit/build-angular:extract-i18n", - "options": { - "buildTarget": "dev:build" - } - }, "test": { "builder": "@angular-devkit/build-angular:karma", "options": { @@ -91,14 +95,45 @@ "src/assets" ], "styles": [ + "src/styles.scss" ], "scripts": [] } } } + }, + "lib": { + "projectType": "library", + "root": "projects/lib", + "sourceRoot": "projects/lib/src", + "prefix": "lib", + "architect": { + "build": { + "builder": "@angular-devkit/build-angular:ng-packagr", + "options": { + "project": "projects/lib/ng-package.json" + }, + "configurations": { + "production": { + "tsConfig": "projects/lib/tsconfig.lib.prod.json" + }, + "development": { + "tsConfig": "projects/lib/tsconfig.lib.json" + } + }, + "defaultConfiguration": "production" + }, + "test": { + "builder": "@angular-devkit/build-angular:karma", + "options": { + "tsConfig": "projects/lib/tsconfig.spec.json", + "polyfills": [ + "zone.js", + "zone.js/testing" + ] + } + } + } } - }, - "cli": { - "analytics": false } } diff --git a/package.json b/package.json index ed97359..c5a0600 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,10 @@ "test": "node node_modules/@angular/cli/bin/ng test", "test:headless": "node node_modules/@angular/cli/bin/ng test --browsers=ChromeHeadless", "test:headless:singleRun": "node node_modules/@angular/cli/bin/ng test --no-watch --no-progress --browsers=ChromeHeadless", - "release:minor": "cd ./src/lib/ && npm version minor", - "release:major": "cd ./src/lib/ && npm version major", - "release:patch": "cd ./src/lib/ && npm version patch", - "pack": "ng-packagr -p ./src/lib/package.json" + "release:minor": "cd ./projects/lib/ && npm version minor", + "release:major": "cd ./projects/lib/ && npm version major", + "release:patch": "cd ./projects/lib/ && npm version patch", + "pack": "npm run build lib" }, "private": true, "dependencies": { @@ -28,8 +28,8 @@ "zone.js": "~0.14.2" }, "devDependencies": { - "@angular-devkit/build-angular": "^17.0.9", - "@angular/cli": "^17.0.9", + "@angular-devkit/build-angular": "^17.0.8", + "@angular/cli": "^17.0.8", "@angular/compiler-cli": "^17.0.8", "@types/jasmine": "~5.1.0", "@types/jasminewd2": "~2.0.3", @@ -40,7 +40,7 @@ "karma-coverage": "~2.2.0", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.1.0", - "ng-packagr": "^17.0.3", + "ng-packagr": "^17.0.0", "typescript": "5.2.2" } } diff --git a/projects/lib/README.md b/projects/lib/README.md new file mode 100644 index 0000000..572acbd --- /dev/null +++ b/projects/lib/README.md @@ -0,0 +1,24 @@ +# Lib + +This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 17.0.0. + +## Code scaffolding + +Run `ng generate component component-name --project lib` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project lib`. +> Note: Don't forget to add `--project lib` or else it will be added to the default project in your `angular.json` file. + +## Build + +Run `ng build lib` to build the project. The build artifacts will be stored in the `dist/` directory. + +## Publishing + +After building your library with `ng build lib`, go to the dist folder `cd dist/lib` and run `npm publish`. + +## Running unit tests + +Run `ng test lib` to execute the unit tests via [Karma](https://karma-runner.github.io). + +## Further help + +To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. diff --git a/projects/lib/ng-package.json b/projects/lib/ng-package.json new file mode 100644 index 0000000..d719c13 --- /dev/null +++ b/projects/lib/ng-package.json @@ -0,0 +1,7 @@ +{ + "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", + "dest": "../../dist/lib", + "lib": { + "entryFile": "src/public-api.ts" + } +} \ No newline at end of file diff --git a/src/lib/package.json b/projects/lib/package.json similarity index 79% rename from src/lib/package.json rename to projects/lib/package.json index 3c5d9ee..ac1e1c3 100644 --- a/src/lib/package.json +++ b/projects/lib/package.json @@ -1,6 +1,6 @@ { "name": "ng2-fittext", - "version": "1.3.2", + "version": "1.4.0", "description": "Ng2-fittext: An Angular2+ directive that change the font size until it fit the upper level container dimension.", "keywords": [ "ng2-fittext", @@ -28,12 +28,15 @@ ], "author": "Lorenzo Iovino", "license": "MIT", - "ngPackage": { - "lib": { - "entryFile": "./ng2-fittext.module.ts" - } + "peerDependencies": { + "@angular/common": "^17.0.0", + "@angular/core": "^17.0.0" + }, + "dependencies": { + "tslib": "^2.3.0" }, "repository": { "url": "https://github.com/thisloke/ng2-fittext.git" - } + }, + "sideEffects": false } diff --git a/src/lib/directives/specs/ng2-fittext.directive.spec.ts b/projects/lib/src/directives/specs/ng2-fittext.directive.spec.ts similarity index 99% rename from src/lib/directives/specs/ng2-fittext.directive.spec.ts rename to projects/lib/src/directives/specs/ng2-fittext.directive.spec.ts index 80f824b..e0ac909 100644 --- a/src/lib/directives/specs/ng2-fittext.directive.spec.ts +++ b/projects/lib/src/directives/specs/ng2-fittext.directive.spec.ts @@ -1,4 +1,4 @@ -import { Ng2FittextDirective } from '../ng2-fittext.directive'; +import { Ng2FittextDirective } from '../../ng2-fittext.directive'; import { Renderer2, ElementRef } from '@angular/core'; describe('Class: Ng2FittextDirective', () => { diff --git a/src/lib/directives/ng2-fittext.directive.ts b/projects/lib/src/ng2-fittext.directive.ts similarity index 100% rename from src/lib/directives/ng2-fittext.directive.ts rename to projects/lib/src/ng2-fittext.directive.ts diff --git a/src/lib/ng2-fittext.module.ts b/projects/lib/src/ng2-fittext.module.ts similarity index 69% rename from src/lib/ng2-fittext.module.ts rename to projects/lib/src/ng2-fittext.module.ts index 0a38b53..ee8c768 100644 --- a/src/lib/ng2-fittext.module.ts +++ b/projects/lib/src/ng2-fittext.module.ts @@ -1,8 +1,8 @@ -import { Ng2FittextDirective } from './directives/ng2-fittext.directive'; +import { Ng2FittextDirective } from './ng2-fittext.directive'; import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; -export { Ng2FittextDirective } from './directives/ng2-fittext.directive'; +export { Ng2FittextDirective } from './ng2-fittext.directive'; @NgModule({ declarations: [Ng2FittextDirective], @@ -16,4 +16,4 @@ export class Ng2FittextModule { providers: [], }; } -} +} \ No newline at end of file diff --git a/projects/lib/src/public-api.ts b/projects/lib/src/public-api.ts new file mode 100644 index 0000000..5ffad95 --- /dev/null +++ b/projects/lib/src/public-api.ts @@ -0,0 +1,6 @@ +/* + * Public API Surface of lib + */ + +export * from './ng2-fittext.directive'; +export * from './ng2-fittext.module'; diff --git a/projects/lib/tsconfig.lib.json b/projects/lib/tsconfig.lib.json new file mode 100644 index 0000000..543fd47 --- /dev/null +++ b/projects/lib/tsconfig.lib.json @@ -0,0 +1,14 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "../../out-tsc/lib", + "declaration": true, + "declarationMap": true, + "inlineSources": true, + "types": [] + }, + "exclude": [ + "**/*.spec.ts" + ] +} diff --git a/projects/lib/tsconfig.lib.prod.json b/projects/lib/tsconfig.lib.prod.json new file mode 100644 index 0000000..06de549 --- /dev/null +++ b/projects/lib/tsconfig.lib.prod.json @@ -0,0 +1,10 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "extends": "./tsconfig.lib.json", + "compilerOptions": { + "declarationMap": false + }, + "angularCompilerOptions": { + "compilationMode": "partial" + } +} diff --git a/projects/lib/tsconfig.spec.json b/projects/lib/tsconfig.spec.json new file mode 100644 index 0000000..ce7048b --- /dev/null +++ b/projects/lib/tsconfig.spec.json @@ -0,0 +1,14 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "../../out-tsc/spec", + "types": [ + "jasmine" + ] + }, + "include": [ + "**/*.spec.ts", + "**/*.d.ts" + ] +} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 27ea423..8378004 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,7 +1,7 @@ import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; -import {Ng2FittextModule} from '../lib/ng2-fittext.module'; +import { Ng2FittextModule } from 'lib'; @NgModule({ declarations: [ diff --git a/src/lib/.gitignore b/src/lib/.gitignore deleted file mode 100644 index 5b80600..0000000 --- a/src/lib/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -build -coverage -dist -debug.log -node_modules -out-tsc diff --git a/src/lib/.npmignore b/src/lib/.npmignore deleted file mode 100644 index 941041c..0000000 --- a/src/lib/.npmignore +++ /dev/null @@ -1,23 +0,0 @@ -*.spec.ts -*.tgz -.erector -.gitignore -.npmignore -.vscode -build -coverage -debug.log -DEVELOPMENT.md -dist -karma.conf.js -node_modules -out-tsc -src -tasks -test.ts -tsconfig.*json -tslint.json -typings -typings.json -vendor.ts -webpack diff --git a/src/lib/tsconfig.json b/src/lib/tsconfig.json deleted file mode 100644 index a815df9..0000000 --- a/src/lib/tsconfig.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "angularCompilerOptions": { - "strictMetadataEmit": true, - "skipTemplateCodegen": true - }, - "compilerOptions": { - "baseUrl": "tsconfig", - "declaration": true, - "stripInternal": true, - "strictNullChecks": true, - "noImplicitAny": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "lib": ["es2015", "dom", "es5"], - "inlineSources": true, - "rootDir": "./src", - "mapRoot": "./", - "module": "es2015", - "moduleResolution": "node", - "outDir": "./dist", - "sourceMap": true, - "target": "es5", - "typeRoots": [ - "./node_modules/@types" - ], - "paths": { - "@angular/core": ["./node_modules/@angular/core"] - } - }, - "files": [ - ], - "awesomeTypescriptLoaderOptions": { - "forkChecker": true - } -} diff --git a/tsconfig.json b/tsconfig.json index 602e5ea..52f49e7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,11 @@ "strict": true, "noImplicitOverride": true, "noPropertyAccessFromIndexSignature": true, + "paths": { + "lib": [ + "./dist/lib" + ] + }, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, "skipLibCheck": true,