From 0e94d8e0b9b515c4f1a81921ccdee224b8c4f77a Mon Sep 17 00:00:00 2001 From: Edouard Bozon Date: Wed, 9 Oct 2024 12:30:16 +0200 Subject: [PATCH 1/3] chore(release): include common pkg --- nx.json | 2 +- tools/scripts/start-local-registry.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nx.json b/nx.json index 6ab06178..afc87d03 100644 --- a/nx.json +++ b/nx.json @@ -113,7 +113,7 @@ } }, "release": { - "projects": ["packages/*", "!common"], + "projects": ["packages/*"], "projectsRelationship": "independent", "version": { "conventionalCommits": true, diff --git a/tools/scripts/start-local-registry.ts b/tools/scripts/start-local-registry.ts index b5f04a58..d8271531 100644 --- a/tools/scripts/start-local-registry.ts +++ b/tools/scripts/start-local-registry.ts @@ -37,7 +37,7 @@ export default async () => { '-t', 'build', '--exclude', - 'docs,common', + 'docs' ]); await releasePublish({ From 8fae4898df4975fb3f32a5a0da5437993b3f8b56 Mon Sep 17 00:00:00 2001 From: Edouard Bozon Date: Wed, 9 Oct 2024 12:30:31 +0200 Subject: [PATCH 2/3] feat(capacitor): add inference plugin --- packages/capacitor/package.json | 3 +- .../configuration/generator.spec.ts | 81 +------------------ .../src/generators/configuration/generator.ts | 4 +- packages/capacitor/src/index.ts | 1 + packages/capacitor/src/plugins/plugin.ts | 41 ++++++++++ 5 files changed, 50 insertions(+), 80 deletions(-) create mode 100644 packages/capacitor/src/plugins/plugin.ts diff --git a/packages/capacitor/package.json b/packages/capacitor/package.json index eb765992..9f8a3652 100644 --- a/packages/capacitor/package.json +++ b/packages/capacitor/package.json @@ -19,7 +19,8 @@ "builders": "./executors.json", "dependencies": { "ignore": "^5.3.1", - "tslib": "^2.3.0" + "tslib": "^2.3.0", + "@nxext/common": "^19.0.0" }, "peerDependencies": { "@nx/devkit": "^19.0.0", diff --git a/packages/capacitor/src/generators/configuration/generator.spec.ts b/packages/capacitor/src/generators/configuration/generator.spec.ts index 1b39c676..5b127d5b 100644 --- a/packages/capacitor/src/generators/configuration/generator.spec.ts +++ b/packages/capacitor/src/generators/configuration/generator.spec.ts @@ -2,6 +2,7 @@ import { addProjectConfiguration, normalizePath, readJson, + readNxJson, readProjectConfiguration, Tree, writeJson, @@ -90,84 +91,10 @@ describe('capacitor-project', () => { ); }); - it('should update workspace.json', async () => { + it('should update nx.json', async () => { await generator(appTree, options); - const projectConfiguration = readProjectConfiguration( - appTree, - options.project - ); - - expect(projectConfiguration.targets.cap.executor).toEqual( - '@nxext/capacitor:cap' - ); - expect(projectConfiguration.targets.cap.options).toEqual({ - cmd: '--help', - }); - - expect(projectConfiguration.targets.add.executor).toEqual( - '@nxext/capacitor:cap' - ); - expect(projectConfiguration.targets.add.options).toEqual({ - cmd: 'add', - }); - expect( - projectConfiguration.targets.add.configurations['ios'].cmd - ).toEqual('add ios'); - expect( - projectConfiguration.targets.add.configurations['android'].cmd - ).toEqual('add android'); - - expect(projectConfiguration.targets.copy.executor).toEqual( - '@nxext/capacitor:cap' - ); - expect(projectConfiguration.targets.copy.options).toEqual({ - cmd: 'copy', - }); - expect( - projectConfiguration.targets.copy.configurations['ios'].cmd - ).toEqual('copy ios'); - expect( - projectConfiguration.targets.copy.configurations['android'].cmd - ).toEqual('copy android'); - - expect(projectConfiguration.targets.open.executor).toEqual( - '@nxext/capacitor:cap' - ); - expect(projectConfiguration.targets.open.options).toEqual({ - cmd: 'open', - }); - expect( - projectConfiguration.targets.open.configurations['ios'].cmd - ).toEqual('open ios'); - expect( - projectConfiguration.targets.open.configurations['android'].cmd - ).toEqual('open android'); - - expect(projectConfiguration.targets.sync.executor).toEqual( - '@nxext/capacitor:cap' - ); - expect(projectConfiguration.targets.sync.options).toEqual({ - cmd: 'sync', - }); - expect( - projectConfiguration.targets.sync.configurations['ios'].cmd - ).toEqual('sync ios'); - expect( - projectConfiguration.targets.sync.configurations['android'].cmd - ).toEqual('sync android'); - - expect(projectConfiguration.targets.update.executor).toEqual( - '@nxext/capacitor:cap' - ); - expect(projectConfiguration.targets.update.options).toEqual({ - cmd: 'update', - }); - expect( - projectConfiguration.targets.update.configurations['ios'].cmd - ).toEqual('update ios'); - expect( - projectConfiguration.targets.update.configurations['android'].cmd - ).toEqual('update android'); + const nxJson = readNxJson(appTree); + expect(nxJson.plugins).toContain('@nxext/capacitor'); }); it('should not remove existing target configurations', async () => { diff --git a/packages/capacitor/src/generators/configuration/generator.ts b/packages/capacitor/src/generators/configuration/generator.ts index a0dbe57f..fd52dccd 100644 --- a/packages/capacitor/src/generators/configuration/generator.ts +++ b/packages/capacitor/src/generators/configuration/generator.ts @@ -1,11 +1,11 @@ import { convertNxGenerator, formatFiles, Tree } from '@nx/devkit'; import { addCapacitorConfig } from './lib/add-capacitor-config'; import { addDependencies } from './lib/add-dependencies'; -import { addProject } from './lib/add-project'; import { normalizeOptions } from './lib/normalize-options'; import { updateProjectGitignore } from './lib/update-project-gitignore'; import { updateProjectPackageJson } from './lib/update-project-package-json'; import { CapacitorConfigurationSchema } from './schema'; +import { addPluginToNxJson } from '@nxext/common'; export async function capacitorConfigurationGenerator( host: Tree, @@ -15,8 +15,8 @@ export async function capacitorConfigurationGenerator( const installTask = addDependencies(host); addCapacitorConfig(host, normalizedOptions); updateProjectGitignore(host, normalizedOptions); - addProject(host, normalizedOptions); updateProjectPackageJson(host, normalizedOptions); + addPluginToNxJson('@nxext/capacitor', host); if (!options.skipFormat) { await formatFiles(host); diff --git a/packages/capacitor/src/index.ts b/packages/capacitor/src/index.ts index 595e670c..04d197d7 100644 --- a/packages/capacitor/src/index.ts +++ b/packages/capacitor/src/index.ts @@ -1,2 +1,3 @@ export { capacitorConfigurationGenerator } from './generators/configuration/generator'; export { CapacitorConfigurationSchema } from './generators/configuration/schema'; +export { createNodes, CapacitorPluginOptions } from './plugins/plugin'; diff --git a/packages/capacitor/src/plugins/plugin.ts b/packages/capacitor/src/plugins/plugin.ts new file mode 100644 index 00000000..3b0e1960 --- /dev/null +++ b/packages/capacitor/src/plugins/plugin.ts @@ -0,0 +1,41 @@ +import { + CreateNodesV2, + getPackageManagerCommand, + ProjectConfiguration +} from '@nx/devkit'; +import { dirname } from 'node:path'; + +const pmc = getPackageManagerCommand(); + +export interface CapacitorPluginOptions {} + +export const createNodes: CreateNodesV2 = [ + '**/capacitor.config.ts', + (configFiles, options, context) => { + return configFiles.map((configFile) => { + const projectRoot = dirname(configFile); + return [ + projectRoot, + { + projects: { + [projectRoot]: { + projectType: 'application', + targets: buildTargets(projectRoot), + }, + }, + }, + ] as const; + }); + }, +]; + +function buildTargets(projectRoot: string): ProjectConfiguration['targets'] { + return { + cap: { + command: `${pmc.exec} cap {args.cmd}`, + options: { + cwd: projectRoot, + }, + }, + }; +} From 21b1d13a2ee1ef663eb7f20369d8f5612a7d3f68 Mon Sep 17 00:00:00 2001 From: Edouard Bozon Date: Wed, 9 Oct 2024 12:51:40 +0200 Subject: [PATCH 3/3] chore: format --- packages/capacitor/src/plugins/plugin.ts | 2 +- tools/scripts/start-local-registry.ts | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/capacitor/src/plugins/plugin.ts b/packages/capacitor/src/plugins/plugin.ts index 3b0e1960..a9bd78a4 100644 --- a/packages/capacitor/src/plugins/plugin.ts +++ b/packages/capacitor/src/plugins/plugin.ts @@ -1,7 +1,7 @@ import { CreateNodesV2, getPackageManagerCommand, - ProjectConfiguration + ProjectConfiguration, } from '@nx/devkit'; import { dirname } from 'node:path'; diff --git a/tools/scripts/start-local-registry.ts b/tools/scripts/start-local-registry.ts index d8271531..cc048304 100644 --- a/tools/scripts/start-local-registry.ts +++ b/tools/scripts/start-local-registry.ts @@ -31,14 +31,7 @@ export default async () => { }, }); - execFileSync('pnpm', [ - 'nx', - 'run-many', - '-t', - 'build', - '--exclude', - 'docs' - ]); + execFileSync('pnpm', ['nx', 'run-many', '-t', 'build', '--exclude', 'docs']); await releasePublish({ tag: 'e2e',