Skip to content

Commit

Permalink
Flatten scoped module when copying into android/src (#2837)
Browse files Browse the repository at this point in the history
* fix path when removing  dir in a scoped dependency during prepare

* flatten android plugins with native code when copying into main/src
  • Loading branch information
petekanev authored Jun 6, 2017
1 parent ab08c91 commit c1c3ac4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 4 additions & 1 deletion lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
if (this.$fs.exists(pluginPlatformsFolderPath)) {
this.$fs.ensureDirectoryExists(pluginConfigurationDirectoryPath);

let isScoped = pluginData.name.indexOf("@") === 0;
let flattenedDependencyName = isScoped ? pluginData.name.replace("/", "_") : pluginData.name;

// Copy all resources from plugin
let resourcesDestinationDirectoryPath = path.join(this.getPlatformData(projectData).projectRoot, "src", pluginData.name);
let resourcesDestinationDirectoryPath = path.join(this.getPlatformData(projectData).projectRoot, "src", flattenedDependencyName);
this.$fs.ensureDirectoryExists(resourcesDestinationDirectoryPath);
shell.cp("-Rf", path.join(pluginPlatformsFolderPath, "*"), resourcesDestinationDirectoryPath);

Expand Down
16 changes: 9 additions & 7 deletions lib/tools/node-modules/node-modules-dest-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@ export class TnsModulesCopy {

private copyDependencyDir(dependency: IDependencyData): void {
if (dependency.depth === 0) {
const targetPackageDir = path.join(this.outputRoot, dependency.name);

shelljs.mkdir("-p", targetPackageDir);

let isScoped = dependency.name.indexOf("@") === 0;
let targetDir = this.outputRoot;

if (isScoped) {
targetDir = path.join(this.outputRoot, dependency.name.substring(0, dependency.name.indexOf("/")));
// copy module into tns_modules/@scope/module instead of tns_modules/module
shelljs.cp("-Rf", dependency.directory, path.join(this.outputRoot, dependency.name.substring(0, dependency.name.indexOf("/"))));
} else {
shelljs.cp("-Rf", dependency.directory, this.outputRoot);
}

shelljs.mkdir("-p", targetDir);
shelljs.cp("-Rf", dependency.directory, targetDir);

//remove platform-specific files (processed separately by plugin services)
const targetPackageDir = path.join(targetDir, dependency.name);
// remove platform-specific files (processed separately by plugin services)
shelljs.rm("-rf", path.join(targetPackageDir, "platforms"));
}
}
Expand Down

0 comments on commit c1c3ac4

Please sign in to comment.