Skip to content

Commit 79339f4

Browse files
authored
More verbose logging (#121)
* Logging * Don't show diff for files missing * More iOS verbose logging * More logging and create json file if not exists * More android logging * Happy with additional logging * More better logging * Cleanup
1 parent e5307f5 commit 79339f4

File tree

17 files changed

+151
-35
lines changed

17 files changed

+151
-35
lines changed

package-lock.json

Lines changed: 15 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/configure/src/operations/ios/json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default async function execute(ctx: Context, op: Operation) {
1818

1919
jsonFile = ctx.project.ios?.getProjectFile<JsonFile>(
2020
filename!,
21-
(filename: string) => new JsonFile(filename, ctx.project.vfs),
21+
(filename: string) => new JsonFile(filename, ctx.project.vfs)
2222
);
2323

2424
if (!jsonFile) {

packages/configure/src/tasks/run.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import c from '../colors';
22
import { processOperations } from '../op';
3-
import { logger, log, error, warn } from '../util/log';
3+
import { logger, log, error, warn, debug } from '../util/log';
44
import { logPrompt } from '../util/cli';
55
import { loadYamlConfig, YamlFile } from '../yaml-config';
66
import { hasHandler, runOperation } from '../operations/index';
77
import { Context } from '../ctx';
88
import { Operation } from '../definitions';
9-
import { VFSDiff } from '@trapezedev/project';
9+
import { Logger, VFSDiff } from '@trapezedev/project';
10+
import kleur from 'kleur';
1011

1112
export async function runCommand(ctx: Context, configFile: YamlFile) {
1213
let processed: Operation[];
@@ -34,7 +35,13 @@ export async function runCommand(ctx: Context, configFile: YamlFile) {
3435
async function executeOperations(ctx: Context, operations: Operation[]) {
3536
for (const op of operations) {
3637
if (!ctx.args.quiet) {
37-
printOp(op);
38+
printOp(ctx, op);
39+
}
40+
41+
const skipped = op.platform === 'ios' ? !ctx.project.ios : !ctx.project.android;
42+
if (skipped) {
43+
Logger.debug(`Skipping ${op.id} because ${op.platform} project does not exist`);
44+
continue;
3845
}
3946

4047
if (!hasHandler(op)) {
@@ -49,9 +56,10 @@ async function executeOperations(ctx: Context, operations: Operation[]) {
4956
await checkModifiedFiles(ctx);
5057
}
5158

52-
function printOp(op: Operation) {
59+
function printOp(ctx: Context, op: Operation) {
60+
const skipped = op.platform === 'ios' ? !ctx.project.ios : !ctx.project.android;
5361
// const env = c.weak(`[${op.env}]`);
54-
const tag = c.weak(c.strong(`run`));
62+
const tag = skipped ? c.weak(c.strong(`skip`)) : kleur.bold().magenta(`run`);
5563
const platform = c.success(c.strong(`${op.platform}`));
5664
const opName = c.strong(op.name);
5765
const opDisplay = op.displayText;
0 Bytes
Binary file not shown.

packages/project/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232
"@types/slice-ansi": "^5.0.0",
3333
"@xmldom/xmldom": "^0.7.5",
3434
"conventional-changelog": "^3.1.4",
35+
"cross-fetch": "^3.1.5",
3536
"cross-spawn": "^7.0.3",
3637
"diff": "^5.1.0",
3738
"env-paths": "^3.0.0",
3839
"gradle-to-js": "^2.0.0",
3940
"ini": "^2.0.0",
41+
"kleur": "^4.1.5",
4042
"lodash": "^4.17.21",
4143
"mergexml": "^1.2.3",
42-
"cross-fetch": "^3.1.5",
4344
"npm-watch": "^0.9.0",
4445
"plist": "^3.0.4",
4546
"prettier": "^2.7.1",

packages/project/src/android/gradle-file.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { indent } from '../util/text';
77
import { VFS, VFSFile, VFSStorable, VFSDiff } from '../vfs';
88
import detectIndent from '../util/detect-indent';
99
import { AndroidGradleInjectType } from '../definitions';
10+
import { Logger } from '../logger';
1011

1112
export type GradleAST = any;
1213
export interface GradleASTNode {
@@ -238,6 +239,9 @@ export class GradleFile extends VFSStorable {
238239
throw new Error(this.gradleParseError());
239240
}
240241

242+
Logger.v('gradle', 'parse', `running Gradle parse with Java path ${java}`);
243+
Logger.v('gradle', 'parse', `read gradle file at ${this.filename}`);
244+
241245
try {
242246
let json: string | null = null;
243247

@@ -529,6 +533,7 @@ export class GradleFile extends VFSStorable {
529533
const source = await this.getGradleSource();
530534

531535
if (source) {
536+
Logger.v('gradle', 'setVersionCode', `to ${versionCode} in ${this.filename}`);
532537
this.source = source.replace(/(versionCode\s+)\w+/, `$1${versionCode}`);
533538
}
534539
}
@@ -556,6 +561,7 @@ export class GradleFile extends VFSStorable {
556561
}
557562
const num = parseInt(versionCode[1]);
558563
if (!isNaN(num)) {
564+
Logger.v('gradle', 'incrementVersionCode', `to ${num} in ${this.filename}`);
559565
this.source = source.replace(/(versionCode\s+)\w+/, `$1${num + 1}`);
560566
}
561567
}
@@ -565,6 +571,7 @@ export class GradleFile extends VFSStorable {
565571
const source = await this.getGradleSource();
566572

567573
if (source) {
574+
Logger.v('gradle', 'setVersionName', `to ${versionName} in ${this.filename}`);
568575
this.source = source.replace(
569576
/(versionName\s+)["'][^"']+["']/,
570577
`$1"${versionName}"`,

packages/project/src/android/project.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { XmlFile } from '../xml';
1919
import { PropertiesFile } from '../properties';
2020
import { PlatformProject } from '../platform-project';
2121
import { readSource } from '../read-src';
22+
import { Logger } from '../logger';
2223

2324
export class AndroidProject extends PlatformProject {
2425
private manifest: XmlFile;
@@ -83,14 +84,14 @@ export class AndroidProject extends PlatformProject {
8384
getXmlFile(path: string) {
8485
return this.getProjectFile(
8586
path,
86-
(filename: string) => new XmlFile(filename, this.project.vfs),
87+
(filename: string) => new XmlFile(filename, this.project.vfs)
8788
);
8889
}
8990

9091
getPropertiesFile(path: string) {
9192
return this.getProjectFile(
9293
path,
93-
(filename: string) => new PropertiesFile(filename, this.project.vfs),
94+
(filename: string) => new PropertiesFile(filename, this.project.vfs)
9495
);
9596
}
9697

@@ -118,6 +119,8 @@ export class AndroidProject extends PlatformProject {
118119
?.getAttribute('package');
119120
const oldPackageParts = oldPackageName?.split('.') ?? [];
120121

122+
Logger.v('android', 'setPackageName', 'setting Android package name to', packageName, 'from', oldPackageName);
123+
121124
if (packageName === oldPackageName) {
122125
return;
123126
}
@@ -131,9 +134,11 @@ export class AndroidProject extends PlatformProject {
131134

132135
this.manifest.getDocumentElement()?.setAttribute('package', packageName);
133136
await this.appBuildGradle?.setApplicationId(packageName);
137+
Logger.v('android', 'setPackageName', `set manifest package attribute and applicationId to ${packageName}`);
134138
this.manifest.setAttrs('manifest/application/activity', {
135139
'android:name': `${packageName}.MainActivity`,
136140
});
141+
Logger.v('android', 'setPackageName', `set <activity android:name="${packageName}.MainActivity"`);
137142

138143
if (!this.getAppRoot()) {
139144
return;
@@ -143,11 +148,14 @@ export class AndroidProject extends PlatformProject {
143148

144149
const destDir = join(sourceDir, ...newPackageParts);
145150

146-
// TODO: Don't hard code this
147151
const mainActivityName = this.getMainActivityFilename();
148152

153+
Logger.v('android', 'setPackageName', `Got main activity name ${mainActivityName}`);
154+
149155
let activityFile = join(sourceDir, ...oldPackageParts, mainActivityName);
150156

157+
Logger.v('android', 'setPackageName', `Looking for old activity file at ${activityFile}`);
158+
151159
// Make the new directory tree and any missing parents
152160
await mkdirp(destDir);
153161
// Move the old activity file over
@@ -157,6 +165,8 @@ export class AndroidProject extends PlatformProject {
157165
// from the deepest
158166
let sourceDirLeaf = join(sourceDir, ...oldPackageParts);
159167

168+
Logger.v('android', 'setPackageName', `removing old source dirs for old package (${sourceDirLeaf})`);
169+
160170
for (const _ of oldPackageParts) {
161171
try {
162172
await rmdir(sourceDirLeaf);
@@ -169,6 +179,7 @@ export class AndroidProject extends PlatformProject {
169179
// Rename the package in the main source file
170180
activityFile = join(sourceDir, ...newPackageParts, this.getMainActivityFilename());
171181
if (await pathExists(activityFile)) {
182+
Logger.v('android', 'setPackageName', `renaming package in source for activity file ${activityFile}`);
172183
const activitySource = await readFile(activityFile, {
173184
encoding: 'utf-8',
174185
});
@@ -253,6 +264,8 @@ export class AndroidProject extends PlatformProject {
253264

254265
const dir = join(root, resDir);
255266

267+
Logger.v(`android`, 'addResource', `add res file ${file} to ${resDir}`);
268+
256269
if (!(await pathExists(dir))) {
257270
await mkdir(dir);
258271
}
@@ -266,6 +279,8 @@ export class AndroidProject extends PlatformProject {
266279
}
267280
const destPath = join(this.project.config.android.path, dest);
268281

282+
Logger.v(`android`, `copyFile`, `copying ${src} to ${destPath}`);
283+
269284
if (/^(https?:\/\/)/.test(src)) {
270285
const res = await fetch(src);
271286
return writeFile(destPath, Buffer.from(await res.arrayBuffer()));
@@ -291,6 +306,8 @@ export class AndroidProject extends PlatformProject {
291306
await mkdir(dir);
292307
}
293308

309+
Logger.v(`android`, `copyToResources`, `copying ${file} to Android resources at ${join(dir, file)}`);
310+
294311
const sourceData = await readSource(source);
295312
return writeFile(join(dir, file), sourceData);
296313
}

packages/project/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from './definitions';
22
export * from './frameworks';
33
export * from './config';
4+
export * from './logger';
45
export * from './project';
56
export * from './xml';
67
export * from './json';

0 commit comments

Comments
 (0)