diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +node_modules diff --git a/.eslintrc.json b/.eslintrc.json index 94c5845..9b233a6 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,36 +1,53 @@ { - "root": true, - "ignorePatterns": ["**/*"], - "plugins": ["@nrwl/nx"], - "overrides": [ - { - "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], - "rules": { - "@nrwl/nx/enforce-module-boundaries": [ - "error", - { - "enforceBuildableLibDependency": true, - "allow": [], - "depConstraints": [ - { - "sourceTag": "*", - "onlyDependOnLibsWithTags": ["*"] - } - ] - } - ] - } - }, - { - "files": ["*.ts", "*.tsx"], - "extends": ["plugin:@nrwl/nx/typescript"], - "rules": {} - }, - { - "files": ["*.js", "*.jsx"], - "extends": ["plugin:@nrwl/nx/javascript"], - "rules": {} + "root": true, + "ignorePatterns": ["**/*"], + "plugins": ["@nx"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": { + "@nx/enforce-module-boundaries": [ + "error", + { + "enforceBuildableLibDependency": true, + "allow": [], + "depConstraints": [ + { + "sourceTag": "*", + "onlyDependOnLibsWithTags": ["*"] + } + ] + } + ], + "@nx/dependency-checks": [ + "error", + { + "buildTargets": ["build", "custom-build"], + "ignoredDependencies": ["lodash"], + "includeTransitiveDependencies": true, + "ignoredFiles": ["webpack.config.js", "eslint.config.js"], + "checkMissingDependencies": true, + "checkObsoleteDependencies": true, + "checkVersionMismatches": true + } + ] } - ] - } - \ No newline at end of file + }, + { + "files": ["*.ts", "*.tsx"], + "extends": ["plugin:@nx/typescript"], + "rules": { + "@typescript-eslint/no-extra-semi": "error", + "no-extra-semi": "off" + } + }, + { + "files": ["*.js", "*.jsx"], + "extends": ["plugin:@nx/javascript"], + "rules": { + "@typescript-eslint/no-extra-semi": "error", + "no-extra-semi": "off" + } + } + ] +} diff --git a/.gitignore b/.gitignore index cabe745..3cf0d52 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ testem.log # System Files .DS_Store Thumbs.db + +.nx/cache +.nx/workspace-data \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 diff --git a/.prettierignore b/.prettierignore index d0b804d..daffe92 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,3 +2,6 @@ /dist /coverage + +/.nx/cache +/.nx/workspace-data \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e4e99d..780c4bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,65 +1,227 @@ -## [2.0.7](https://github.com/NativeScript/plugin-tools/compare/2.0.6...2.0.7) (2021-07-26) +## [5.5.3](https://github.com/NativeScript/plugin-tools/compare/5.5.1...5.5.3) (2025-05-21) + + +### Features + +* add migration for improved demo aesthetic ([c7a1ae6](https://github.com/NativeScript/plugin-tools/commit/c7a1ae6d085eb4b9e6d4a2378d8466f5a3bfd3d6)) +* NativeScript 8.9 + + + +# [5.3.0](https://github.com/NativeScript/plugin-tools/compare/5.2.5...5.3.0) (2024-06-19) + + +### Features + +* Nx 19.3+ ([#20](https://github.com/NativeScript/plugin-tools/issues/20)) ([cfb5664](https://github.com/NativeScript/plugin-tools/commit/cfb5664ce926017991d629afe55bb3621ee9ff6f)) + + + +## [5.2.5](https://github.com/NativeScript/plugin-tools/compare/5.2.4...5.2.5) (2024-05-15) ### Bug Fixes -* demo app migration for devDependency updates ([89ffa7b](https://github.com/NativeScript/plugin-tools/commit/89ffa7b11fc3e7f091597b7893656810d0c4780b)) +* **publish:** package preparation ([d9423c5](https://github.com/NativeScript/plugin-tools/commit/d9423c5451898ff75ed4e2c123e3b7bacb93c571)) -## [2.0.6](https://github.com/NativeScript/plugin-tools/compare/2.0.5...2.0.6) (2021-07-25) +## [5.2.4](https://github.com/NativeScript/plugin-tools/compare/5.2.3...5.2.4) (2024-04-09) + + +### Features + +* 8.7 ([456e2ae](https://github.com/NativeScript/plugin-tools/commit/456e2ae81b95aff5f1baf7e08dddea1ceb427e20)) + + + +## [5.2.3](https://github.com/NativeScript/plugin-tools/compare/5.0.3...5.2.3) (2024-04-07) + + +### Features + +* add bump-packages generator ([#19](https://github.com/NativeScript/plugin-tools/issues/19)) ([5061aff](https://github.com/NativeScript/plugin-tools/commit/5061affe4828fc87fa6152d8bf3cf1c6b825a0d6)) +* Nx 18+ with migrations and dep updates ([#18](https://github.com/NativeScript/plugin-tools/issues/18)) ([4ecc884](https://github.com/NativeScript/plugin-tools/commit/4ecc8844974e910f92eb266281c7268f82a1c020)) + + + +## [5.0.3](https://github.com/NativeScript/plugin-tools/compare/5.0.2...5.0.3) (2022-12-28) ### Bug Fixes -* migration handling when other demo's are not {N} apps ([a6521eb](https://github.com/NativeScript/plugin-tools/commit/a6521ebc1e29ca2f6284aab22ca15b34df9d41b9)) +* executor prefix ([f9aa310](https://github.com/NativeScript/plugin-tools/commit/f9aa3107afd278dbbd3a6c2e4e561e18aaf0cc97)) -## [2.0.5](https://github.com/NativeScript/plugin-tools/compare/2.0.4...2.0.5) (2021-07-25) +## [5.0.2](https://github.com/NativeScript/plugin-tools/compare/4.1.1...5.0.2) (2022-12-26) + + +### Features + +* nx migrate 15.4.1, {N} 8.4, Angular 15 ([#17](https://github.com/NativeScript/plugin-tools/issues/17)) ([1d32498](https://github.com/NativeScript/plugin-tools/commit/1d32498af30b2b0122af179a8b9e7b5d9e5d1054)) + + + +## [4.1.1](https://github.com/NativeScript/plugin-tools/compare/4.1.0...4.1.1) (2022-09-17) ### Bug Fixes -* migration handling when other demo's are present ([1f25314](https://github.com/NativeScript/plugin-tools/commit/1f2531435ba038c1b90f98368aab39a9ef274319)) +* migration handling ([9fcb9c9](https://github.com/NativeScript/plugin-tools/commit/9fcb9c93ecd1d0c6f991bc7ff9023c79135d894e)) -## [2.0.4](https://github.com/NativeScript/plugin-tools/compare/2.0.3...2.0.4) (2021-07-24) +# [4.1.0](https://github.com/NativeScript/plugin-tools/compare/4.0.3...4.1.0) (2022-09-17) + + +### Features + +* upgrade to nx 14.7.5 ([#15](https://github.com/NativeScript/plugin-tools/issues/15)) ([fb7cde4](https://github.com/NativeScript/plugin-tools/commit/fb7cde4a7315b47afdf044a4d7780dcf497fe1ea)) + + + +## [4.0.3](https://github.com/NativeScript/plugin-tools/compare/4.0.2...4.0.3) (2022-07-04) + + +### Features + +* include @nrwl/nx-cloud for executors ([9e46567](https://github.com/NativeScript/plugin-tools/commit/9e46567e16a021357b9f02e610451138e6f23a60)) + + + +## [4.0.2](https://github.com/NativeScript/plugin-tools/compare/4.0.1...4.0.2) (2022-07-04) + + +### Features + +* include @nrwl/angular for executors ([830d79c](https://github.com/NativeScript/plugin-tools/commit/830d79cb80b1bc54d0e95ef88cbbb9c8f9c8af1b)) + + + +## [4.0.1](https://github.com/NativeScript/plugin-tools/compare/4.0.0...4.0.1) (2022-07-04) ### Bug Fixes -* migration when run a 2nd time and demo css had already been handled ([dd82faa](https://github.com/NativeScript/plugin-tools/commit/dd82faaa6dd6fab8c6c3b68c70fb9f3109ab41fc)) +* migration handling resilience with config updates ([fc9870a](https://github.com/NativeScript/plugin-tools/commit/fc9870adefa6ce2fb8807a7c7461b02d0d621e40)) -## [2.0.3](https://github.com/NativeScript/plugin-tools/compare/2.0.2...2.0.3) (2021-07-24) +# [4.0.0](https://github.com/NativeScript/plugin-tools/compare/3.0.3...4.0.0) (2022-07-04) ### Features -* generators for add-demo + remove-package ([cb3c5c9](https://github.com/NativeScript/plugin-tools/commit/cb3c5c999fea2863dcd5d34a90a4a6e240ef46b1)) +* **focus:** consider custom modals for demos ([3210cb2](https://github.com/NativeScript/plugin-tools/commit/3210cb21141009d03af8f8b3475df239f696a97d)) +* migration for latest nx ([b07021a](https://github.com/NativeScript/plugin-tools/commit/b07021a1df1f3945de7750d3a77fcb87f0b816c5)) +* nx and flavor updates ([afa72d4](https://github.com/NativeScript/plugin-tools/commit/afa72d4d0ae2137dfcfc0adab833afe869249180)) -## [2.0.2](https://github.com/NativeScript/plugin-tools/compare/2.0.0...2.0.2) (2021-07-23) +## [3.0.3](https://github.com/NativeScript/plugin-tools/compare/3.0.2...3.0.3) (2022-03-21) ### Bug Fixes -* ensure package listing is only valid structures ([828bfce](https://github.com/NativeScript/plugin-tools/commit/828bfcea3cdabb2ad3fda7eb7dc9039bea2722fb)) +* remove-package handling ([211395d](https://github.com/NativeScript/plugin-tools/commit/211395d6c23911994bb398b78269eb84f0b81a8f)) -# [2.0.0](https://github.com/NativeScript/plugin-tools/compare/1.1.0...2.0.0) (2021-07-22) +## [3.0.2](https://github.com/NativeScript/plugin-tools/compare/3.0.1...3.0.2) (2022-03-15) + +### Bug Fixes + +* migration should auto update demo app runtimes ([a47f610](https://github.com/NativeScript/plugin-tools/commit/a47f6108c8f9e200d4c898c22c87fbe8bc458eed)) + + + +## [3.0.1](https://github.com/NativeScript/plugin-tools/compare/3.0.0...3.0.1) (2022-03-09) + + +### Bug Fixes + +* ensure using Nx 13.8.5 @nrwl/js:tsc executor ([f8ff3be](https://github.com/NativeScript/plugin-tools/commit/f8ff3becc58f6ec14cda5510c9b834af61a44c79)) + + + +# [3.0.0](https://github.com/NativeScript/plugin-tools/compare/2.3.0...3.0.0) (2022-03-08) + + +### Features + +* nx latest and more improvements ([#12](https://github.com/NativeScript/plugin-tools/issues/12)) ([323f0ca](https://github.com/NativeScript/plugin-tools/commit/323f0cab9568ca01595e17bde32167ab9768ca4e)) + + + +# [2.3.0](https://github.com/NativeScript/plugin-tools/compare/2.2.1...2.3.0) (2021-10-10) + +### Features + +- allow config to set default repo url and author details ([80c38b5](https://github.com/NativeScript/plugin-tools/commit/80c38b58da6101a25aac6e67379eef102caac18f)) + +## [2.2.1](https://github.com/NativeScript/plugin-tools/compare/2.2.0...2.2.1) (2021-09-16) + +### Bug Fixes + +- migration handling syntax ([d7630ec](https://github.com/NativeScript/plugin-tools/commit/d7630ec2ad55805dddf01bd9ae5953ce0a90d9f8)) + +# [2.2.0](https://github.com/NativeScript/plugin-tools/compare/2.1.0...2.2.0) (2021-09-15) + +### Bug Fixes + +- demo app index for vanilla is now properly updated ([#6](https://github.com/NativeScript/plugin-tools/issues/6)) ([1867989](https://github.com/NativeScript/plugin-tools/commit/18679891a72bfb3f464eaafd3f31265374d31154)) +- remove package ([#7](https://github.com/NativeScript/plugin-tools/issues/7)) ([afc17e3](https://github.com/NativeScript/plugin-tools/commit/afc17e331b371a030e7c4e9e360d980b21d7bc58)) +- remove-package from demo flavours used ([#9](https://github.com/NativeScript/plugin-tools/issues/9)) ([43e9413](https://github.com/NativeScript/plugin-tools/commit/43e9413c4f5169590b5a5b3a7cab16eb293c0669)), closes [#8](https://github.com/NativeScript/plugin-tools/issues/8) + +# [2.1.0](https://github.com/NativeScript/plugin-tools/compare/2.0.7...2.1.0) (2021-08-11) + +### Features + +- allow nonscoped packages ([#5](https://github.com/NativeScript/plugin-tools/issues/5)) ([7d8bff8](https://github.com/NativeScript/plugin-tools/commit/7d8bff80dcdd3178cb9e9d913678ab5e40ff86af)) + +## [2.0.7](https://github.com/NativeScript/plugin-tools/compare/2.0.6...2.0.7) (2021-07-26) + +### Bug Fixes + +- demo app migration for devDependency updates ([89ffa7b](https://github.com/NativeScript/plugin-tools/commit/89ffa7b11fc3e7f091597b7893656810d0c4780b)) + +## [2.0.6](https://github.com/NativeScript/plugin-tools/compare/2.0.5...2.0.6) (2021-07-25) + +### Bug Fixes + +- migration handling when other demo's are not {N} apps ([a6521eb](https://github.com/NativeScript/plugin-tools/commit/a6521ebc1e29ca2f6284aab22ca15b34df9d41b9)) + +## [2.0.5](https://github.com/NativeScript/plugin-tools/compare/2.0.4...2.0.5) (2021-07-25) + +### Bug Fixes + +- migration handling when other demo's are present ([1f25314](https://github.com/NativeScript/plugin-tools/commit/1f2531435ba038c1b90f98368aab39a9ef274319)) + +## [2.0.4](https://github.com/NativeScript/plugin-tools/compare/2.0.3...2.0.4) (2021-07-24) + +### Bug Fixes + +- migration when run a 2nd time and demo css had already been handled ([dd82faa](https://github.com/NativeScript/plugin-tools/commit/dd82faaa6dd6fab8c6c3b68c70fb9f3109ab41fc)) + +## [2.0.3](https://github.com/NativeScript/plugin-tools/compare/2.0.2...2.0.3) (2021-07-24) ### Features -* nx-plugin structure + Nx 12.5.x + webpack5 ([#4](https://github.com/NativeScript/plugin-tools/issues/4)) ([5cd770b](https://github.com/NativeScript/plugin-tools/commit/5cd770be682362fdd0d8bf98c2efcca4cbebafb4)) +- generators for add-demo + remove-package ([cb3c5c9](https://github.com/NativeScript/plugin-tools/commit/cb3c5c999fea2863dcd5d34a90a4a6e240ef46b1)) +## [2.0.2](https://github.com/NativeScript/plugin-tools/compare/2.0.0...2.0.2) (2021-07-23) + +### Bug Fixes + +- ensure package listing is only valid structures ([828bfce](https://github.com/NativeScript/plugin-tools/commit/828bfcea3cdabb2ad3fda7eb7dc9039bea2722fb)) + +# [2.0.0](https://github.com/NativeScript/plugin-tools/compare/1.1.0...2.0.0) (2021-07-22) + +### Features +- nx-plugin structure + Nx 12.5.x + webpack5 ([#4](https://github.com/NativeScript/plugin-tools/issues/4)) ([5cd770b](https://github.com/NativeScript/plugin-tools/commit/5cd770be682362fdd0d8bf98c2efcca4cbebafb4)) # [1.1.0](https://github.com/NativeScript/plugin-tools/compare/1.0.7...1.1.0) (2021-02-21) diff --git a/e2e/plugin-tools-e2e/jest.config.js b/e2e/plugin-tools-e2e/jest.config.js index b9084c2..22f3f37 100644 --- a/e2e/plugin-tools-e2e/jest.config.js +++ b/e2e/plugin-tools-e2e/jest.config.js @@ -1,13 +1,14 @@ module.exports = { displayName: 'plugin-tools-e2e', preset: '../../jest.preset.js', - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - }, - }, + globals: {}, transform: { - '^.+\\.[tj]s$': 'ts-jest', + '^.+\\.[tj]s$': [ + 'ts-jest', + { + tsconfig: '/tsconfig.spec.json', + }, + ], }, moduleFileExtensions: ['ts', 'js', 'html'], coverageDirectory: '../../coverage/e2e/plugin-tools-e2e', diff --git a/e2e/plugin-tools-e2e/project.json b/e2e/plugin-tools-e2e/project.json new file mode 100644 index 0000000..761a935 --- /dev/null +++ b/e2e/plugin-tools-e2e/project.json @@ -0,0 +1,19 @@ +{ + "name": "plugin-tools-e2e", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "projectType": "application", + "sourceRoot": "e2e/plugin-tools-e2e/src", + "tags": [], + "implicitDependencies": ["plugin-tools"], + "targets": { + "e2e": { + "executor": "@nx/jest:jest", + "options": { + "jestConfig": "e2e/plugin-tools-e2e/jest.config.js", + "runInBand": true, + "passWithNoTests": false + }, + "dependsOn": ["plugin-tools:build"] + } + } +} diff --git a/e2e/plugin-tools-e2e/tests/plugin-tools.spec.ts b/e2e/plugin-tools-e2e/tests/plugin-tools.spec.ts index fbc5bfd..703535c 100644 --- a/e2e/plugin-tools-e2e/tests/plugin-tools.spec.ts +++ b/e2e/plugin-tools-e2e/tests/plugin-tools.spec.ts @@ -1,17 +1,9 @@ -import { - checkFilesExist, - ensureNxProject, - readJson, - runNxCommandAsync, - uniq, -} from '@nrwl/nx-plugin/testing'; +import { checkFilesExist, ensureNxProject, readJson, runNxCommandAsync, uniq } from '@nx/plugin/testing'; describe('plugin-tools e2e', () => { it('should create plugin-tools', async () => { const plugin = uniq('plugin-tools'); ensureNxProject('@nativescript/plugin-tools', 'dist/packages/plugin-tools'); - await runNxCommandAsync( - `generate @nativescript/plugin-tools:plugin-tools ${plugin}` - ); + await runNxCommandAsync(`generate @nativescript/plugin-tools:plugin-tools ${plugin}`); const result = await runNxCommandAsync(`build ${plugin}`); expect(result.stdout).toContain('Executor ran'); @@ -20,29 +12,17 @@ describe('plugin-tools e2e', () => { describe('--directory', () => { it('should create src in the specified directory', async () => { const plugin = uniq('plugin-tools'); - ensureNxProject( - '@nativescript/plugin-tools', - 'dist/packages/plugin-tools' - ); - await runNxCommandAsync( - `generate @nativescript/plugin-tools:plugin-tools ${plugin} --directory subdir` - ); - expect(() => - checkFilesExist(`libs/subdir/${plugin}/src/index.ts`) - ).not.toThrow(); + ensureNxProject('@nativescript/plugin-tools', 'dist/packages/plugin-tools'); + await runNxCommandAsync(`generate @nativescript/plugin-tools:plugin-tools ${plugin} --directory subdir`); + expect(() => checkFilesExist(`libs/subdir/${plugin}/src/index.ts`)).not.toThrow(); }, 120000); }); describe('--tags', () => { it('should add tags to nx.json', async () => { const plugin = uniq('plugin-tools'); - ensureNxProject( - '@nativescript/plugin-tools', - 'dist/packages/plugin-tools' - ); - await runNxCommandAsync( - `generate @nativescript/plugin-tools:plugin-tools ${plugin} --tags e2etag,e2ePackage` - ); + ensureNxProject('@nativescript/plugin-tools', 'dist/packages/plugin-tools'); + await runNxCommandAsync(`generate @nativescript/plugin-tools:plugin-tools ${plugin} --tags e2etag,e2ePackage`); const nxJson = readJson('nx.json'); expect(nxJson.projects[plugin].tags).toEqual(['e2etag', 'e2ePackage']); }, 120000); diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 32a0d75..0000000 --- a/jest.config.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - projects: [ - '/packages/plugin-tools', - '/e2e/plugin-tools-e2e', - ], -}; diff --git a/jest.config.ts b/jest.config.ts new file mode 100644 index 0000000..ee4fe21 --- /dev/null +++ b/jest.config.ts @@ -0,0 +1,3 @@ +const { getJestProjects } = require('@nx/jest'); + +export default { projects: [...getJestProjects(), '/e2e/plugin-tools-e2e'] }; diff --git a/jest.preset.js b/jest.preset.js index c93ed9d..c1c3c4c 100644 --- a/jest.preset.js +++ b/jest.preset.js @@ -1,3 +1,15 @@ -const nxPreset = require('@nrwl/jest/preset'); +const nxPreset = require('@nx/jest/preset').default; -module.exports = { ...nxPreset }; +module.exports = { + ...nxPreset, + /* TODO: Update to latest Jest snapshotFormat + * By default Nx has kept the older style of Jest Snapshot formats + * to prevent breaking of any existing tests with snapshots. + * It's recommend you update to the latest format. + * You can do this by removing snapshotFormat property + * and running tests with --update-snapshot flag. + * Example: "nx affected --targets=test --update-snapshot" + * More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format + */ + snapshotFormat: { escapeString: true, printBasicPrototype: true }, +}; diff --git a/migrations.json b/migrations.json new file mode 100644 index 0000000..2185149 --- /dev/null +++ b/migrations.json @@ -0,0 +1,41 @@ +{ + "migrations": [ + { + "version": "20.0.0-beta.7", + "description": "Migration for v20.0.0-beta.7", + "implementation": "./src/migrations/update-20-0-0/move-use-daemon-process", + "package": "nx", + "name": "move-use-daemon-process" + }, + { + "version": "20.0.1", + "description": "Set `useLegacyCache` to true for migrating workspaces", + "implementation": "./src/migrations/update-20-0-1/use-legacy-cache", + "x-repair-skip": true, + "package": "nx", + "name": "use-legacy-cache" + }, + { + "version": "20.2.0-beta.5", + "description": "Update TypeScript ESLint packages to v8.13.0 if they are already on v8", + "implementation": "./src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0", + "package": "@nx/eslint", + "name": "update-typescript-eslint-v8.13.0" + }, + { + "version": "20.3.0-beta.1", + "description": "Update ESLint flat config to include .cjs, .mjs, .cts, and .mts files in overrides (if needed)", + "implementation": "./src/migrations/update-20-3-0/add-file-extensions-to-overrides", + "package": "@nx/eslint", + "name": "add-file-extensions-to-overrides" + }, + { + "cli": "nx", + "version": "20.0.0-beta.5", + "description": "replace getJestProjects with getJestProjectsAsync", + "implementation": "./src/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync", + "package": "@nx/jest", + "name": "replace-getJestProjects-with-getJestProjectsAsync" + } + ] +} diff --git a/nx.json b/nx.json index 876dc83..dc72914 100644 --- a/nx.json +++ b/nx.json @@ -1,34 +1,50 @@ { - "npmScope": "nativescript", - "affected": { - "defaultBase": "master" + "workspaceLayout": { + "appsDir": "e2e", + "libsDir": "packages" }, - "implicitDependencies": { - "package.json": { - "dependencies": "*", - "devDependencies": "*" + "$schema": "./node_modules/nx/schemas/nx-schema.json", + "targetDefaults": { + "build": { + "dependsOn": ["^build"], + "inputs": ["production", "^production"], + "cache": true }, - ".eslintrc.json": "*" - }, - "targetDependencies": { - "build": [ - { - "target": "build", - "projects": "dependencies" + "@nx/jest:jest": { + "cache": true, + "inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"], + "options": { + "passWithNoTests": true + }, + "configurations": { + "ci": { + "ci": true, + "codeCoverage": true + } } - ] - }, - "projects": { - "plugin-tools": { - "tags": [] }, - "plugin-tools-e2e": { - "tags": [], - "implicitDependencies": ["plugin-tools"] + "@nx/eslint:lint": { + "inputs": ["default", "{workspaceRoot}/.eslintrc.json"], + "cache": true } }, - "workspaceLayout": { - "appsDir": "e2e", - "libsDir": "packages" - } + "tasksRunnerOptions": { + "default": { + "options": { + "runtimeCacheInputs": ["node -v"], + "canTrackAnalytics": false, + "showUsageWarnings": true + } + } + }, + "namedInputs": { + "default": ["{projectRoot}/**/*", "sharedGlobals"], + "sharedGlobals": [], + "production": ["default", "!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)", "!{projectRoot}/tsconfig.spec.json", "!{projectRoot}/jest.config.[jt]s", "!{projectRoot}/.eslintrc.json", "!{projectRoot}/src/test-setup.[jt]s"] + }, + "useDaemonProcess": false, + "parallel": 1, + "useInferencePlugins": false, + "defaultBase": "master", + "useLegacyCache": true } diff --git a/package.json b/package.json index 50239d1..26e9848 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/plugin-tools-source", - "version": "2.0.7", + "version": "5.5.3", "license": "MIT", "scripts": { "clean": "npx rimraf package-lock.json yarn.lock node_modules && yarn", @@ -25,47 +25,50 @@ "workspace-generator": "nx workspace-generator", "dep-graph": "nx dep-graph", "help": "nx help", - "postinstall": "husky install", + "postinstall": "husky", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", "reset.changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0", "contributors": "githubcontrib --owner NativeScript --repo $(basename $(pwd)) --cols 6 --showlogin true --sortOrder desc | pbcopy" }, "private": true, - "dependencies": { - "tslib": "^2.0.0" - }, "devDependencies": { - "@nrwl/cli": "12.5.9", - "@nrwl/devkit": "12.5.9", - "@nrwl/eslint-plugin-nx": "12.5.9", - "@nrwl/jest": "12.5.9", - "@nrwl/linter": "12.5.9", - "@nrwl/node": "12.5.9", - "@nrwl/nx-plugin": "12.5.9", - "@nrwl/tao": "12.5.9", - "@nrwl/workspace": "12.5.9", - "@types/jest": "26.0.8", - "@types/node": "14.14.33", - "@typescript-eslint/eslint-plugin": "4.19.0", - "@typescript-eslint/parser": "4.19.0", - "conventional-changelog-cli": "~2.1.0", - "dotenv": "8.2.0", - "eslint": "7.22.0", - "eslint-config-prettier": "8.1.0", + "@nx/devkit": "20.3.3", + "@nx/eslint": "20.3.3", + "@nx/eslint-plugin": "20.3.3", + "@nx/jest": "20.3.3", + "@nx/js": "20.3.3", + "@nx/node": "20.3.3", + "@nx/plugin": "20.3.3", + "@nx/workspace": "20.3.3", + "@swc-node/register": "1.10.9", + "@swc/core": "1.7.10", + "@types/jest": "29.5.14", + "@types/node": "^20.0.0", + "@typescript-eslint/eslint-plugin": "^8.13.0", + "@typescript-eslint/parser": "^8.13.0", + "@typescript-eslint/utils": "^8.13.0", + "conventional-changelog-cli": "^5.0.0", + "dotenv": "~16.4.0", + "eslint": "^9.9.0", + "eslint-config-prettier": "^9.1.0", "github-contributors-list": "~1.2.3", - "husky": "~5.1.3", - "jest": "27.0.3", - "jsonc-parser": "3.0.0", + "husky": "~9.0.0", + "jest": "29.7.0", + "nx": "20.3.3", + "nx-cloud": "19.1.0", "parse-version-string": "^1.0.1", - "prettier": "^2.3.1", - "ts-jest": "27.0.3", - "ts-node": "~9.1.1", + "prettier": "^3.3.0", + "rxjs": "^7.8.1", + "semver": "^7.5.4", + "ts-jest": "29.2.4", + "ts-node": "^10.9.0", "tslib": "^2.0.0", - "typescript": "~4.2.4" + "typescript": "5.6.3" }, "lint-staged": { "**/*.{js,ts,scss,json,html}": [ "npx prettier --write" ] - } + }, + "dependencies": {} } diff --git a/packages/plugin-tools/.babelrc b/packages/plugin-tools/.babelrc index cf7ddd9..fd4cbcd 100644 --- a/packages/plugin-tools/.babelrc +++ b/packages/plugin-tools/.babelrc @@ -1,3 +1,10 @@ { - "presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]] + "presets": [ + [ + "@nx/js/babel", + { + "useBuiltIns": "usage" + } + ] + ] } diff --git a/packages/plugin-tools/.eslintrc.json b/packages/plugin-tools/.eslintrc.json index 9d9c0db..adbe7ae 100644 --- a/packages/plugin-tools/.eslintrc.json +++ b/packages/plugin-tools/.eslintrc.json @@ -13,6 +13,13 @@ { "files": ["*.js", "*.jsx"], "rules": {} + }, + { + "files": ["*.json"], + "parser": "jsonc-eslint-parser", + "rules": { + "@nx/dependency-checks": "error" + } } ] } diff --git a/packages/plugin-tools/README.md b/packages/plugin-tools/README.md index 9f84eef..d322ded 100644 --- a/packages/plugin-tools/README.md +++ b/packages/plugin-tools/README.md @@ -1 +1 @@ -## Tooling for NativeScript plugin workspaces \ No newline at end of file +## Tooling for NativeScript plugin workspaces diff --git a/packages/plugin-tools/generators.json b/packages/plugin-tools/generators.json index b197e69..90337b9 100644 --- a/packages/plugin-tools/generators.json +++ b/packages/plugin-tools/generators.json @@ -42,6 +42,11 @@ "factory": "./src/generators/config", "schema": "./src/generators/config/schema.json", "description": "Configure workspace scope." + }, + "bump-packages": { + "factory": "./src/generators/bump-packages/generator", + "schema": "./src/generators/bump-packages/schema.json", + "description": "bump-packages generator" } } } diff --git a/packages/plugin-tools/jest.config.js b/packages/plugin-tools/jest.config.ts similarity index 57% rename from packages/plugin-tools/jest.config.js rename to packages/plugin-tools/jest.config.ts index 7a755a1..0ec63af 100644 --- a/packages/plugin-tools/jest.config.js +++ b/packages/plugin-tools/jest.config.ts @@ -1,14 +1,16 @@ -module.exports = { +/* eslint-disable */ +export default { displayName: 'plugin-tools', preset: '../../jest.preset.js', - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - }, - }, + globals: {}, testEnvironment: 'node', transform: { - '^.+\\.[tj]sx?$': 'ts-jest', + '^.+\\.[tj]sx?$': [ + 'ts-jest', + { + tsconfig: '/tsconfig.spec.json', + }, + ], }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], coverageDirectory: '../../coverage/packages/plugin-tools', diff --git a/packages/plugin-tools/migrations.json b/packages/plugin-tools/migrations.json index f1e1966..ad2814c 100644 --- a/packages/plugin-tools/migrations.json +++ b/packages/plugin-tools/migrations.json @@ -1,20 +1,94 @@ { - "schematics": { - "update-to-1.0.6": { - "version": "1.0.6", - "description": "Migrate tools to 1.0.6", - "factory": "./src/migrations/update-1-0-6/update-1-0-6" - }, - "update-to-1.1.0": { - "version": "1.1.0", - "description": "Migrate tools to 1.1.0", - "factory": "./src/migrations/update-1-1-0/update-1-1-0" - }, - "update-to-2.0.0": { - "version": "2.0.0", - "description": "Migrate tools to 2.0.0", - "factory": "./src/migrations/update-2-0-0/update-2-0-0" - } + "generators": { + "update-to-1.0.6": { + "cli": "nx", + "version": "1.0.6", + "description": "Migrate tools to 1.0.6", + "implementation": "./src/migrations/update-1-0-6/update-1-0-6" + }, + "update-to-1.1.0": { + "cli": "nx", + "version": "1.1.0", + "description": "Migrate tools to 1.1.0", + "implementation": "./src/migrations/update-1-1-0/update-1-1-0" + }, + "update-to-2.0.0": { + "cli": "nx", + "version": "2.0.0", + "description": "Migrate tools to 2.0.0", + "implementation": "./src/migrations/update-2-0-0/update-2-0-0" + }, + "update-to-2.1.0": { + "cli": "nx", + "version": "2.1.0", + "description": "Migrate tools to 2.1.0", + "implementation": "./src/migrations/update-2-1-0/update-2-1-0" + }, + "update-to-2.2.1": { + "cli": "nx", + "version": "2.2.1", + "description": "Migrate tools to 2.2.1", + "implementation": "./src/migrations/update-2-2-1/update-2-2-1" + }, + "update-to-3.0.0": { + "cli": "nx", + "version": "3.0.0", + "description": "Migrate tools to 3.0.0", + "implementation": "./src/migrations/update-3-0-0/update-3-0-0" + }, + "update-to-4.0.0": { + "cli": "nx", + "version": "4.0.0", + "description": "Migrate tools to 4.0.0", + "implementation": "./src/migrations/update-4-0-0/update-4-0-0" + }, + "update-to-4.1.0": { + "cli": "nx", + "version": "4.1.0", + "description": "Migrate tools to 4.1.0", + "implementation": "./src/migrations/update-4-1-0/update-4-1-0" + }, + "update-to-5.0.2": { + "cli": "nx", + "version": "5.0.2", + "description": "Migrate tools to 5.0.0", + "implementation": "./src/migrations/update-5-0-0/update-5-0-0" + }, + "update-to-5.1.0": { + "cli": "nx", + "version": "5.1.0", + "description": "Migrate tools to 5.1.0", + "implementation": "./src/migrations/update-5-1-0/update-5-1-0" + }, + "update-to-5.2.0": { + "cli": "nx", + "version": "5.2.0", + "description": "Migrate tools to 5.2.0", + "implementation": "./src/migrations/update-5-2-0/update-5-2-0" + }, + "update-to-5.3.0": { + "cli": "nx", + "version": "5.3.0", + "description": "Migrate tools to 5.3.0", + "implementation": "./src/migrations/update-5-3-0/update-5-3-0" + }, + "update-to-5.4.0": { + "cli": "nx", + "version": "5.4.0", + "description": "Migrate tools to 5.4.0", + "implementation": "./src/migrations/update-5-4-0/update-5-4-0" + }, + "update-to-5.5.0": { + "cli": "nx", + "version": "5.5.0", + "description": "Migrate tools to 5.5.0", + "implementation": "./src/migrations/update-5-5-0/update-5-5-0" + }, + "update-to-5.5.3": { + "cli": "nx", + "version": "5.5.3", + "description": "Migrate tools to 5.5.3", + "implementation": "./src/migrations/update-5-5-3/update-5-5-3" } } - \ No newline at end of file +} diff --git a/packages/plugin-tools/package.json b/packages/plugin-tools/package.json index 6b9c671..3ea0885 100644 --- a/packages/plugin-tools/package.json +++ b/packages/plugin-tools/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/plugin-tools", - "version": "2.0.7", + "version": "5.5.3", "description": "NativeScript plugin tooling for workspaces", "homepage": "https://nativescript.org", "repository": { @@ -22,37 +22,39 @@ "main": "src/index.js", "generators": "./generators.json", "executors": "./executors.json", - "ng-update": { - "requirements": {}, + "nx-migrations": { "migrations": "./migrations.json" }, "dependencies": { - "xml2js": "~0.4.23", - "@nativescript/nx": "^2.0.0", - "@nrwl/devkit": "12.5.9", - "@nrwl/eslint-plugin-nx": "12.5.9", - "@nrwl/jest": "12.5.9", - "@nrwl/node": "12.5.9", - "@nrwl/workspace": "12.5.9", - "@nstudio/focus": "^12.5.0", - "@nstudio/nps-i": "^1.1.0", - "@types/jest": "~26.0.10", - "@types/node": "14.14.37", - "dotenv": "~8.2.0", - "husky": "^5.1.3", - "jest": "~26.5.2", - "jsonc-parser": "3.0.0", - "lint-staged": "^11.0.0", - "nativescript-permissions": "^1.3.9", + "xml2js": "~0.6.0", + "@nativescript/nx": "^20.0.0", + "@nx/angular": "^20.0.0", + "@nx/devkit": "^20.0.0", + "@nx/eslint": "^20.0.0", + "@nx/workspace": "^20.0.0", + "@nx/js": "^20.0.0", + "@nx/plugin": "^20.0.0", + "@nx/jest": "^20.0.0", + "@nx/node": "^20.0.0", + "@nx/eslint-plugin": "^20.0.0", + "nx-cloud": "^19.1.0", + "@nstudio/focus": "^20.0.0", + "@nstudio/nps-i": "^2.0.0", + "@types/node": "^22.0.0", + "@typescript-eslint/eslint-plugin": "^8.0.0", + "@typescript-eslint/parser": "^8.0.0", + "eslint": "^9.9.0", + "eslint-config-prettier": "^9.1.0", + "husky": "^9.0.0", + "lint-staged": "15.2.5", "nativescript-theme-core": "~1.0.4", "sass": "^1.35.0", + "semver": "^7.5.4", "parse-version-string": "^1.0.1", - "prettier": "~2.3.0", + "prettier": "^3.3.0", "pretty-data": "^0.40.0", - "rimraf": "^3.0.2", - "ts-jest": "27.0.3", - "ts-node": "~9.1.0", - "ts-patch": "^1.3.0", - "tslint": "~6.1.2" + "rimraf": "^6.0.0", + "ts-node": "^10.0.0", + "ts-patch": "^3.0.0" } } diff --git a/packages/plugin-tools/project.json b/packages/plugin-tools/project.json new file mode 100644 index 0000000..44d007e --- /dev/null +++ b/packages/plugin-tools/project.json @@ -0,0 +1,58 @@ +{ + "name": "plugin-tools", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "packages/plugin-tools/src", + "projectType": "library", + "tags": [], + "targets": { + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"] + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/packages/plugin-tools"], + "options": { + "jestConfig": "packages/plugin-tools/jest.config.ts" + } + }, + "build": { + "executor": "@nx/js:tsc", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/packages/plugin-tools", + "tsConfig": "packages/plugin-tools/tsconfig.lib.json", + "packageJson": "packages/plugin-tools/package.json", + "main": "packages/plugin-tools/src/index.ts", + "assets": [ + "packages/plugin-tools/*.md", + { + "input": "./packages/plugin-tools/src", + "glob": "**/!(*.ts)", + "output": "./src" + }, + { + "input": "./packages/plugin-tools/src", + "glob": "**/*.d.ts", + "output": "./src" + }, + { + "input": "./packages/plugin-tools", + "glob": "generators.json", + "output": "." + }, + { + "input": "./packages/plugin-tools", + "glob": "executors.json", + "output": "." + }, + { + "input": "./packages/plugin-tools", + "glob": "migrations.json", + "output": "." + } + ] + } + } + } +} diff --git a/packages/plugin-tools/src/executors/build/schema.json b/packages/plugin-tools/src/executors/build/schema.json index 54d8d22..a45d779 100644 --- a/packages/plugin-tools/src/executors/build/schema.json +++ b/packages/plugin-tools/src/executors/build/schema.json @@ -1,7 +1,10 @@ { + "version": 2, + "outputCapture": "direct-nodejs", "$schema": "http://json-schema.org/schema", - "cli": "nx", "title": "Build executor", + "$id": "build-executor", + "cli": "nx", "description": "", "type": "object", "properties": {}, diff --git a/packages/plugin-tools/src/generators/add-angular/files/__dot__eslintrc.json b/packages/plugin-tools/src/generators/add-angular/files/__dot__eslintrc.json new file mode 100644 index 0000000..b373d84 --- /dev/null +++ b/packages/plugin-tools/src/generators/add-angular/files/__dot__eslintrc.json @@ -0,0 +1,24 @@ +{ + "extends": ["../.eslintrc.json"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": { + "@nrwl/nx/enforce-module-boundaries": [ + "error", + { + "allowCircularSelfDependency": true + } + ] + } + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/packages/plugin-tools/src/generators/add-angular/files/index.ts__tmpl__ b/packages/plugin-tools/src/generators/add-angular/files/index.ts__tmpl__ index c9063af..df9ea8a 100644 --- a/packages/plugin-tools/src/generators/add-angular/files/index.ts__tmpl__ +++ b/packages/plugin-tools/src/generators/add-angular/files/index.ts__tmpl__ @@ -1,6 +1,6 @@ import { NgModule } from '@angular/core'; import { registerElement } from '@nativescript/angular'; -import { <%= stringUtils.classify(name) %> } from '<%= npmScope %>/<%= name %>'; +import { <%= stringUtils.classify(name) %> } from '<%= npmPackageName %>'; @NgModule() export class NativeScript<%= stringUtils.classify(name) %>Module {} diff --git a/packages/plugin-tools/src/generators/add-angular/files/ng-package.json b/packages/plugin-tools/src/generators/add-angular/files/ng-package.json new file mode 100644 index 0000000..1b72c68 --- /dev/null +++ b/packages/plugin-tools/src/generators/add-angular/files/ng-package.json @@ -0,0 +1,8 @@ +{ + "$schema": "../../../node_modules/ng-packagr/ng-package.schema.json", + "lib": { + "entryFile": "index.ts" + }, + "allowedNonPeerDependencies": ["."], + "dest": "../../../dist/packages/<%= name %>/angular" +} diff --git a/packages/plugin-tools/src/generators/add-angular/files/package.json b/packages/plugin-tools/src/generators/add-angular/files/package.json index ca7957c..2ab1be4 100644 --- a/packages/plugin-tools/src/generators/add-angular/files/package.json +++ b/packages/plugin-tools/src/generators/add-angular/files/package.json @@ -1,16 +1,3 @@ { - "name": "<%= nxNpmScope %>-<%= name %>-angular", - "ngPackage": { - "lib": { - "entryFile": "index.ts", - "umdModuleIds": { - "@nativescript/core": "ns-core", - "@nativescript/angular": "ns-angular", - "<%= npmScope %>/<%= name %>": "ns-<%= name %>" - } - }, - "allowedNonPeerDependencies": [ - "." - ] - } + "name": "<%= npmPackageName %>-angular" } diff --git a/packages/plugin-tools/src/generators/add-angular/files/tsconfig.angular.json b/packages/plugin-tools/src/generators/add-angular/files/tsconfig.angular.json index a3c8a0f..a43b92a 100644 --- a/packages/plugin-tools/src/generators/add-angular/files/tsconfig.angular.json +++ b/packages/plugin-tools/src/generators/add-angular/files/tsconfig.angular.json @@ -1,10 +1,13 @@ { - "extends": "../../../node_modules/ng-packagr/lib/ts/conf/tsconfig.ngc.json", - "compilerOptions": { - "types": ["node"], - "baseUrl": ".", - "paths": { - "<%= npmScope %>/<%= name %>": ["../../../dist/packages/<%= name %>"] - } - } + "extends": "../../../node_modules/ng-packagr/lib/ts/conf/tsconfig.ngc.json", + "compilerOptions": { + "types": ["node"], + "baseUrl": ".", + "paths": { + "<%= npmPackageName %>": ["../../../dist/packages/<%= name %>"] + }, + "outDir": "../../../dist/out-tsc", + "declarationDir": "../../../dist/out-tsc" + }, + "files": ["index.ts"] } diff --git a/packages/plugin-tools/src/generators/add-angular/files/tsconfig.json b/packages/plugin-tools/src/generators/add-angular/files/tsconfig.json index 2d6ba44..0ec69de 100644 --- a/packages/plugin-tools/src/generators/add-angular/files/tsconfig.json +++ b/packages/plugin-tools/src/generators/add-angular/files/tsconfig.json @@ -1,7 +1,7 @@ { - "extends": "../../../tsconfig.base.json", - "compilerOptions": { - "outDir": "../../../dist/out-tsc", - "rootDir": "." - } -} \ No newline at end of file + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "rootDirs": [".", "../.."] + } +} diff --git a/packages/plugin-tools/src/generators/add-angular/index.ts b/packages/plugin-tools/src/generators/add-angular/index.ts index ba141bd..b11c99a 100644 --- a/packages/plugin-tools/src/generators/add-angular/index.ts +++ b/packages/plugin-tools/src/generators/add-angular/index.ts @@ -1,19 +1,29 @@ -import { generateFiles, joinPathFragments, Tree } from '@nrwl/devkit'; -import { stringUtils } from '@nrwl/workspace'; -import { prerun, getNpmScope, getNxNpmScope } from '../../utils'; +import { generateFiles, joinPathFragments, readJson, Tree, updateJson } from '@nx/devkit'; +import * as stringUtils from '@nx/devkit/src/utils/string-utils'; +import { prerun, getNpmScope } from '../../utils'; import { Schema } from './schema'; let name: string; +let npmPackageName: string; export default async function (tree: Tree, schema: Schema) { name = stringUtils.dasherize(schema.name.toLowerCase()); prerun(tree); addAngularFiles(tree); - console.log(`Angular support added for "${getNpmScope()}/${name}". Continue developing the Angular support in the packages/${name}/angular folder.`); + updateJson(tree, 'tsconfig.base.json', (json) => { + const packagePath = {}; + packagePath[`${npmPackageName}/angular`] = [`packages/${name}/angular/index.ts`]; + json.compilerOptions.paths = { ...json.compilerOptions.paths, ...packagePath }; + return json; + }); + console.log(`Angular support added for "${npmPackageName}". Continue developing the Angular support in the packages/${name}/angular folder.`); } function addAngularFiles(tree: Tree) { console.log(`Adding Angular support to ${name}...`); - generateFiles(tree, joinPathFragments(__dirname, 'files'), `./packages/${name}/angular`, { name, npmScope: getNpmScope(), nxNpmScope: getNxNpmScope(), stringUtils, tmpl: '', dot: '.' }); + const packageJson = readJson(tree, `packages/${name}/package.json`); + npmPackageName = packageJson.name; + + generateFiles(tree, joinPathFragments(__dirname, 'files'), `./packages/${name}/angular`, { name, npmPackageName, npmScope: getNpmScope(), stringUtils, tmpl: '', dot: '.' }); } diff --git a/packages/plugin-tools/src/generators/add-angular/schema.json b/packages/plugin-tools/src/generators/add-angular/schema.json index 20b96d8..4eeff71 100644 --- a/packages/plugin-tools/src/generators/add-angular/schema.json +++ b/packages/plugin-tools/src/generators/add-angular/schema.json @@ -1,8 +1,8 @@ { "$schema": "http://json-schema.org/schema", - "cli": "nx", "title": "Add Angular support to package", - "id": "add-angular", + "$id": "add-angular", + "cli": "nx", "type": "object", "properties": { "name": { diff --git a/packages/plugin-tools/src/generators/add-demo/files_react/__dot__eslintrc.json b/packages/plugin-tools/src/generators/add-demo/files_react/__dot__eslintrc.json new file mode 100644 index 0000000..53c06c8 --- /dev/null +++ b/packages/plugin-tools/src/generators/add-demo/files_react/__dot__eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*", "node_modules/**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/packages/plugin-tools/src/generators/add-demo/files_react/package.json b/packages/plugin-tools/src/generators/add-demo/files_react/package.json index a1f8236..750649a 100644 --- a/packages/plugin-tools/src/generators/add-demo/files_react/package.json +++ b/packages/plugin-tools/src/generators/add-demo/files_react/package.json @@ -4,7 +4,7 @@ "@nativescript/core": "file:../../node_modules/@nativescript/core" }, "devDependencies": { - "@nativescript/android": "8.0.0", - "@nativescript/ios": "8.0.0" + "@nativescript/android": "~8.8.0", + "@nativescript/ios": "~8.8.0" } } diff --git a/packages/plugin-tools/src/generators/add-demo/files_react/src/app.scss b/packages/plugin-tools/src/generators/add-demo/files_react/src/app.scss index f48bce1..7720737 100644 --- a/packages/plugin-tools/src/generators/add-demo/files_react/src/app.scss +++ b/packages/plugin-tools/src/generators/add-demo/files_react/src/app.scss @@ -1,2 +1,6 @@ @import 'nativescript-theme-core/scss/light'; @import 'nativescript-theme-core/scss/index'; + +.rounded { + border-radius: 20; +} diff --git a/packages/plugin-tools/src/generators/add-demo/files_react/tsconfig.json b/packages/plugin-tools/src/generators/add-demo/files_react/tsconfig.json index 38a4166..9edf877 100644 --- a/packages/plugin-tools/src/generators/add-demo/files_react/tsconfig.json +++ b/packages/plugin-tools/src/generators/add-demo/files_react/tsconfig.json @@ -1,21 +1,12 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "rootDirs": [ - ".", - "../.." - ], + "rootDirs": [".", "../.."], "baseUrl": ".", "paths": { - "~/*": [ - "src/*" - ], - "@demo/shared": [ - "../../tools/demo/index.ts" - ], - "<%= npmScope %>/*": [ - "../../packages/*" - ] + "~/*": ["src/*"], + "@demo/shared": ["../../tools/demo/index.ts"], + "<%= npmScope %>/*": ["../../packages/*"] } } } diff --git a/packages/plugin-tools/src/generators/add-demo/files_react/webpack.config.js b/packages/plugin-tools/src/generators/add-demo/files_react/webpack.config.js index 31baeb2..8fcd972 100644 --- a/packages/plugin-tools/src/generators/add-demo/files_react/webpack.config.js +++ b/packages/plugin-tools/src/generators/add-demo/files_react/webpack.config.js @@ -2,7 +2,6 @@ const webpack = require('@nativescript/webpack'); const { resolve } = require('path'); module.exports = (env) => { - webpack.init(env); webpack.useConfig('react'); @@ -13,8 +12,8 @@ module.exports = (env) => { // Example of how to share common images across demo apps: // webpack.Utils.addCopyRule({ - // from: '../../../tools/images', - // to: 'images', + // from: '../../../tools/images', + // to: 'images', // context: webpack.Utils.project.getProjectFilePath('node_modules') // }); diff --git a/packages/plugin-tools/src/generators/add-demo/files_svelte/__dot__eslintrc.json b/packages/plugin-tools/src/generators/add-demo/files_svelte/__dot__eslintrc.json new file mode 100644 index 0000000..53c06c8 --- /dev/null +++ b/packages/plugin-tools/src/generators/add-demo/files_svelte/__dot__eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*", "node_modules/**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/packages/plugin-tools/src/generators/add-demo/files_svelte/app/app.scss b/packages/plugin-tools/src/generators/add-demo/files_svelte/app/app.scss index 2f132c3..6899485 100644 --- a/packages/plugin-tools/src/generators/add-demo/files_svelte/app/app.scss +++ b/packages/plugin-tools/src/generators/add-demo/files_svelte/app/app.scss @@ -1,2 +1,6 @@ @import 'nativescript-theme-core/scss/light'; @import 'nativescript-theme-core/scss/index'; + +.rounded { + border-radius: 20; +} diff --git a/packages/plugin-tools/src/generators/add-demo/files_svelte/package.json b/packages/plugin-tools/src/generators/add-demo/files_svelte/package.json index 2108d10..35a3af4 100644 --- a/packages/plugin-tools/src/generators/add-demo/files_svelte/package.json +++ b/packages/plugin-tools/src/generators/add-demo/files_svelte/package.json @@ -4,7 +4,7 @@ "@nativescript/core": "file:../../node_modules/@nativescript/core" }, "devDependencies": { - "@nativescript/android": "8.0.0", - "@nativescript/ios": "8.0.0" + "@nativescript/android": "~8.8.0", + "@nativescript/ios": "~8.8.0" } } diff --git a/packages/plugin-tools/src/generators/add-demo/files_svelte/svelte.config.js b/packages/plugin-tools/src/generators/add-demo/files_svelte/svelte.config.js index 5209f08..2dd3664 100644 --- a/packages/plugin-tools/src/generators/add-demo/files_svelte/svelte.config.js +++ b/packages/plugin-tools/src/generators/add-demo/files_svelte/svelte.config.js @@ -1,5 +1,5 @@ -const sveltePreprocess = require('svelte-preprocess') +const sveltePreprocess = require('svelte-preprocess'); module.exports = { preprocess: sveltePreprocess(), -} +}; diff --git a/packages/plugin-tools/src/generators/add-demo/files_svelte/tsconfig.json b/packages/plugin-tools/src/generators/add-demo/files_svelte/tsconfig.json index e084199..c8c79e3 100644 --- a/packages/plugin-tools/src/generators/add-demo/files_svelte/tsconfig.json +++ b/packages/plugin-tools/src/generators/add-demo/files_svelte/tsconfig.json @@ -1,21 +1,12 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "rootDirs": [ - ".", - "../.." - ], + "rootDirs": [".", "../.."], "baseUrl": ".", "paths": { - "~/*": [ - "app/*" - ], - "@demo/shared": [ - "../../tools/demo/index.ts" - ], - "<%= npmScope %>/*": [ - "../../packages/*" - ] + "~/*": ["app/*"], + "@demo/shared": ["../../tools/demo/index.ts"], + "<%= npmScope %>/*": ["../../packages/*"] } } } diff --git a/packages/plugin-tools/src/generators/add-demo/files_svelte/webpack.config.js b/packages/plugin-tools/src/generators/add-demo/files_svelte/webpack.config.js index 5e85e54..cf0df89 100644 --- a/packages/plugin-tools/src/generators/add-demo/files_svelte/webpack.config.js +++ b/packages/plugin-tools/src/generators/add-demo/files_svelte/webpack.config.js @@ -2,7 +2,6 @@ const webpack = require('@nativescript/webpack'); const { resolve } = require('path'); module.exports = (env) => { - webpack.init(env); webpack.useConfig('svelte'); @@ -10,21 +9,21 @@ module.exports = (env) => { // shared demo code config.resolve.alias.set('@demo/shared', resolve(__dirname, '..', '..', 'tools', 'demo')); - config.set( - 'ignoreWarnings', - (config.get('ignoreWarnings') || []).concat([ - { - module: /svelte-native\/dom/, - message: /export/, - } - ]) - ) + config.set( + 'ignoreWarnings', + (config.get('ignoreWarnings') || []).concat([ + { + module: /svelte-native\/dom/, + message: /export/, + }, + ]) + ); }); // Example of how to share common images across demo apps: // webpack.Utils.addCopyRule({ - // from: '../../../tools/images', - // to: 'images', + // from: '../../../tools/images', + // to: 'images', // context: webpack.Utils.project.getProjectFilePath('node_modules') // }); diff --git a/packages/plugin-tools/src/generators/add-demo/files_vue/__dot__eslintrc.json b/packages/plugin-tools/src/generators/add-demo/files_vue/__dot__eslintrc.json new file mode 100644 index 0000000..53c06c8 --- /dev/null +++ b/packages/plugin-tools/src/generators/add-demo/files_vue/__dot__eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*", "node_modules/**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/packages/plugin-tools/src/generators/add-demo/files_vue/app/app.android.css b/packages/plugin-tools/src/generators/add-demo/files_vue/app/app.android.css new file mode 100644 index 0000000..0f5a461 --- /dev/null +++ b/packages/plugin-tools/src/generators/add-demo/files_vue/app/app.android.css @@ -0,0 +1,5 @@ +@import 'nativescript-theme-core/css/core.light.android.css'; + +.rounded { + border-radius: 20; +} \ No newline at end of file diff --git a/packages/plugin-tools/src/generators/add-demo/files_vue/app/app.ios.css b/packages/plugin-tools/src/generators/add-demo/files_vue/app/app.ios.css new file mode 100644 index 0000000..b6e8a88 --- /dev/null +++ b/packages/plugin-tools/src/generators/add-demo/files_vue/app/app.ios.css @@ -0,0 +1,5 @@ +@import 'nativescript-theme-core/css/core.light.ios.css'; + +.rounded { + border-radius: 20; +} \ No newline at end of file diff --git a/packages/plugin-tools/src/generators/add-demo/files_vue/app/app.scss b/packages/plugin-tools/src/generators/add-demo/files_vue/app/app.scss deleted file mode 100644 index f48bce1..0000000 --- a/packages/plugin-tools/src/generators/add-demo/files_vue/app/app.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import 'nativescript-theme-core/scss/light'; -@import 'nativescript-theme-core/scss/index'; diff --git a/packages/plugin-tools/src/generators/add-demo/files_vue/app/components/Home.vue b/packages/plugin-tools/src/generators/add-demo/files_vue/app/components/Home.vue index c5c1aab..3f417a2 100644 --- a/packages/plugin-tools/src/generators/add-demo/files_vue/app/components/Home.vue +++ b/packages/plugin-tools/src/generators/add-demo/files_vue/app/components/Home.vue @@ -1,32 +1,31 @@ - diff --git a/packages/plugin-tools/src/generators/add-demo/files_vue/package.json b/packages/plugin-tools/src/generators/add-demo/files_vue/package.json index 2e37b70..5d8abbe 100644 --- a/packages/plugin-tools/src/generators/add-demo/files_vue/package.json +++ b/packages/plugin-tools/src/generators/add-demo/files_vue/package.json @@ -5,7 +5,7 @@ "@nativescript/core": "file:../../node_modules/@nativescript/core" }, "devDependencies": { - "@nativescript/android": "8.0.0", - "@nativescript/ios": "8.0.0" + "@nativescript/android": "~8.8.0", + "@nativescript/ios": "~8.8.0" } } diff --git a/packages/plugin-tools/src/generators/add-demo/files_vue/tsconfig.json b/packages/plugin-tools/src/generators/add-demo/files_vue/tsconfig.json index e084199..c8c79e3 100644 --- a/packages/plugin-tools/src/generators/add-demo/files_vue/tsconfig.json +++ b/packages/plugin-tools/src/generators/add-demo/files_vue/tsconfig.json @@ -1,21 +1,12 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "rootDirs": [ - ".", - "../.." - ], + "rootDirs": [".", "../.."], "baseUrl": ".", "paths": { - "~/*": [ - "app/*" - ], - "@demo/shared": [ - "../../tools/demo/index.ts" - ], - "<%= npmScope %>/*": [ - "../../packages/*" - ] + "~/*": ["app/*"], + "@demo/shared": ["../../tools/demo/index.ts"], + "<%= npmScope %>/*": ["../../packages/*"] } } } diff --git a/packages/plugin-tools/src/generators/add-demo/files_vue/webpack.config.js b/packages/plugin-tools/src/generators/add-demo/files_vue/webpack.config.js index 9b64d27..dfe6812 100644 --- a/packages/plugin-tools/src/generators/add-demo/files_vue/webpack.config.js +++ b/packages/plugin-tools/src/generators/add-demo/files_vue/webpack.config.js @@ -2,7 +2,6 @@ const webpack = require('@nativescript/webpack'); const { resolve } = require('path'); module.exports = (env) => { - webpack.init(env); webpack.useConfig('vue'); @@ -13,8 +12,8 @@ module.exports = (env) => { // Example of how to share common images across demo apps: // webpack.Utils.addCopyRule({ - // from: '../../../tools/images', - // to: 'images', + // from: '../../../tools/images', + // to: 'images', // context: webpack.Utils.project.getProjectFilePath('node_modules') // }); diff --git a/packages/plugin-tools/src/generators/add-demo/index.ts b/packages/plugin-tools/src/generators/add-demo/index.ts index 459875b..bca6ae6 100644 --- a/packages/plugin-tools/src/generators/add-demo/index.ts +++ b/packages/plugin-tools/src/generators/add-demo/index.ts @@ -1,5 +1,5 @@ -import { addProjectConfiguration, generateFiles, joinPathFragments, readProjectConfiguration, Tree, updateJson, updateProjectConfiguration } from '@nrwl/devkit'; -import { stringUtils, addProjectToNxJsonInTree } from '@nrwl/workspace'; +import { addProjectConfiguration, generateFiles, joinPathFragments, readProjectConfiguration, Tree, updateJson, updateProjectConfiguration } from '@nx/devkit'; +import * as stringUtils from '@nx/devkit/src/utils/string-utils'; import { updateReadMe, prerun, getNpmScope, getSrcFolderForType, SupportedDemoType, getAllPackages } from '../../utils'; import syncPackagesWithDemos from '../sync-packages-with-demos'; import { Schema } from './schema'; @@ -13,7 +13,6 @@ export default async function (tree: Tree, schema: Schema) { } else { prerun(tree); addAppFiles(tree, schema.type); - addProjectToNxJsonInTree(demoName, {}); updateWorkspaceConfig(tree, demoName, schema.type); updateWorkspaceScripts(tree, schema.type); @@ -68,13 +67,15 @@ function updateRootPackageDeps(tree: Tree, type: SupportedDemoType) { devDependencies = { svelte: '~3.35.0', 'svelte-loader-hot': '~0.3.1', - 'svelte-native-preprocessor': '^0.2.0', - 'svelte-native': '~0.9.5', + 'svelte-native-preprocessor': '^1.0.0', + 'svelte-native': '~1.0.0', 'svelte-preprocess': '^4.7.0', }; break; case 'vue': devDependencies = { + 'nativescript-vue-template-compiler': '^2.9.3', + 'nativescript-vue': '^2.9.3', vue: '~2.6.12', }; break; @@ -101,7 +102,7 @@ function updateRootTSConfig(tree: Tree, type: SupportedDemoType) { function updateWorkspaceConfig(tree: Tree, name: string, type: SupportedDemoType) { const srcFolder = getSrcFolderForType(type); - + addProjectConfiguration(tree, name, { root: `apps/${name}/`, projectType: 'application', @@ -116,18 +117,36 @@ function updateWorkspaceConfig(tree: Tree, name: string, type: SupportedDemoType release: true, forDevice: true, }, + dependsOn: [ + { + target: 'build.all', + projects: 'dependencies', + }, + ], }, ios: { executor: '@nativescript/nx:build', options: { platform: 'ios', }, + dependsOn: [ + { + target: 'build.all', + projects: 'dependencies', + }, + ], }, android: { executor: '@nativescript/nx:build', options: { platform: 'android', }, + dependsOn: [ + { + target: 'build.all', + projects: 'dependencies', + }, + ], }, clean: { executor: '@nativescript/nx:build', @@ -135,6 +154,12 @@ function updateWorkspaceConfig(tree: Tree, name: string, type: SupportedDemoType clean: true, }, }, + lint: { + executor: '@nx/eslint:eslint', + options: { + lintFilePatterns: [`apps/${name}/**/*.ts`], + }, + }, }, tags: [], }); diff --git a/packages/plugin-tools/src/generators/add-demo/schema.json b/packages/plugin-tools/src/generators/add-demo/schema.json index 9123ccb..9ff95d4 100644 --- a/packages/plugin-tools/src/generators/add-demo/schema.json +++ b/packages/plugin-tools/src/generators/add-demo/schema.json @@ -1,8 +1,8 @@ { "$schema": "http://json-schema.org/schema", - "cli": "nx", "title": "Add a demo app", - "id": "add-demo", + "$id": "add-demo", + "cli": "nx", "type": "object", "properties": { "type": { @@ -29,4 +29,4 @@ } }, "required": ["type"] -} \ No newline at end of file +} diff --git a/packages/plugin-tools/src/generators/add-package/files/README.md b/packages/plugin-tools/src/generators/add-package/files/README.md index 2f5fa7d..b11fc14 100644 --- a/packages/plugin-tools/src/generators/add-package/files/README.md +++ b/packages/plugin-tools/src/generators/add-package/files/README.md @@ -1,7 +1,7 @@ -# <%= npmScope %>/<%= name %> +# <%= npmPackageName %> ```javascript -ns plugin add <%= npmScope %>/<%= name %> +npm install <%= npmPackageName %> ``` ## Usage diff --git a/packages/plugin-tools/src/generators/add-package/files/__dot__eslintrc.json b/packages/plugin-tools/src/generators/add-package/files/__dot__eslintrc.json new file mode 100644 index 0000000..53c06c8 --- /dev/null +++ b/packages/plugin-tools/src/generators/add-package/files/__dot__eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*", "node_modules/**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/packages/plugin-tools/src/generators/add-package/files/package.json b/packages/plugin-tools/src/generators/add-package/files/package.json index 76d8f62..a8c56c5 100644 --- a/packages/plugin-tools/src/generators/add-package/files/package.json +++ b/packages/plugin-tools/src/generators/add-package/files/package.json @@ -1,35 +1,35 @@ { - "name": "<%= npmScope %>/<%= name %>", - "version": "1.0.0", - "description": "Add a plugin description", - "main": "index", - "typings": "index.d.ts", - "nativescript": { - "platforms": { - "ios": "6.0.0", - "android": "6.0.0" - } - }, - "repository": { - "type": "git", - "url": "https://github.com/NativeScript/plugins.git" - }, - "keywords": [ - "NativeScript", - "JavaScript", - "TypeScript", - "iOS", - "Android" - ], - "author": { - "name": "NativeScript", - "email": "oss@nativescript.org" - }, - "bugs": { - "url": "https://github.com/NativeScript/plugins/issues" - }, - "license": "Apache-2.0", - "homepage": "https://github.com/NativeScript/plugins", - "readmeFilename": "README.md", - "bootstrapper": "@nativescript/plugin-seed" + "name": "<%= npmPackageName %>", + "version": "1.0.0", + "description": "Add a plugin description", + "main": "index", + "types": "index.d.ts", + "nativescript": { + "platforms": { + "ios": "6.0.0", + "android": "6.0.0" + } + }, + "repository": { + "type": "git", + "url": "<%= repo %>.git" + }, + "keywords": [ + "NativeScript", + "JavaScript", + "TypeScript", + "iOS", + "Android" + ], + "author": { + "name": "<%= gitAuthorName %>", + "email": "<%= gitAuthorEmail %>" + }, + "bugs": { + "url": "<%= repo %>/issues" + }, + "license": "Apache-2.0", + "homepage": "<%= repo %>", + "readmeFilename": "README.md", + "bootstrapper": "@nativescript/plugin-seed" } diff --git a/packages/plugin-tools/src/generators/add-package/files/tsconfig.json b/packages/plugin-tools/src/generators/add-package/files/tsconfig.json index a2ef9cc..aed7323 100644 --- a/packages/plugin-tools/src/generators/add-package/files/tsconfig.json +++ b/packages/plugin-tools/src/generators/add-package/files/tsconfig.json @@ -4,6 +4,6 @@ "outDir": "../../dist/out-tsc", "rootDir": "." }, - "exclude": ["**/*.spec.ts", "angular"], + "exclude": ["**/*.spec.ts", "**/*.test.ts", "angular"], "include": ["**/*.ts", "references.d.ts"] } diff --git a/packages/plugin-tools/src/generators/add-package/index.ts b/packages/plugin-tools/src/generators/add-package/index.ts index a116453..25c8892 100644 --- a/packages/plugin-tools/src/generators/add-package/index.ts +++ b/packages/plugin-tools/src/generators/add-package/index.ts @@ -1,18 +1,25 @@ -import { addProjectConfiguration, generateFiles, joinPathFragments, readProjectConfiguration, Tree, updateProjectConfiguration } from '@nrwl/devkit'; -import { stringUtils, addProjectToNxJsonInTree } from '@nrwl/workspace'; +import { addProjectConfiguration, generateFiles, getProjects, joinPathFragments, readJson, readProjectConfiguration, Tree, updateJson, updateProjectConfiguration } from '@nx/devkit'; +import * as stringUtils from '@nx/devkit/src/utils/string-utils'; import { updateReadMe, prerun, getNpmScope } from '../../utils'; import syncPackagesWithDemos from '../sync-packages-with-demos'; import { Schema } from './schema'; let name: string; +let npmPackageName: string; export default async function (tree: Tree, schema: Schema) { name = stringUtils.dasherize(schema.name); prerun(tree); + npmPackageName = schema.isScoped ? `${getNpmScope()}/${name}` : name; addPackageFiles(tree); - addProjectToNxJsonInTree(name, {}); updateWorkspaceConfig(tree); updateWorkspaceScripts(tree); updateReadMe(tree); + updateJson(tree, 'tsconfig.base.json', (json) => { + const packagePath = {}; + packagePath[npmPackageName] = [`packages/${name}/index.d.ts`]; + json.compilerOptions.paths = { ...json.compilerOptions.paths, ...packagePath }; + return json; + }); syncPackagesWithDemos( tree, { @@ -22,11 +29,41 @@ export default async function (tree: Tree, schema: Schema) { true ); - console.log(`"${getNpmScope()}/${name}" created and added to all demo apps. Ready to develop!`); + console.log(`"${npmPackageName}" created and added to all demo apps. Ready to develop!`); } function addPackageFiles(tree: Tree) { - generateFiles(tree, joinPathFragments(__dirname, 'files'), `./packages/${name}`, { name, npmScope: getNpmScope(), stringUtils, tmpl: '', dot: '.' }); + // set default package values + let repo = `https://github.com/NativeScript/plugins`; + let gitAuthorName = `NativeScript`; + let gitAuthorEmail = `oss@nativescript.org`; + // check for custom package settings + const toolsPackageSettingsPath = 'tools/package-settings.json'; + if (tree.exists(toolsPackageSettingsPath)) { + const packageSettings = readJson(tree, toolsPackageSettingsPath); + if (packageSettings) { + if (packageSettings.repository && packageSettings.repository.url) { + repo = packageSettings.repository.url.replace('.git', ''); + } + if (packageSettings.author && packageSettings.author.name) { + gitAuthorName = packageSettings.author.name; + } + if (packageSettings.author && packageSettings.author.email) { + gitAuthorEmail = packageSettings.author.email; + } + } + } + generateFiles(tree, joinPathFragments(__dirname, 'files'), `./packages/${name}`, { + name, + npmPackageName, + npmScope: getNpmScope(), + repo, + gitAuthorName, + gitAuthorEmail, + stringUtils, + tmpl: '', + dot: '.', + }); } function updateWorkspaceConfig(tree: Tree) { @@ -36,7 +73,7 @@ function updateWorkspaceConfig(tree: Tree) { sourceRoot: `packages/${name}`, targets: { build: { - executor: '@nrwl/node:package', + executor: '@nx/js:tsc', options: { outputPath: `dist/packages/${name}`, tsConfig: `packages/${name}/tsconfig.json`, @@ -52,47 +89,48 @@ function updateWorkspaceConfig(tree: Tree) { output: './platforms/', }, ], + dependsOn: [ + { + target: 'build.all', + projects: 'dependencies', + }, + ], }, }, 'build.all': { - executor: '@nrwl/workspace:run-commands', + executor: 'nx:run-commands', options: { - commands: [`nx run ${name}:build`, `node tools/scripts/build-finish.ts ${name}`], + commands: [`node tools/scripts/build-finish.ts ${name}`], parallel: false, }, + outputs: [`{workspaceRoot}/dist/packages/${name}`], + dependsOn: [ + { + target: 'build.all', + projects: 'dependencies', + }, + { + target: 'build', + projects: 'self', + }, + ], }, focus: { - executor: '@nrwl/workspace:run-commands', + executor: 'nx:run-commands', options: { commands: [`nx g @nativescript/plugin-tools:focus-packages ${name}`], parallel: false, }, }, - }, - tags: [] - }); - const allConfig = readProjectConfiguration(tree, 'all'); - if (allConfig) { - let commands = []; - if (allConfig.targets?.build?.options?.commands) { - commands = allConfig.targets.build.options.commands; - commands.push(`nx run ${name}:build.all`); - } - updateProjectConfiguration(tree, 'all', { - ...allConfig, - targets: { - build: { - executor: allConfig.targets.build.executor, - outputs: ['dist/packages'], - options: { - commands, - parallel: false - }, + lint: { + executor: '@nx/eslint:eslint', + options: { + lintFilePatterns: [`packages/${name}/**/*.ts`], }, - focus: allConfig.targets.focus }, - }); - } + }, + tags: [], + }); } function updateWorkspaceScripts(tree: Tree) { @@ -103,11 +141,11 @@ function updateWorkspaceScripts(tree: Tree) { const buildSectionIndex = workspaceScripts.indexOf(`'build-all':`); const buildStart = workspaceScripts.substring(0, buildSectionIndex); const buildEnd = workspaceScripts.substring(buildSectionIndex, workspaceScripts.length); - const newBuild = `// ${getNpmScope()}/${name} + const newBuild = `// ${npmPackageName} '${name}': { build: { script: 'nx run ${name}:build.all', - description: '${getNpmScope()}/${name}: Build', + description: '${npmPackageName}: Build', }, }, `; @@ -119,7 +157,7 @@ function updateWorkspaceScripts(tree: Tree) { const focusEnd = workspaceScripts.substring(focusSectionIndex, workspaceScripts.length); const newFocus = `'${name}': { script: 'nx run ${name}:focus', - description: 'Focus on ${getNpmScope()}/${name}', + description: 'Focus on ${npmPackageName}', }, `; workspaceScripts = `${focusStart}${newFocus} ${focusEnd}`; diff --git a/packages/plugin-tools/src/generators/add-package/schema.d.ts b/packages/plugin-tools/src/generators/add-package/schema.d.ts index 995dbae..e300faa 100644 --- a/packages/plugin-tools/src/generators/add-package/schema.d.ts +++ b/packages/plugin-tools/src/generators/add-package/schema.d.ts @@ -1,3 +1,4 @@ export interface Schema { name: string; + isScoped?: boolean; } diff --git a/packages/plugin-tools/src/generators/add-package/schema.json b/packages/plugin-tools/src/generators/add-package/schema.json index 78bc8e0..37938ca 100644 --- a/packages/plugin-tools/src/generators/add-package/schema.json +++ b/packages/plugin-tools/src/generators/add-package/schema.json @@ -1,8 +1,8 @@ { "$schema": "http://json-schema.org/schema", - "cli": "nx", "title": "Add a package", - "id": "add-package", + "$id": "add-package", + "cli": "nx", "type": "object", "properties": { "name": { @@ -13,7 +13,13 @@ "index": 0 }, "x-prompt": "What should the new package be named?" + }, + "isScoped": { + "type": "boolean", + "default": true, + "description": "Whether the new package should be scoped to the npm scope of the workspace or not.", + "x-prompt": "Should it use the npm scope of the workspace? 'Y' is the most common. This is the difference between, for example @nativescript/camera vs. nativescript-camera. If you choose 'N' here, be sure you have specified the full npm name you would like to use during publishing." } }, "required": ["name"] -} \ No newline at end of file +} diff --git a/packages/plugin-tools/src/generators/bump-packages/generator.spec.ts b/packages/plugin-tools/src/generators/bump-packages/generator.spec.ts new file mode 100644 index 0000000..420aeac --- /dev/null +++ b/packages/plugin-tools/src/generators/bump-packages/generator.spec.ts @@ -0,0 +1,71 @@ +import { Tree, addProjectConfiguration } from '@nx/devkit'; +import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; + +import generator from './generator'; + +describe('bump-packages generator', () => { + let appTree: Tree; + + beforeEach(() => { + appTree = createTreeWithEmptyWorkspace(); + appTree.write('apps/app/package.json', JSON.stringify({ version: '1.0.0' })); + appTree.write('packages/lib/package.json', JSON.stringify({ version: '1.0.0' })); + appTree.write('packages/lib2/package.json', JSON.stringify({ version: '2.0.0' })); + addProjectConfiguration(appTree, 'app', { + root: 'apps/app', + projectType: 'application', + tags: ['tag1', 'tag2'], + }); + addProjectConfiguration(appTree, 'lib', { + root: 'packages/lib', + projectType: 'library', + tags: ['tag2'], + }); + addProjectConfiguration(appTree, 'lib2', { + root: 'packages/lib2', + projectType: 'library', + tags: ['tag1'], + }); + }); + + it('should bump all by patch', async () => { + await generator(appTree, { + targetVersion: 'patch', + }); + expect(JSON.parse(appTree.read('apps/app/package.json').toString()).version).toBe('1.0.1'); + expect(JSON.parse(appTree.read('packages/lib/package.json').toString()).version).toBe('1.0.1'); + expect(JSON.parse(appTree.read('packages/lib2/package.json').toString()).version).toBe('2.0.1'); + }); + + it('should filter by type', async () => { + await generator(appTree, { + targetVersion: 'patch', + projectType: 'library', + }); + expect(JSON.parse(appTree.read('apps/app/package.json').toString()).version).toBe('1.0.0'); + expect(JSON.parse(appTree.read('packages/lib/package.json').toString()).version).toBe('1.0.1'); + expect(JSON.parse(appTree.read('packages/lib2/package.json').toString()).version).toBe('2.0.1'); + }); + it('should filter by tag', async () => { + await generator(appTree, { + targetVersion: 'patch', + tags: 'tag2', + }); + expect(JSON.parse(appTree.read('apps/app/package.json').toString()).version).toBe('1.0.1'); + expect(JSON.parse(appTree.read('packages/lib/package.json').toString()).version).toBe('1.0.1'); + expect(JSON.parse(appTree.read('packages/lib2/package.json').toString()).version).toBe('2.0.0'); + }); + + it('should fail to set non-semver', async () => { + const gen = await generator(appTree, { + targetVersion: 'not-semver', + }).catch(() => 'failed'); + expect(gen).toBe('failed'); + }); + it('should fail to set version lower than the existing version', async () => { + const gen = await generator(appTree, { + targetVersion: '1.0.1', + }).catch(() => 'failed'); + expect(gen).toBe('failed'); + }); +}); diff --git a/packages/plugin-tools/src/generators/bump-packages/generator.ts b/packages/plugin-tools/src/generators/bump-packages/generator.ts new file mode 100644 index 0000000..7117ac8 --- /dev/null +++ b/packages/plugin-tools/src/generators/bump-packages/generator.ts @@ -0,0 +1,72 @@ +import { ProjectConfiguration, Tree, formatFiles, getProjects, logger } from '@nx/devkit'; +import * as semver from 'semver'; +import { BumpPackagesGeneratorSchema } from './schema'; + +interface NormalizedSchema extends BumpPackagesGeneratorSchema { + projects: ProjectConfiguration[]; + versionBump: semver.ReleaseType | false; + fixedVersion: string; +} + +function isVersionBump(version: string): version is semver.ReleaseType { + return ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'].includes(version); +} + +function normalizeOptions(tree: Tree, options: BumpPackagesGeneratorSchema): NormalizedSchema { + const filters = { + projectType: options.projectType ?? '', + tags: options.tags?.split(',').map((s) => s.trim()), + }; + console.log(filters); + const projects = options.projectName + ? [getProjects(tree).get(options.projectName)] + : Array.from(getProjects(tree).values()).filter((v) => { + if (filters.projectType) { + if (v.projectType !== filters.projectType) { + return false; + } + } + if (filters.tags) { + if (!v.tags.some((t) => filters.tags.includes(t))) { + return false; + } + } + return true; + }); + + const versionBump = isVersionBump(options.targetVersion) ? options.targetVersion : false; + if (!versionBump) { + if (!semver.parse(options.targetVersion)) { + throw new Error(`Invalid version ${options.targetVersion}`); + } + } + + return { + ...options, + projects, + versionBump, + fixedVersion: versionBump ? '' : options.targetVersion, + }; +} + +export default async function (tree: Tree, options: BumpPackagesGeneratorSchema) { + const normalizedOptions = normalizeOptions(tree, options); + normalizedOptions.projects.forEach((project) => { + const packageJson = tree.read(`${project.root}/package.json`); + if (!packageJson) { + throw new Error(`Could not find package.json for project ${project.name}`); + } + const parsedPackageJson = JSON.parse(packageJson.toString()); + const oldVersion = parsedPackageJson.version; + const newVersion = normalizedOptions.versionBump ? semver.inc(parsedPackageJson.version, normalizedOptions.versionBump) : normalizedOptions.fixedVersion; + if (!newVersion) { + throw new Error(`Could not bump version for project ${project.name}`); + } + if (semver.gte(oldVersion, newVersion)) { + throw new Error(`New version (${newVersion}) is not greater than old version (${oldVersion}) for project ${project.name}, Skipping project`); + } + parsedPackageJson.version = newVersion; + tree.write(`${project.root}/package.json`, JSON.stringify(parsedPackageJson, null, 2)); + }); + await formatFiles(tree); +} diff --git a/packages/plugin-tools/src/generators/bump-packages/schema.d.ts b/packages/plugin-tools/src/generators/bump-packages/schema.d.ts new file mode 100644 index 0000000..3331053 --- /dev/null +++ b/packages/plugin-tools/src/generators/bump-packages/schema.d.ts @@ -0,0 +1,6 @@ +export interface BumpPackagesGeneratorSchema { + targetVersion: string; + projectName?: string; + tags?: string; + projectType?: string; +} diff --git a/packages/plugin-tools/src/generators/bump-packages/schema.json b/packages/plugin-tools/src/generators/bump-packages/schema.json new file mode 100644 index 0000000..66e1f82 --- /dev/null +++ b/packages/plugin-tools/src/generators/bump-packages/schema.json @@ -0,0 +1,44 @@ +{ + "$schema": "http://json-schema.org/schema", + "$id": "BumpPackages", + "cli": "nx", + "title": "Bump Packages", + "type": "object", + "properties": { + "targetVersion": { + "x-prompt": "What's the new version (patch, minor, major) or explicit version number?.", + "type": "string", + "description": "Desired version to bump (patch, minor, major), or explicit version number (must comply with semver)", + "default": "patch", + "$default": { + "$source": "argv", + "index": 0 + }, + "anyOf": [ + { + "enum": ["major", "premajor", "minor", "preminor", "patch", "prepatch", "prerelease"] + }, + { + "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$" + } + ], + "x-priority": "important" + }, + "projectName": { + "description": "Project to bump. If unspecified all projects are bumped", + "type": "string", + "x-dropdown": "projects" + }, + "tags": { + "type": "string", + "description": "Filter projects by tags (comma separated)", + "alias": "t" + }, + "projectType": { + "type": "string", + "enum": ["application", "library"], + "default": "library" + } + }, + "required": ["targetVersion"] +} diff --git a/packages/plugin-tools/src/generators/config/index.ts b/packages/plugin-tools/src/generators/config/index.ts index 8968faa..2e6493b 100644 --- a/packages/plugin-tools/src/generators/config/index.ts +++ b/packages/plugin-tools/src/generators/config/index.ts @@ -1,24 +1,80 @@ import { getJsonFromFile } from '../../utils'; import { Schema } from './schema'; -import { stringUtils, serializeJson } from '@nrwl/workspace'; -import { Tree } from '@nrwl/devkit'; +import * as stringUtils from '@nx/devkit/src/utils/string-utils'; +import { serializeJson, Tree, updateJson, writeJson } from '@nx/devkit'; let customNpmScope: string; +let gitRepo = 'https://github.com/NativeScript/plugins'; +let gitAuthorName = 'NativeScript'; +let gitAuthorEmail = 'oss@nativescript.org'; export default async function (tree: Tree, schema: Schema) { customNpmScope = stringUtils.dasherize(schema.scope); + if (customNpmScope.indexOf('@') === -1) { + customNpmScope = `@${customNpmScope}`; + } + if (schema.repo) { + const repo = schema.repo.replace('.git', ''); + gitRepo = repo.trim(); + } + if (schema.gitAuthorName) { + gitAuthorName = schema.gitAuthorName.trim(); + } + if (schema.gitAuthorEmail) { + gitAuthorEmail = schema.gitAuthorEmail.trim(); + } + + // package.json settings that apply to all new packages added to workspace + const toolsPackageSettingsPath = 'tools/package-settings.json'; + const packageSettings = { + name: customNpmScope, + repository: { + type: 'git', + url: `${gitRepo}.git`, + }, + keywords: ['NativeScript', 'JavaScript', 'TypeScript', 'iOS', 'Android'], + author: { + name: gitAuthorName, + email: gitAuthorEmail, + }, + bugs: { + url: `${gitRepo}/issues`, + }, + license: 'Apache-2.0', + homepage: gitRepo, + }; + if (!tree.exists(toolsPackageSettingsPath)) { + writeJson(tree, toolsPackageSettingsPath, packageSettings); + } else { + updateJson(tree, toolsPackageSettingsPath, (json) => { + if (!json.name) { + json.name = packageSettings.name; + } + if (!json.repository) { + json.repository = { + type: 'git', + }; + } + json.repository.url = packageSettings.repository.url; + if (!json.author) { + json.author = {}; + } + json.author.name = packageSettings.author.name; + json.author.email = packageSettings.author.email; + if (!json.bugs) { + json.bugs = {}; + } + json.bugs.url = packageSettings.bugs.url; + json.homepage = packageSettings.homepage; - const nxConfigPath = `nx.json`; - const nxConfig = getJsonFromFile(tree, nxConfigPath); - if (nxConfig && nxConfig.npmScope) { - nxConfig.npmScope = customNpmScope; - tree.write(nxConfigPath, serializeJson(nxConfig)); + return json; + }); } const tsconfigBasePath = `tsconfig.base.json`; const tsconfigBase = getJsonFromFile(tree, tsconfigBasePath); if (tsconfigBase && tsconfigBase.compilerOptions && tsconfigBase.compilerOptions.paths) { delete tsconfigBase.compilerOptions.paths[`@nativescript/*`]; - tsconfigBase.compilerOptions.paths[`@${customNpmScope}/*`] = ['packages/*']; + tsconfigBase.compilerOptions.paths[`${customNpmScope}/*`] = ['packages/*']; tree.write(tsconfigBasePath, serializeJson(tsconfigBase)); } @@ -32,7 +88,7 @@ export default async function (tree: Tree, schema: Schema) { if (demoTsConfig && demoTsConfig.compilerOptions && demoTsConfig.compilerOptions.paths) { delete demoTsConfig.compilerOptions.paths[`@nativescript/*`]; - demoTsConfig.compilerOptions.paths[`@${customNpmScope}/*`] = [`../../${dir.indexOf('angular') > -1 ? 'dist/' : ''}packages/*`]; + demoTsConfig.compilerOptions.paths[`${customNpmScope}/*`] = [`../../${dir.indexOf('angular') > -1 ? 'dist/' : ''}packages/*`]; tree.write(demoTsConfigPath, serializeJson(demoTsConfig)); } } @@ -40,13 +96,14 @@ export default async function (tree: Tree, schema: Schema) { const travisPath = `.travis.yml`; let travisContent = tree.read(travisPath).toString('utf-8'); - travisContent = travisContent.replace(/@nativescript/gm, `@${customNpmScope}`); + travisContent = travisContent.replace(/@nativescript/gm, `${customNpmScope}`); // context.logger.info('travisContent:' + travisContent); tree.write(travisPath, travisContent); const workspaceScriptsPath = `tools/workspace-scripts.js`; let workspaceScripts = tree.read(workspaceScriptsPath).toString('utf-8'); - workspaceScripts = workspaceScripts.replace(/@nativescript/gm, `@${customNpmScope}`); + workspaceScripts = workspaceScripts.replace(/@nativescript/gm, `${customNpmScope}`) + .replace(new RegExp(`${customNpmScope}/plugin-tools:`, 'gm'), `@nativescript/plugin-tools:`); // context.logger.info(travisContent); tree.write(workspaceScriptsPath, workspaceScripts); @@ -54,7 +111,7 @@ export default async function (tree: Tree, schema: Schema) { let sharedDemoTsConfig = getJsonFromFile(tree, sharedDemoTsConfigPath); if (sharedDemoTsConfig && sharedDemoTsConfig.compilerOptions && sharedDemoTsConfig.compilerOptions.paths) { delete sharedDemoTsConfig.compilerOptions.paths[`@nativescript/*`]; - sharedDemoTsConfig.compilerOptions.paths[`@${customNpmScope}/*`] = [`../../packages/*`]; + sharedDemoTsConfig.compilerOptions.paths[`${customNpmScope}/*`] = [`../../packages/*`]; tree.write(sharedDemoTsConfigPath, serializeJson(sharedDemoTsConfig)); } @@ -67,9 +124,9 @@ export default async function (tree: Tree, schema: Schema) { readme = readme.substring(headingIndex, readme.length); } } - readme = readme.replace(/@nativescript/gm, `@${customNpmScope}`); + readme = readme.replace(/@nativescript/gm, `${customNpmScope}`); // context.logger.info(travisContent); tree.write(readmePath, readme); - console.log(`Workspace has been configured for npm scope: @${customNpmScope}\n\n`); + console.log(`Workspace has been configured for npm scope: ${customNpmScope}\n\n`); } diff --git a/packages/plugin-tools/src/generators/config/schema.d.ts b/packages/plugin-tools/src/generators/config/schema.d.ts index 2f77f2b..c915c97 100644 --- a/packages/plugin-tools/src/generators/config/schema.d.ts +++ b/packages/plugin-tools/src/generators/config/schema.d.ts @@ -3,4 +3,7 @@ export interface Schema { * The npm scope */ scope?: string; + repo?: string; + gitAuthorName?: string; + gitAuthorEmail?: string; } diff --git a/packages/plugin-tools/src/generators/config/schema.json b/packages/plugin-tools/src/generators/config/schema.json index 6734e24..a334dcb 100644 --- a/packages/plugin-tools/src/generators/config/schema.json +++ b/packages/plugin-tools/src/generators/config/schema.json @@ -1,18 +1,34 @@ { "$schema": "http://json-schema.org/schema", + "$id": "config", "cli": "nx", - "id": "config", "title": "Configure workspace", "type": "object", "properties": { "scope": { "type": "string", - "description": "npm scope to use for the workspace packages.", + "description": "npm scope to use for the workspace packages", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What npm scope would you like to use for this workspace?" + "x-prompt": "What npm scope would you like to use for this workspace? This will become the default npm scope of the workspace however you can add packages that are non-scoped at anytime via 'npm run add'" + }, + "repo": { + "type": "string", + "description": "Repository location", + "x-prompt": "What is the git repository adress where this workspace will be located remotely? If left unanswered, all plugin packages will default to https://github.com/NativeScript/plugins which you can manually change later. Answering now will ensure all plugins reference the proper git repository url." + }, + "gitAuthorName": { + "type": "string", + "description": "Author display name", + "x-prompt": "What is the author display name? This will set the default package.json author.name field when adding new packages to the workspace." + }, + "gitAuthorEmail": { + "type": "string", + "description": "Author email", + "x-prompt": "What is the author email? This will set the default package.json author.email field when adding new package to the workspace." } - } + }, + "required": ["scope"] } diff --git a/packages/plugin-tools/src/generators/focus-packages/index.ts b/packages/plugin-tools/src/generators/focus-packages/index.ts index a1715b0..477aa20 100644 --- a/packages/plugin-tools/src/generators/focus-packages/index.ts +++ b/packages/plugin-tools/src/generators/focus-packages/index.ts @@ -1,7 +1,7 @@ -import { sanitizeCollectionArgs, getDemoTypeFromName, updateDemoDependencies, setPackageNamesToUpdate, getAllPackages, resetIndexForDemoType, getPluginDemoPath, updateDemoSharedIndex, getNpmScope, prerun } from '../../utils'; +import { sanitizeCollectionArgs, getDemoTypeFromName, updateDemoDependencies, setPackageNamesToUpdate, getAllPackages, resetIndexForDemoType, getPluginDemoPath, updateDemoSharedIndex, getNpmScope, prerun, getNpmPackageNames, getSrcFolderForType } from '../../utils'; import { Schema } from './schema'; -import { wrapAngularDevkitSchematic } from '@nrwl/devkit/ngcli-adapter'; -import { Tree } from '@nrwl/devkit'; +import { wrapAngularDevkitSchematic } from '@nx/devkit/ngcli-adapter'; +import { Tree } from '@nx/devkit'; let focusPackages: Array; let allPackages: Array; @@ -14,22 +14,22 @@ export default async function (tree: Tree, schema: Schema) { await nstudioFocus(tree, { name: schema.name, }); + setPackageNamesToUpdate(focusPackages); + allPackages = getAllPackages(tree); + const npmPackageNames = getNpmPackageNames(); + // console.log('allPackages:', allPackages); // Isolate code in demo apps by default based on focus if (!schema.ignoreDemos) { - setPackageNamesToUpdate(focusPackages); - allPackages = getAllPackages(tree); - // console.log('allPackages:', allPackages); - // adjust demo shared index for focusing updateDemoSharedIndex(tree, allPackages, focusPackages); // apps - const appFolders = tree.children('apps'); for (const dir of appFolders) { // console.log(`demoAppRoot: ${demoAppRoot}`); const demoType = getDemoTypeFromName(dir); const demoViewsPath = `apps/${dir}/${getPluginDemoPath(demoType)}`; + const demoModalViewsPath = `apps/${dir}/${getSrcFolderForType(demoType)}/modals`; const demoAppRoot = `apps/${dir}`; // console.log(`demoType: ${demoType}`); updateDemoDependencies(tree, demoType, demoAppRoot, allPackages, true); @@ -66,13 +66,38 @@ export default async function (tree: Tree, schema: Schema) { } } + const allModals = tree.children(demoModalViewsPath); + for (const filename of allModals) { + switch (demoType) { + case 'xml': + const currentFilename = `${demoModalViewsPath}/${filename}`; + let origFilename = currentFilename; + if (currentFilename.indexOf('_off') > -1) { + origFilename = currentFilename.split('_off')[0]; + } + const relatedToFocusedPackage = focusPackages.find((p) => { + return origFilename.indexOf(p) > -1; + }); + if (focusPackages.length === 0 || relatedToFocusedPackage) { + if (tree.exists(`${origFilename}_off`)) { + tree.rename(`${origFilename}_off`, origFilename); + } + } else { + if (tree.exists(origFilename)) { + tree.rename(origFilename, `${origFilename}_off`); + } + } + break; + } + } + // cleanup index listing to only have buttons for what is being focused on resetIndexForDemoType(tree, demoType); } } const isFocusing = focusPackages && focusPackages.length > 0; - const focusTargets = (focusPackages && focusPackages.length ? focusPackages : allPackages).map((n) => `\n${getNpmScope()}/${n}`).join(''); + const focusTargets = (focusPackages && focusPackages.length ? focusPackages : allPackages).map((n) => `\n${npmPackageNames[n]}`).join(''); console.log(`${isFocusing ? 'Focusing workspace on:' : 'Resetting workspace for:'}\n${focusTargets}\n\n`); if (!schema.ignoreDemos) { console.log(` > NOTE: Clean the demo app you plan to test with before running now that the demo code has been updated.\n`); diff --git a/packages/plugin-tools/src/generators/focus-packages/schema.json b/packages/plugin-tools/src/generators/focus-packages/schema.json index b7cc7b9..8e9ea3d 100644 --- a/packages/plugin-tools/src/generators/focus-packages/schema.json +++ b/packages/plugin-tools/src/generators/focus-packages/schema.json @@ -1,7 +1,7 @@ { "$schema": "http://json-schema.org/schema", + "$id": "focus-packages", "cli": "nx", - "id": "focus-packages", "title": "Focus the workspace", "type": "object", "properties": { diff --git a/packages/plugin-tools/src/generators/publish/index.ts b/packages/plugin-tools/src/generators/publish/index.ts index 254634c..4bee1c0 100644 --- a/packages/plugin-tools/src/generators/publish/index.ts +++ b/packages/plugin-tools/src/generators/publish/index.ts @@ -1,12 +1,11 @@ import { sanitizeCollectionArgs, setPackageNamesToUpdate, getAllPackages, getNpmScope, prerun, jsonParse } from '../../utils'; import { Schema } from './schema'; import parseVersionString from 'parse-version-string'; -import { serializeJson } from '@nrwl/workspace'; import { Observable } from 'rxjs'; import { spawn } from 'child_process'; import * as path from 'path'; -import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs'; -import { Tree } from '@nrwl/devkit'; +import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'fs'; +import { Tree, serializeJson } from '@nx/devkit'; interface ISemVer { major: number; @@ -89,6 +88,25 @@ export default async function (tree: Tree, schema: Schema) { await new Promise((resolve, reject) => { // console.log(options.args); let cnt = 0; + const cleanPackage = () => { + // helps remove unwanted properties which may be added by other tooling + const p = publishPackages[cnt]; + const packageJsonPath = path.resolve(workspaceDir, 'dist', 'packages', p, 'package.json'); + let packageJson: any = readFileSync(packageJsonPath, { encoding: 'utf-8' }); + if (packageJson) { + packageJson = jsonParse(packageJson); + // we don't need module or type properties at the moment + delete packageJson['module']; + delete packageJson['type']; + writeFileSync(packageJsonPath, serializeJson(packageJson)); + + const angularNpmIgnorePath = path.resolve(workspaceDir, 'dist', 'packages', p, 'angular', '.npmignore'); + // remove .npmignore as we don't need it in angular folder if found + if (existsSync(angularNpmIgnorePath)) { + unlinkSync(angularNpmIgnorePath); + } + } + }; const buildPackage = () => { const p = publishPackages[cnt]; @@ -106,6 +124,8 @@ export default async function (tree: Tree, schema: Schema) { child.on('close', (res) => { console.log('build finished with code:', res); child.kill(); + // cleanup anything with the package not needed + cleanPackage(); cnt++; if (cnt === publishPackages.length) { console.log(`✅ Successfully built ${packageVersions.map((p) => `${p.name}:${p.version}`).join(',')}`); diff --git a/packages/plugin-tools/src/generators/publish/schema.json b/packages/plugin-tools/src/generators/publish/schema.json index b62cf2d..bcc3940 100644 --- a/packages/plugin-tools/src/generators/publish/schema.json +++ b/packages/plugin-tools/src/generators/publish/schema.json @@ -1,7 +1,7 @@ { "$schema": "http://json-schema.org/schema", + "$id": "publish", "cli": "nx", - "id": "publish", "title": "Publish packages", "type": "object", "properties": { diff --git a/packages/plugin-tools/src/generators/remove-package/index.ts b/packages/plugin-tools/src/generators/remove-package/index.ts index 028fa0d..31e5e17 100644 --- a/packages/plugin-tools/src/generators/remove-package/index.ts +++ b/packages/plugin-tools/src/generators/remove-package/index.ts @@ -1,31 +1,40 @@ -import { Tree, removeProjectConfiguration, updateJson, readProjectConfiguration, updateProjectConfiguration } from '@nrwl/devkit'; -import { stringUtils } from '@nrwl/workspace'; -import { prerun, getNpmScope, getDemoTypes, getDemoAppRoot, getPluginDemoPath, SupportedDemoType, checkPackages, getDemoIndexPathForType, getPackageNamesToUpdate, getPathToPackageForDemo, updateReadMe } from '../../utils'; +import { Tree, removeProjectConfiguration, updateJson, readProjectConfiguration, updateProjectConfiguration, readJson } from '@nx/devkit'; +import * as stringUtils from '@nx/devkit/src/utils/string-utils'; +import { prerun, getNpmScope, getDemoTypes, getDemoAppRoot, getPluginDemoPath, SupportedDemoType, checkPackages, getDemoIndexPathForType, getPackageNamesToUpdate, getPathToPackageForDemo, updateReadMe, getNpmPackageNames } from '../../utils'; import { Schema } from './schema'; let name: string; +let npmPackageName: string; export default function (tree: Tree, schema: Schema) { name = stringUtils.dasherize(schema.name); prerun(tree); - removePackage(tree); - - removeProjectConfiguration(tree, name); - removeFromBuildAll(tree); + const packagePath = `packages/${name}/package.json`; + if (tree.exists(packagePath)) { + const packageJson = readJson(tree, packagePath); + npmPackageName = packageJson.name; + removePackage(tree); + + removeProjectConfiguration(tree, name); + + updateReadMe(tree, getUpdatedPackages(tree)); + + for (const t of getDemoTypes()) { + const demoAppRoot = getDemoAppRoot(t); + if (tree.exists(`${demoAppRoot}/package.json`)) { + removeDemoFiles(tree, t, demoAppRoot); + removeFromDemoIndex(tree, t, demoAppRoot); + updateDemoDependencies(tree, demoAppRoot); + } + } - updateReadMe(tree, getUpdatedPackages(tree)); + removeSharedDemoFiles(tree); + updateDemoSharedIndex(tree); - for (const t of getDemoTypes()) { - const demoAppRoot = getDemoAppRoot(t); - removeDemoFiles(tree, t, demoAppRoot); - removeFromDemoIndex(tree, t, demoAppRoot); - updateDemoDependencies(tree, demoAppRoot); + console.log(`"${npmPackageName}" removed from 'packages' and removed from all demo apps.`); + } else { + console.error(`Nothing found at 'packages/${name}/package.json' to remove.`); } - - removeSharedDemoFiles(tree); - updateDemoSharedIndex(tree); - - console.log(`"${getNpmScope()}/${name}" removed from 'packages' and removed from all demo apps.`); } function removePackage(tree: Tree) { @@ -34,33 +43,6 @@ function removePackage(tree: Tree) { tree.delete(`packages/${name}`); } -function removeFromBuildAll(tree: Tree) { - const allConfig = readProjectConfiguration(tree, 'all'); - if (allConfig) { - let commands = []; - if (allConfig.targets?.build?.options?.commands) { - commands = allConfig.targets.build.options.commands; - const index = commands.indexOf(`nx run ${name}:build.all`); - if (index > -1) { - commands.splice(index, 1); - } - } - updateProjectConfiguration(tree, 'all', { - ...allConfig, - targets: { - build: { - executor: allConfig.targets.build.executor, - outputs: ['dist/packages'], - options: { - commands, - parallel: false, - }, - }, - focus: allConfig.targets.focus, - }, - }); - } -} function removeDemoFiles(tree: Tree, type: SupportedDemoType, demoAppRoot: string) { const demoAppFolder = `${demoAppRoot}/${getPluginDemoPath(type)}`; console.log(`Removing demo files in "${demoAppFolder}"`); @@ -112,14 +94,14 @@ function removeFromDemoIndex(tree: Tree, type: SupportedDemoType, demoAppRoot: s resetAngularIndex(tree); resetAngularRoutes(tree); return tree; - } else if (['react', 'svelte', 'vue']) { + } else if (['react', 'svelte', 'vue'].includes(type)) { // TODO: add index page for these flavors return tree; } const demoIndexViewPath = `${demoAppRoot}/${getDemoIndexPathForType(type)}`; let indexViewContent = tree.read(demoIndexViewPath).toString('utf-8'); - indexViewContent = indexViewContent.replace(` - - + + + + + diff --git a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_angular/__name__.component.ts__tmpl__ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_angular/__name__.component.ts__tmpl__ index e657dd8..535f789 100644 --- a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_angular/__name__.component.ts__tmpl__ +++ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_angular/__name__.component.ts__tmpl__ @@ -1,6 +1,6 @@ import { Component, NgZone } from '@angular/core'; import { DemoShared<%= stringUtils.classify(name) %> } from '@demo/shared'; -import { } from '<%= npmScope %>/<%= name %>'; +import { } from '<%= npmPackageName %>'; @Component({ selector: 'demo-<%= name %>', diff --git a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_demo_shared/__name__/index.ts__tmpl__ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_demo_shared/__name__/index.ts__tmpl__ index 9182852..a5f71ea 100644 --- a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_demo_shared/__name__/index.ts__tmpl__ +++ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_demo_shared/__name__/index.ts__tmpl__ @@ -1,5 +1,5 @@ import { DemoSharedBase } from '../utils'; -import { } from '<%= npmScope %>/<%= name %>'; +import { } from '<%= npmPackageName %>'; export class DemoShared<%= stringUtils.classify(name) %> extends DemoSharedBase { diff --git a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_react/__name__.tsx__tmpl__ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_react/__name__.tsx__tmpl__ index 1cc9ad9..b6ee9c3 100644 --- a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_react/__name__.tsx__tmpl__ +++ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_react/__name__.tsx__tmpl__ @@ -2,7 +2,7 @@ import * as React from "react"; import { Dialogs } from '@nativescript/core'; import { StyleSheet } from "react-nativescript"; import { DemoShared<%= stringUtils.classify(name) %> } from '@demo/shared'; -import { } from '<%= npmScope %>/<%= name %>'; +import { } from '<%= npmPackageName %>'; export function HomeScreen() { return ( diff --git a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_svelte/__name__.svelte__tmpl__ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_svelte/__name__.svelte__tmpl__ index 440c11b..9ddfa5b 100644 --- a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_svelte/__name__.svelte__tmpl__ +++ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_svelte/__name__.svelte__tmpl__ @@ -7,7 +7,7 @@ diff --git a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_vue/__name__.vue__tmpl__ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_vue/__name__.vue__tmpl__ index 50e934b..4a83e26 100644 --- a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_vue/__name__.vue__tmpl__ +++ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_vue/__name__.vue__tmpl__ @@ -13,7 +13,7 @@