Skip to content

Commit

Permalink
feat(cli): do not require webDir when server.url is set (#4200)
Browse files Browse the repository at this point in the history
  • Loading branch information
imhoffd authored Feb 16, 2021
1 parent 5510d30 commit 91ddfbd
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
4 changes: 4 additions & 0 deletions cli/src/android/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
getPlugins,
printPlugins,
} from '../plugin';
import { copy as copyTask } from '../tasks/copy';
import { convertToUnixPath } from '../util/fs';
import { resolveNode } from '../util/node';
import { extractTemplate } from '../util/template';
Expand All @@ -56,6 +57,9 @@ export async function updateAndroid(config: Config): Promise<void> {
if (cordovaPlugins.length > 0) {
await copyPluginsNativeFiles(config, cordovaPlugins);
}
if (!(await pathExists(config.android.webDirAbs))) {
await copyTask(config, platform);
}
await handleCordovaPluginsJS(cordovaPlugins, config, platform);
await checkPluginDependencies(plugins, platform);
await installGradlePlugins(config, capacitorPlugins, cordovaPlugins);
Expand Down
5 changes: 5 additions & 0 deletions cli/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export async function check(checks: CheckFunction[]): Promise<void> {
}

export async function checkWebDir(config: Config): Promise<string | null> {
// We can skip checking the web dir if a server URL is set.
if (config.app.extConfig.server?.url) {
return null;
}

const invalidFolders = ['', '.', '..', '../', './'];
if (invalidFolders.includes(config.app.webDir)) {
return `"${config.app.webDir}" is not a valid value for webDir`;
Expand Down
8 changes: 4 additions & 4 deletions cli/src/cordova.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
copy,
ensureDir,
mkdirp,
pathExists,
readFile,
remove,
Expand Down Expand Up @@ -29,7 +30,6 @@ import {
getPlugins,
printPlugins,
} from './plugin';
import { copy as copyTask } from './tasks/copy';
import { resolveNode } from './util/node';
import { buildXmlElement, parseXML, readXML, writeXML } from './util/xml';

Expand Down Expand Up @@ -291,9 +291,9 @@ export async function handleCordovaPluginsJS(
config: Config,
platform: string,
): Promise<void> {
if (!(await pathExists(await getWebDir(config, platform)))) {
await copyTask(config, platform);
}
const webDir = await getWebDir(config, platform);
await mkdirp(webDir);

if (cordovaPlugins.length > 0) {
printPlugins(cordovaPlugins, platform, 'cordova');
await copyCordovaJS(config, platform);
Expand Down
13 changes: 12 additions & 1 deletion cli/src/ios/update.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { copy, remove, readFile, realpath, writeFile } from '@ionic/utils-fs';
import {
copy,
remove,
pathExists,
readFile,
realpath,
writeFile,
} from '@ionic/utils-fs';
import { basename, dirname, join, relative } from 'path';

import c from '../colors';
Expand All @@ -20,6 +27,7 @@ import {
getPlugins,
printPlugins,
} from '../plugin';
import { copy as copyTask } from '../tasks/copy';
import { convertToUnixPath } from '../util/fs';
import { resolveNode } from '../util/node';
import { runCommand } from '../util/subprocess';
Expand Down Expand Up @@ -48,6 +56,9 @@ export async function updateIOS(
if (cordovaPlugins.length > 0) {
await copyPluginsNativeFiles(config, cordovaPlugins);
}
if (!(await pathExists(await config.ios.webDirAbs))) {
await copyTask(config, platform);
}
await handleCordovaPluginsJS(cordovaPlugins, config, platform);
await checkPluginDependencies(plugins, platform);
await generateCordovaPodspecs(cordovaPlugins, config);
Expand Down
17 changes: 16 additions & 1 deletion cli/src/tasks/copy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { copy as fsCopy, remove, writeJSON } from '@ionic/utils-fs';
import { copy as fsCopy, pathExists, remove, writeJSON } from '@ionic/utils-fs';
import { basename, join, relative } from 'path';

import c from '../colors';
Expand Down Expand Up @@ -104,6 +104,21 @@ async function copyWebDir(config: Config, nativeAbsDir: string) {
const webRelDir = basename(webAbsDir);
const nativeRelDir = relative(config.app.rootDir, nativeAbsDir);

if (config.app.extConfig.server?.url && !(await pathExists(webAbsDir))) {
logger.warn(
`Cannot copy web assets from ${c.strong(
webRelDir,
)} to ${nativeRelDir}\n` +
`Web asset directory specified by ${c.input(
'webDir',
)} does not exist. This is not an error because ${c.input(
'server.url',
)} is set in config.`,
);

return;
}

await runTask(
`Copying web assets from ${c.strong(webRelDir)} to ${nativeRelDir}`,
async () => {
Expand Down

0 comments on commit 91ddfbd

Please sign in to comment.