Skip to content

Commit

Permalink
feat: clean up legacy nsconfig if created for bw compat (#5380)
Browse files Browse the repository at this point in the history
  • Loading branch information
rigor789 authored Sep 8, 2020
1 parent 8491b07 commit 233091b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class PrepareController extends EventEmitter {
this.$logger.info("Preparing project...");

if (this.$mobileHelper.isAndroidPlatform(prepareData.platform)) {
this.$projectConfigService.writeLegacyNSConfigIfNeeded(
await this.$projectConfigService.writeLegacyNSConfigIfNeeded(
projectData.projectDir,
this.$projectDataService.getRuntimePackage(
projectData.projectDir,
Expand Down
2 changes: 1 addition & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ interface IProjectConfigService {
writeLegacyNSConfigIfNeeded(
projectDir: string,
runtimePackage: IBasePluginData
): void;
): Promise<void>;
}

interface IAssetItem {
Expand Down
9 changes: 7 additions & 2 deletions lib/services/project-config-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
import { cache } from "../common/decorators";
import { IOptions } from "../declarations";
import semver = require("semver/preload");
import { ICleanupService } from "../definitions/cleanup-service";

export class ProjectConfigService implements IProjectConfigService {
private forceUsingNewConfig: boolean = false;
Expand All @@ -39,7 +40,8 @@ export class ProjectConfigService implements IProjectConfigService {
private $fs: IFileSystem,
private $logger: ILogger,
private $injector: IInjector,
private $options: IOptions
private $options: IOptions,
private $cleanupService: ICleanupService
) {}

public setForceUsingNewConfig(force: boolean) {
Expand Down Expand Up @@ -329,7 +331,7 @@ export default {
// return Object.assign({}, ...additionalData, NSConfig);
}

public writeLegacyNSConfigIfNeeded(
public async writeLegacyNSConfigIfNeeded(
projectDir: string,
runtimePackage: IBasePluginData
) {
Expand Down Expand Up @@ -370,6 +372,9 @@ You may add \`nsconfig.json\` to \`.gitignore\` as the CLI will regenerate it as
appPath: this.getValue("appPath"),
appResourcesPath: this.getValue("appResourcesPath"),
});

// mark the file for cleanup after the CLI exits
await this.$cleanupService.addCleanupDeleteAction(nsConfigPath);
}

// todo: move into config manipulation
Expand Down
2 changes: 2 additions & 0 deletions test/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe("projectService", () => {
ensureValidName: async () => opts.projectName,
});
testInjector.register("projectConfigService", ProjectConfigService);
testInjector.register("cleanupService", {});
testInjector.register("projectTemplatesService", {
prepareTemplate: async () => ({
templateName: constants.RESERVED_TEMPLATE_NAMES["default"],
Expand Down Expand Up @@ -170,6 +171,7 @@ describe("projectService", () => {
testInjector.register("projectData", {});
testInjector.register("projectNameService", {});
testInjector.register("projectConfigService", ProjectConfigService);
testInjector.register("cleanupService", {});
testInjector.register("projectTemplatesService", {});
testInjector.register("staticConfig", {});
testInjector.register("projectHelper", {});
Expand Down
1 change: 1 addition & 0 deletions test/services/project-config-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const createTestInjector = (
testInjector.register("logger", LoggerStub);
testInjector.register("injector", testInjector);
testInjector.register("projectConfigService", ProjectConfigService);
testInjector.register("cleanupService", {});

return testInjector;
};
Expand Down
1 change: 1 addition & 0 deletions test/services/project-data-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const createTestInjector = (
});

testInjector.register("options", {});
testInjector.register("cleanupService", {});

return testInjector;
};
Expand Down
4 changes: 2 additions & 2 deletions test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,10 @@ export class ProjectConfigServiceStub implements IProjectConfigService {
return true;
}

writeLegacyNSConfigIfNeeded(
async writeLegacyNSConfigIfNeeded(
projectDir: string,
runtimePackage: IBasePluginData
): void {}
): Promise<void> {}
}

export class AndroidPluginBuildServiceStub
Expand Down

0 comments on commit 233091b

Please sign in to comment.