Skip to content

Commit

Permalink
chore(cli): Create 'convertToUnixPath' in fs-utils function (#1699)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Oberwasserlechner authored and jcesarmobile committed Jun 24, 2019
1 parent 9780b6d commit 044c3d4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cli/src/android/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { runCommand } from '../common';
import { Config } from '../config';
import { getPluginPlatform, Plugin, PluginType } from '../plugin';
import { mkdirs } from 'fs-extra';
import { copyAsync, existsAsync, existsSync, readFileAsync, removeAsync, writeFileAsync } from '../util/fs';
import { convertToUnixPath, copyAsync, existsAsync, existsSync, readFileAsync, removeAsync, writeFileAsync } from '../util/fs';
import { resolve, join } from 'path';
import { getIncompatibleCordovaPlugins } from '../cordova';

Expand All @@ -26,7 +26,7 @@ export function resolvePlugin(plugin: Plugin): Plugin | null {
}
plugin.android = {
type: PluginType.Core,
path: pluginFilesPath.replace(/\\/g, '/')
path: convertToUnixPath(pluginFilesPath)
};
} else if (plugin.xml) {
plugin.android = {
Expand Down
14 changes: 7 additions & 7 deletions cli/src/android/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { buildXmlElement, checkPlatformVersions, logFatal, logInfo, parseXML, re
import { getAllElements, getFilePath, getPlatformElement, getPluginPlatform, getPlugins, getPluginType, printPlugins, Plugin, PluginType } from '../plugin';
import { getAndroidPlugins } from './common';
import { checkAndInstallDependencies, handleCordovaPluginsJS } from '../cordova';
import { copySync, readFileAsync, removeSync, writeFileAsync } from '../util/fs';
import { convertToUnixPath, copySync, readFileAsync, removeSync, writeFileAsync} from '../util/fs';
import { join, relative, resolve } from 'path';

const platform = 'android';
Expand Down Expand Up @@ -54,12 +54,12 @@ export async function installGradlePlugins(config: Config, capacitorPlugins: Plu

const settingsPath = join(config.app.rootDir, 'android');
const dependencyPath = join(config.app.rootDir, 'android', 'app');
const relativeCapcitorAndroidPath = relative(settingsPath, capacitorAndroidPath).replace(/\\/g, '/');
const relativeCapcitorAndroidPath = convertToUnixPath(relative(settingsPath, capacitorAndroidPath));
const settingsLines = `// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
include ':capacitor-android'
project(':capacitor-android').projectDir = new File('${relativeCapcitorAndroidPath}')
${capacitorPlugins.map(p => {
const relativePluginPath = relative(settingsPath, p.rootPath).replace(/\\/g, '/');
const relativePluginPath = convertToUnixPath(relative(settingsPath, p.rootPath));
return `
include ':${getGradlePackageName(p.id)}'
project(':${getGradlePackageName(p.id)}').projectDir = new File('${relativePluginPath}/${p.android!.path}')
Expand All @@ -70,7 +70,7 @@ project(':${getGradlePackageName(p.id)}').projectDir = new File('${relativePlugi
let frameworksArray: Array<any> = [];
let prefsArray: Array<any> = [];
cordovaPlugins.map( p => {
const relativePluginPath = relative(dependencyPath, p.rootPath).replace(/\\/g, '/');
const relativePluginPath = convertToUnixPath(relative(dependencyPath, p.rootPath));
const frameworks = getPlatformElement(p, platform, 'framework');
frameworks.map((framework: any) => {
if (framework.$.custom && framework.$.custom === 'true' && framework.$.type && framework.$.type === 'gradleReference') {
Expand All @@ -83,7 +83,7 @@ project(':${getGradlePackageName(p.id)}').projectDir = new File('${relativePlugi
});
let frameworkString = frameworksArray.join('\n');
prefsArray.map((preference: any) => {
frameworkString = frameworkString.replace(new RegExp(('$'+preference.$.name).replace('$', '\\$&'), 'g'), preference.$.default);
frameworkString = frameworkString.replace(new RegExp(('$' + preference.$.name).replace('$', '\\$&'), 'g'), preference.$.default);
});
const dependencyLines = `// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
Expand Down Expand Up @@ -120,7 +120,7 @@ export async function handleCordovaPluginsGradle(config: Config, cordovaPlugins
let applyArray: Array<any> = [];
applyArray.push(`apply from: "cordova.variables.gradle"`);
cordovaPlugins.map( p => {
const relativePluginPath = relative(pluginsFolder, p.rootPath).replace(/\\/g, '/');
const relativePluginPath = convertToUnixPath(relative(pluginsFolder, p.rootPath));
const frameworks = getPlatformElement(p, platform, 'framework');
frameworks.map((framework: any) => {
if (!framework.$.type && !framework.$.custom) {
Expand Down Expand Up @@ -267,4 +267,4 @@ function contains(a: Array<any>, obj: any, k: string) {
}
}
return false;
}
}
4 changes: 2 additions & 2 deletions cli/src/ios/update.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { checkCocoaPods, checkIOSProject, getIOSPlugins } from './common';
import { CheckFunction, checkPlatformVersions, logFatal, resolveNode, runCommand, runTask } from '../common';
import { copySync, readFileAsync, readFileSync, removeSync, writeFileAsync, writeFileSync } from '../util/fs';
import { convertToUnixPath, copySync, readFileAsync, readFileSync, removeSync, writeFileAsync, writeFileSync } from '../util/fs';
import { Config } from '../config';
import { join, relative, resolve } from 'path';
import { realpathSync } from 'fs';
Expand Down Expand Up @@ -95,7 +95,7 @@ export function generatePodFile(config: Config, plugins: Plugin[]) {
}

const podfilePath = join(config.app.rootDir, 'ios', 'App');
const relativeCapacitoriOSPath = relative(podfilePath, capacitoriOSPath).replace(/\\/g, '/');
const relativeCapacitoriOSPath = convertToUnixPath(relative(podfilePath, capacitoriOSPath));

const capacitorPlugins = plugins.filter(p => getPluginType(p, platform) === PluginType.Core);
const pods = capacitorPlugins
Expand Down
3 changes: 3 additions & 0 deletions cli/src/util/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ export const existsAsync = async (path: string) => {
return false;
}
};
export const convertToUnixPath = (path: string) => {
return path.replace(/\\/g, '/');
};

0 comments on commit 044c3d4

Please sign in to comment.