Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add Capacitor Crystal Plugin #1130

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
}
},
"release": {
"projects": ["packages/*", "!common"],
"projects": ["packages/*"],
"projectsRelationship": "independent",
"version": {
"conventionalCommits": true,
Expand Down
3 changes: 2 additions & 1 deletion packages/capacitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
81 changes: 4 additions & 77 deletions packages/capacitor/src/generators/configuration/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
addProjectConfiguration,
normalizePath,
readJson,
readNxJson,
readProjectConfiguration,
Tree,
writeJson,
Expand Down Expand Up @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/capacitor/src/generators/configuration/generator.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/capacitor/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { capacitorConfigurationGenerator } from './generators/configuration/generator';
export { CapacitorConfigurationSchema } from './generators/configuration/schema';
export { createNodes, CapacitorPluginOptions } from './plugins/plugin';
41 changes: 41 additions & 0 deletions packages/capacitor/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
@@ -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<CapacitorPluginOptions> = [
'**/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,
},
},
};
}
9 changes: 1 addition & 8 deletions tools/scripts/start-local-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ export default async () => {
},
});

execFileSync('pnpm', [
'nx',
'run-many',
'-t',
'build',
'--exclude',
'docs,common',
]);
execFileSync('pnpm', ['nx', 'run-many', '-t', 'build', '--exclude', 'docs']);

await releasePublish({
tag: 'e2e',
Expand Down
Loading