Skip to content

Respect configuration when preparing project files #2958

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

Merged
merged 1 commit into from
Jul 27, 2017
Merged
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
11 changes: 8 additions & 3 deletions lib/commands/test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import * as helpers from "../common/helpers";

function RunTestCommandFactory(platform: string) {
return function RunTestCommand(
$options: IOptions,
$testExecutionService: ITestExecutionService,
$projectData: IProjectData) {
$projectData.initializeProjectData();
this.execute = (args: string[]): Promise<void> => $testExecutionService.startTestRunner(platform, $projectData);
const projectFilesConfig = helpers.getProjectFilesConfig({ isReleaseBuild: this.$options.release });
this.execute = (args: string[]): Promise<void> => $testExecutionService.startTestRunner(platform, $projectData, projectFilesConfig);
this.allowedParameters = [];
};
}
Expand All @@ -12,9 +16,10 @@ $injector.registerCommand("dev-test|android", RunTestCommandFactory('android'));
$injector.registerCommand("dev-test|ios", RunTestCommandFactory('iOS'));

function RunKarmaTestCommandFactory(platform: string) {
return function RunKarmaTestCommand($testExecutionService: ITestExecutionService, $projectData: IProjectData) {
return function RunKarmaTestCommand($options: IOptions, $testExecutionService: ITestExecutionService, $projectData: IProjectData) {
$projectData.initializeProjectData();
this.execute = (args: string[]): Promise<void> => $testExecutionService.startKarmaServer(platform, $projectData);
const projectFilesConfig = helpers.getProjectFilesConfig({ isReleaseBuild: this.$options.release });
this.execute = (args: string[]): Promise<void> => $testExecutionService.startKarmaServer(platform, $projectData, projectFilesConfig);
this.allowedParameters = [];
};
}
Expand Down
4 changes: 2 additions & 2 deletions lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ interface IPlatformsData {
}

interface INodeModulesBuilder {
prepareNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData): Promise<void>;
prepareJSNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData): Promise<void>;
prepareNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void>;
prepareJSNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void>;
cleanNodeModules(absoluteOutputPath: string, platform: string): void;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/definitions/plugins.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
interface IPluginsService {
add(plugin: string, projectData: IProjectData): Promise<void>; // adds plugin by name, github url, local path and et.
remove(pluginName: string, projectData: IProjectData): Promise<void>; // removes plugin only by name
prepare(pluginData: IDependencyData, platform: string, projectData: IProjectData): Promise<void>;
prepare(pluginData: IDependencyData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void>;
getAllInstalledPlugins(projectData: IProjectData): Promise<IPluginData[]>;
ensureAllDependenciesAreInstalled(projectData: IProjectData): Promise<void>;
preparePluginScripts(pluginData: IPluginData, platform: string, projectData: IProjectData): void
preparePluginScripts(pluginData: IPluginData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): void

/**
* Returns all dependencies and devDependencies from pacakge.json file.
Expand Down
4 changes: 2 additions & 2 deletions lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ interface IAndroidProjectPropertiesManager {
}

interface ITestExecutionService {
startTestRunner(platform: string, projectData: IProjectData): Promise<void>;
startKarmaServer(platform: string, projectData: IProjectData): Promise<void>;
startTestRunner(platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void>;
startKarmaServer(platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void>;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/providers/project-files-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export class ProjectFilesProvider extends ProjectFilesProviderBase {

private static INTERNAL_NONPROJECT_FILES = [ "**/*.ts" ];

public mapFilePath(filePath: string, platform: string, projectData: IProjectData): string {
public mapFilePath(filePath: string, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): string {
let platformData = this.$platformsData.getPlatformData(platform.toLowerCase(), projectData);
let parsedFilePath = this.getPreparedFilePath(filePath);
let parsedFilePath = this.getPreparedFilePath(filePath, projectFilesConfig);
let mappedFilePath = "";
if (parsedFilePath.indexOf(constants.NODE_MODULES_FOLDER_NAME) > -1) {
let relativePath = path.relative(path.join(projectData.projectDir, constants.NODE_MODULES_FOLDER_NAME), parsedFilePath);
Expand Down
19 changes: 10 additions & 9 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,11 @@ export class PlatformService extends EventEmitter implements IPlatformService {
this.$logger.out("Preparing project...");

let platformData = this.$platformsData.getPlatformData(platform, projectData);
await this.preparePlatformCoreJS(platform, platformData, appFilesUpdaterOptions, projectData, platformSpecificData, changesInfo);
const projectFilesConfig = helpers.getProjectFilesConfig({ isReleaseBuild: appFilesUpdaterOptions.release });
await this.preparePlatformCoreJS(platform, platformData, appFilesUpdaterOptions, projectData, platformSpecificData, changesInfo, filesToSync, projectFilesConfig);

if (!nativePrepare || !nativePrepare.skipNativePrepare) {
await this.preparePlatformCoreNative(platform, platformData, appFilesUpdaterOptions, projectData, platformSpecificData, changesInfo);
await this.preparePlatformCoreNative(platform, platformData, appFilesUpdaterOptions, projectData, platformSpecificData, changesInfo, projectFilesConfig);
}

let directoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
Expand All @@ -306,12 +307,12 @@ export class PlatformService extends EventEmitter implements IPlatformService {
excludedDirs.push(constants.TNS_MODULES_FOLDER_NAME);
}

this.$projectFilesManager.processPlatformSpecificFiles(directoryPath, platform, excludedDirs);
this.$projectFilesManager.processPlatformSpecificFiles(directoryPath, platform, projectFilesConfig, excludedDirs);

this.$logger.out(`Project successfully prepared (${platform})`);
}

private async preparePlatformCoreJS(platform: string, platformData: IPlatformData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, changesInfo?: IProjectChangesInfo, filesToSync?: Array<String>, ): Promise<void> {
private async preparePlatformCoreJS(platform: string, platformData: IPlatformData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, changesInfo?: IProjectChangesInfo, filesToSync?: Array<String>, projectFilesConfig?: IProjectFilesConfig): Promise<void> {
if (!changesInfo || changesInfo.appFilesChanged) {
await this.copyAppFiles(platformData, appFilesUpdaterOptions, projectData);

Expand All @@ -324,11 +325,11 @@ export class PlatformService extends EventEmitter implements IPlatformService {
}

if (!changesInfo || changesInfo.modulesChanged) {
await this.copyTnsModules(platform, platformData, projectData);
await this.copyTnsModules(platform, platformData, projectData, projectFilesConfig);
}
}

public async preparePlatformCoreNative(platform: string, platformData: IPlatformData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, changesInfo?: IProjectChangesInfo): Promise<void> {
public async preparePlatformCoreNative(platform: string, platformData: IPlatformData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, changesInfo?: IProjectChangesInfo, projectFilesConfig?: IProjectFilesConfig): Promise<void> {
if (changesInfo.hasChanges) {
await this.cleanProject(platform, appFilesUpdaterOptions, platformData, projectData);
}
Expand All @@ -347,7 +348,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {

let tnsModulesDestinationPath = path.join(appDestinationDirectoryPath, constants.TNS_MODULES_FOLDER_NAME);
// Process node_modules folder
await this.$nodeModulesBuilder.prepareNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime, projectData);
await this.$nodeModulesBuilder.prepareNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime, projectData, projectFilesConfig);
}

if (!changesInfo || changesInfo.configChanged || changesInfo.modulesChanged) {
Expand Down Expand Up @@ -385,14 +386,14 @@ export class PlatformService extends EventEmitter implements IPlatformService {
}
}

private async copyTnsModules(platform: string, platformData: IPlatformData, projectData: IProjectData): Promise<void> {
private async copyTnsModules(platform: string, platformData: IPlatformData, projectData: IProjectData, projectFilesConfig?: IProjectFilesConfig): Promise<void> {
let appDestinationDirectoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
let lastModifiedTime = this.$fs.exists(appDestinationDirectoryPath) ? this.$fs.getFsStats(appDestinationDirectoryPath).mtime : null;

try {
let tnsModulesDestinationPath = path.join(appDestinationDirectoryPath, constants.TNS_MODULES_FOLDER_NAME);
// Process node_modules folder
await this.$nodeModulesBuilder.prepareJSNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime, projectData);
await this.$nodeModulesBuilder.prepareJSNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime, projectData, projectFilesConfig);
} catch (error) {
this.$logger.debug(error);
shell.rm("-rf", appDestinationDirectoryPath);
Expand Down
8 changes: 4 additions & 4 deletions lib/services/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,22 @@ export class PluginsService implements IPluginsService {
return await platformData.platformProjectService.validatePlugins(projectData);
}

public async prepare(dependencyData: IDependencyData, platform: string, projectData: IProjectData): Promise<void> {
public async prepare(dependencyData: IDependencyData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void> {
platform = platform.toLowerCase();
let platformData = this.$platformsData.getPlatformData(platform, projectData);
let pluginData = this.convertToPluginData(dependencyData, projectData.projectDir);

let appFolderExists = this.$fs.exists(path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME));
if (appFolderExists) {
this.preparePluginScripts(pluginData, platform, projectData);
this.preparePluginScripts(pluginData, platform, projectData, projectFilesConfig);
await this.preparePluginNativeCode(pluginData, platform, projectData);

// Show message
this.$logger.out(`Successfully prepared plugin ${pluginData.name} for ${platform}.`);
}
}

public preparePluginScripts(pluginData: IPluginData, platform: string, projectData: IProjectData): void {
public preparePluginScripts(pluginData: IPluginData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): void {
let platformData = this.$platformsData.getPlatformData(platform, projectData);
let pluginScriptsDestinationPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, "tns_modules");
let scriptsDestinationExists = this.$fs.exists(pluginScriptsDestinationPath);
Expand All @@ -136,7 +136,7 @@ export class PluginsService implements IPluginsService {
}

//prepare platform speciffic files, .map and .ts files
this.$projectFilesManager.processPlatformSpecificFiles(pluginScriptsDestinationPath, platform);
this.$projectFilesManager.processPlatformSpecificFiles(pluginScriptsDestinationPath, platform, projectFilesConfig);
}

public async preparePluginNativeCode(pluginData: IPluginData, platform: string, projectData: IProjectData): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions lib/services/test-execution-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestExecutionService implements ITestExecutionService {

public platform: string;

public async startTestRunner(platform: string, projectData: IProjectData): Promise<void> {
public async startTestRunner(platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void> {
this.platform = platform;
this.$options.justlaunch = true;
await new Promise<void>((resolve, reject) => {
Expand Down Expand Up @@ -133,7 +133,7 @@ class TestExecutionService implements ITestExecutionService {
});
}

public async startKarmaServer(platform: string, projectData: IProjectData): Promise<void> {
public async startKarmaServer(platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void> {
platform = platform.toLowerCase();
this.platform = platform;

Expand Down
8 changes: 4 additions & 4 deletions lib/tools/node-modules/node-modules-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ export class NodeModulesBuilder implements INodeModulesBuilder {
private $nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder
) { }

public async prepareNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData): Promise<void> {
public async prepareNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void> {
const productionDependencies = this.initialPrepareNodeModules(absoluteOutputPath, platform, lastModifiedTime, projectData);
const npmPluginPrepare: NpmPluginPrepare = this.$injector.resolve(NpmPluginPrepare);
await npmPluginPrepare.preparePlugins(productionDependencies, platform, projectData);
await npmPluginPrepare.preparePlugins(productionDependencies, platform, projectData, projectFilesConfig);
}

public async prepareJSNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData): Promise<void> {
public async prepareJSNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void> {
const productionDependencies = this.initialPrepareNodeModules(absoluteOutputPath, platform, lastModifiedTime, projectData);
const npmPluginPrepare: NpmPluginPrepare = this.$injector.resolve(NpmPluginPrepare);
await npmPluginPrepare.prepareJSPlugins(productionDependencies, platform, projectData);
await npmPluginPrepare.prepareJSPlugins(productionDependencies, platform, projectData, projectFilesConfig);
}

public cleanNodeModules(absoluteOutputPath: string, platform: string): void {
Expand Down
8 changes: 4 additions & 4 deletions lib/tools/node-modules/node-modules-dest-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class NpmPluginPrepare {
return result;
}

public async preparePlugins(dependencies: IDependencyData[], platform: string, projectData: IProjectData): Promise<void> {
public async preparePlugins(dependencies: IDependencyData[], platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void> {
if (_.isEmpty(dependencies) || this.allPrepared(dependencies, platform, projectData)) {
return;
}
Expand All @@ -155,10 +155,10 @@ export class NpmPluginPrepare {
await this.afterPrepare(dependencies, platform, projectData);
}

public async prepareJSPlugins(dependencies: IDependencyData[], platform: string, projectData: IProjectData): Promise<void> {
public async prepareJSPlugins(dependencies: IDependencyData[], platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void> {
if (_.isEmpty(dependencies) || this.allPrepared(dependencies, platform, projectData)) {
return;
}
}

for (let dependencyKey in dependencies) {
const dependency = dependencies[dependencyKey];
Expand All @@ -169,7 +169,7 @@ export class NpmPluginPrepare {
let platformData = this.$platformsData.getPlatformData(platform, projectData);
let appFolderExists = this.$fs.exists(path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME));
if (appFolderExists) {
this.$pluginsService.preparePluginScripts(pluginData, platform, projectData);
this.$pluginsService.preparePluginScripts(pluginData, platform, projectData, projectFilesConfig);
// Show message
this.$logger.out(`Successfully prepared plugin ${pluginData.name} for ${platform}.`);
}
Expand Down
6 changes: 3 additions & 3 deletions test/plugin-prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TestNpmPluginPrepare extends NpmPluginPrepare {
describe("Plugin preparation", () => {
it("skips prepare if no plugins", async () => {
const pluginPrepare = new TestNpmPluginPrepare({});
await pluginPrepare.preparePlugins([], "android", null);
await pluginPrepare.preparePlugins([], "android", null, {});
assert.deepEqual({}, pluginPrepare.preparedDependencies);
});

Expand All @@ -42,7 +42,7 @@ describe("Plugin preparation", () => {
nativescript: null,
}
];
await pluginPrepare.preparePlugins(testDependencies, "android", null);
await pluginPrepare.preparePlugins(testDependencies, "android", null, {});
assert.deepEqual({}, pluginPrepare.preparedDependencies);
});

Expand All @@ -62,7 +62,7 @@ describe("Plugin preparation", () => {
nativescript: null,
}
];
await pluginPrepare.preparePlugins(testDependencies, "android", null);
await pluginPrepare.preparePlugins(testDependencies, "android", null, {});
const prepareData = { "tns-core-modules-widgets": true, "nativescript-calendar": true };
assert.deepEqual(prepareData, pluginPrepare.preparedDependencies);
});
Expand Down
2 changes: 1 addition & 1 deletion test/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ describe("Plugins service", () => {
`\n@#[line:1,col:39].` +
`\n@#[line:1,col:39].`;
mockBeginCommand(testInjector, expectedErrorMessage);
await pluginsService.prepare(pluginJsonData, "android", projectData);
await pluginsService.prepare(pluginJsonData, "android", projectData, {});
});
});
});
Loading