Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova copy www folder to existing build

If we have only changed assets in the www/ folder of our cordova project, and have not altered any of the native code/plugins, shouldn't it be possible to have a script that just replaces the new www/ folder with the existing one in the ios build output?

That way we don't have to re-build the entire ios project using cordova build ios every time we want to make a small change and re-run in the simulator. This would save us a nice chunk of time daily.

Does anything like this exist already?

like image 432
Zachary Wand Avatar asked Nov 28 '25 07:11

Zachary Wand


2 Answers

You have three ways to archive this:

  1. Make absolute symlinks for every file or folder from your root-www-folder to your platform-www-folder. BUT don't symlink the whole www-folder and don't symlink the cordova.js file.

  2. In Xcode -> Build Phases you can put copy-shell-scripts in Copy www directory for every file or folder of your www-folder. It should look like: cp -R /absolute/path/to/your/app/www/index.html /absolute/path/to/your/app/platforms/ios/www/index.html

  3. You can use a hook. Put the following hook in hooks->after_platform_add->create_symlinks.js and in hooks->after_build->create_symlinks.js. Everytime you add a android or ios platform or build the application the hook will run.

You have to make the script executable and maybe you need to install shelljs from npm.

Here is my hook, modify it to your needs:

#!/usr/bin/env node

var what_to_symlink_from_www = [
    "assets",
    "index.html"
];

// no need to change below 

var path = require("path"),
    fs = require("fs"),
    shell = require("shelljs"),
    rootdir = process.argv[2],
    added_platform = process.env.CORDOVA_PLATFORMS,
    www = rootdir + "/www/",
    android_www = rootdir + "/platforms/android/assets/www/",
    ios_www = rootdir + "/platforms/ios/www/",
    buildnumber_file = rootdir + "/buildnumber",
    buildnumber,
    active_platform_www;

shell.echo("\r\nHook start: Symlinking");

if (added_platform === "ios") {
    active_platform_www = ios_www;
    do_job()
}
else if (added_platform === "android") {
    active_platform_www = android_www;
    do_job()
}

function do_job() {
    what_to_symlink_from_www.forEach(function (item) {
        shell.rm("-rf", active_platform_www + item);
        shell.ln("-s", www + item, active_platform_www + item);
        shell.echo("symlinked: " + item + " to " + active_platform_www);
    });
    shell.echo("Hook end: Symlinking" + "\r\n");
}
like image 88
Joerg Avatar answered Nov 29 '25 21:11

Joerg


You can just run

cordova prepare

https://cordova.apache.org/docs/en/latest/reference/cordova-cli/#www

like image 43
tanner burton Avatar answered Nov 29 '25 20:11

tanner burton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!