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

Support project-level operations #122

Merged
merged 4 commits into from
Nov 16, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Support project level xml and json operations
  • Loading branch information
mlynch committed Nov 15, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 99ed691f5034b927cdb7b357e5d53a0cdeb5b54c
16 changes: 10 additions & 6 deletions packages/configure/src/op.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Operation } from './definitions';
import { pluralize } from './util/plural';

// Given the parsed yaml file, generate a set of operations to perform against the project
export function processOperations(yaml: any): Operation[] {
@@ -35,8 +36,6 @@ function createProjectPlatform(platform: string, platformEntry: any) {
return [];
}

console.log('Creating project platform', platform, platformEntry);

return Object.keys(platformEntry || {})
.map(op => createOperation(platform, op, platformEntry[op]))
.flat();
@@ -188,6 +187,11 @@ function getOpIdAlias(op: Partial<Operation>) {
// TODO: Move this to per-operation for more powerful display
function createOpDisplayText(op: Partial<Operation>) {
switch (op.id) {
// project
case 'project.xml':
return `${op.value.length} ${pluralize(op.value.length, 'modification')}`;
case 'project.json':
return `${op.value.length} ${pluralize(op.value.length, 'modification')}`;
// ios
case 'ios.bundleId':
return op.value;
@@ -210,9 +214,9 @@ function createOpDisplayText(op: Partial<Operation>) {
case 'ios.plist':
return `${op.value.entries.length} modifications`;
case 'ios.xml':
return `${op.value.entries.length} modifications`;
return `${op.value.length} ${pluralize(op.value.length, 'modification')}`;
case 'ios.json':
return `${op.value.entries.length} modifications`;
return `${op.value.length} ${pluralize(op.value.length, 'modification')}`;
case 'ios.copy':
return op.value.map((r: any) => r.dest).join(', ');
// android
@@ -225,9 +229,9 @@ function createOpDisplayText(op: Partial<Operation>) {
case 'android.manifest':
return `${op.value.length} modifications`;
case 'android.json':
return `${op.value.entries.length} modifications`;
return `${op.value.length} ${pluralize(op.value.length, 'modification')}`;
case 'android.xml':
return `${op.value.entries.length} modifications`;
return `${op.value.length} ${pluralize(op.value.length, 'modification')}`;
case 'android.build.gradle':
return '';
case 'android.app.build.gradle':
5 changes: 5 additions & 0 deletions packages/configure/src/operations/index.ts
Original file line number Diff line number Diff line change
@@ -17,6 +17,9 @@ import executeIosXml from './ios/xml';
import executeIosJson from './ios/json';
import executeIosCopy from './ios/copy';

import executeProjectJson from './project/json';
import executeProjectXml from './project/xml';

import { Context } from '../ctx';
import { Operation } from '../definitions';

@@ -27,6 +30,8 @@ interface OperationHandlers {
}

const operations: OperationHandlers = {
'project.json': executeProjectJson,
'project.xml': executeProjectXml,
'ios.plist': executeIosPlist,
'ios.bundleId': executeIosProject,
'ios.displayName': executeIosProject,
2 changes: 1 addition & 1 deletion packages/configure/src/tasks/run.ts
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ async function executeOperations(ctx: Context, operations: Operation[]) {
printOp(ctx, op);
}

const skipped = op.platform === 'ios' ? !ctx.project.ios : !ctx.project.android;
const skipped = op.platform !== 'project' && (op.platform === 'ios' ? !ctx.project.ios : !ctx.project.android);
if (skipped) {
Logger.debug(`Skipping ${op.id} because ${op.platform} project does not exist`);
continue;
6 changes: 6 additions & 0 deletions packages/configure/src/util/plural.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function pluralize(v: number, msg: string) {
if (v === 0 || v > 1) {
return `${msg}s`;
}
return msg;
}