Skip to content

Commit 52a44fc

Browse files
committed
Merge pull request betaflight#2109 from WalcoFPV/cordova_manifest_and_folders
Gulp cordova generation and cleaning
1 parent 71a3010 commit 52a44fc

File tree

5 files changed

+43
-29
lines changed

5 files changed

+43
-29
lines changed

.gitignore

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,11 @@ yarn-error.log*
99
cache/
1010
apps/
1111
dist/
12+
dist_cordova/
1213
debug/
1314
release/
1415
testresults/
1516

16-
# Cordova
17-
cordova/www/
18-
cordova/platforms/
19-
cordova/plugins/
20-
cordova/resources/
21-
cordova/package-lock.json
22-
2317
# OSX
2418
.DS_store
2519

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ List of possible values of `<task-name>`:
7676
* **release** zips up the apps into individual archives in the `./release` folder [1].
7777

7878
[1] Running this task on macOS or Linux requires Wine, since it's needed to set the icon for the Windows app (build for specific platform to avoid errors).
79-
[2] For Android platform, **dist** task will generate the `./cordova` folder
79+
[2] For Android platform, **dist** task will generate folders and files in the `./dist_cordova` folder.
8080
[3] For Android platform, you need to configure an emulator or to plug an Android device with USB debugging enabled
8181

8282
#### Build or release app for one specific platform
File renamed without changes.
File renamed without changes.

gulpfile.js

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const APPS_DIR = './apps/';
3838
const DEBUG_DIR = './debug/';
3939
const RELEASE_DIR = './release/';
4040
const CORDOVA_DIR = './cordova/';
41+
const CORDOVA_DIST_DIR = './dist_cordova/';
4142

4243
const LINUX_INSTALL_DIR = '/opt/betaflight';
4344

@@ -66,7 +67,7 @@ const SELECTED_PLATFORMS = getInputPlatforms();
6667
//Tasks
6768
//-----------------
6869

69-
gulp.task('clean', gulp.parallel(clean_dist, clean_apps, clean_debug, clean_release));
70+
gulp.task('clean', gulp.parallel(clean_dist, clean_apps, clean_debug, clean_release, clean_cordova));
7071

7172
gulp.task('clean-dist', clean_dist);
7273

@@ -78,7 +79,7 @@ gulp.task('clean-release', clean_release);
7879

7980
gulp.task('clean-cache', clean_cache);
8081

81-
gulp.task('clean-cordova', cordova_clean);
82+
gulp.task('clean-cordova', clean_cordova);
8283

8384
// Function definitions are processed before function calls.
8485
const getChangesetId = gulp.series(getHash, writeChangesetId);
@@ -795,11 +796,14 @@ function cordova_dist() {
795796
const distTasks = [];
796797
const platforms = getPlatforms();
797798
if (platforms.indexOf('android') !== -1) {
798-
distTasks.push(cordova_clean);
799+
distTasks.push(clean_cordova);
799800
distTasks.push(cordova_copy_www);
800801
distTasks.push(cordova_locales_www);
801802
distTasks.push(cordova_resources);
802803
distTasks.push(cordova_include_www);
804+
distTasks.push(cordova_copy_src);
805+
distTasks.push(cordova_rename_src_config);
806+
distTasks.push(cordova_rename_src_package);
803807
distTasks.push(cordova_packagejson);
804808
distTasks.push(cordova_configxml);
805809
distTasks.push(cordova_depedencies);
@@ -827,49 +831,65 @@ function cordova_apps() {
827831
}
828832

829833

830-
function cordova_clean() {
831-
const patterns = ['./cordova/www/**', './cordova/resources/**'];
834+
function clean_cordova() {
835+
const patterns = [];
832836
if (cordovaDependencies) {
833-
patterns.push('./cordova/plugins/**');
834-
patterns.push('./cordova/platforms/**');
837+
patterns.push(`${CORDOVA_DIST_DIR}**`);
838+
} else {
839+
patterns.push(`${CORDOVA_DIST_DIR}www/**`);
840+
patterns.push(`${CORDOVA_DIST_DIR}resources/**`);
835841
}
836842
return del(patterns, { force: true });
837843
}
838844
function cordova_copy_www() {
839845
return gulp.src(`${DIST_DIR}**`, { base: DIST_DIR })
840-
.pipe(gulp.dest(`${CORDOVA_DIR}www/`));
846+
.pipe(gulp.dest(`${CORDOVA_DIST_DIR}www/`));
841847
}
842848
function cordova_locales_www(cb) {
843-
fs.renameSync(`${CORDOVA_DIR}www/_locales`, `${CORDOVA_DIR}www/i18n`);
844-
gulp.src(`${CORDOVA_DIR}www/js/localization.js`)
849+
fs.renameSync(`${CORDOVA_DIST_DIR}www/_locales`, `${CORDOVA_DIST_DIR}www/i18n`);
850+
gulp.src(`${CORDOVA_DIST_DIR}www/js/localization.js`)
845851
.pipe(replace('/_locales', './i18n'))
846-
.pipe(gulp.dest(`${CORDOVA_DIR}www/js`));
852+
.pipe(gulp.dest(`${CORDOVA_DIST_DIR}www/js`));
847853
cb();
848854
}
849855
function cordova_resources() {
850856
return gulp.src('assets/android/**')
851-
.pipe(gulp.dest(`${CORDOVA_DIR}resources/android/`));
857+
.pipe(gulp.dest(`${CORDOVA_DIST_DIR}resources/android/`));
852858
}
853859
function cordova_include_www() {
854-
return gulp.src(`${CORDOVA_DIR}www/main.html`)
860+
return gulp.src(`${CORDOVA_DIST_DIR}www/main.html`)
855861
.pipe(replace('<!-- CORDOVA_INCLUDE js/cordova_chromeapi.js -->', '<script type="text/javascript" src="./js/cordova_chromeapi.js"></script>'))
856862
.pipe(replace('<!-- CORDOVA_INCLUDE js/cordova_startup.js -->', '<script type="text/javascript" src="./js/cordova_startup.js"></script>'))
857863
.pipe(replace('<!-- CORDOVA_INCLUDE cordova.js -->', '<script type="text/javascript" src="cordova.js"></script>'))
858-
.pipe(gulp.dest(`${CORDOVA_DIR}www`));
864+
.pipe(gulp.dest(`${CORDOVA_DIST_DIR}www`));
865+
}
866+
function cordova_copy_src() {
867+
return gulp.src([`${CORDOVA_DIR}**`, `!${CORDOVA_DIR}config_template.xml`, `!${CORDOVA_DIR}package_template.json`])
868+
.pipe(gulp.dest(`${CORDOVA_DIST_DIR}`));
869+
}
870+
function cordova_rename_src_config() {
871+
return gulp.src(`${CORDOVA_DIR}config_template.xml`)
872+
.pipe(rename('config.xml'))
873+
.pipe(gulp.dest(`${CORDOVA_DIST_DIR}`));
874+
}
875+
function cordova_rename_src_package() {
876+
return gulp.src(`${CORDOVA_DIR}package_template.json`)
877+
.pipe(rename('package.json'))
878+
.pipe(gulp.dest(`${CORDOVA_DIST_DIR}`));
859879
}
860880
function cordova_packagejson() {
861-
return gulp.src(`${CORDOVA_DIR}package.json`)
881+
return gulp.src(`${CORDOVA_DIST_DIR}package.json`)
862882
.pipe(jeditor({
863883
'name': pkg.name,
864884
'description': pkg.description,
865885
'version': pkg.version,
866886
'author': pkg.author,
867887
'license': pkg.license,
868888
}))
869-
.pipe(gulp.dest(CORDOVA_DIR));
889+
.pipe(gulp.dest(CORDOVA_DIST_DIR));
870890
}
871891
function cordova_configxml() {
872-
return gulp.src([`${CORDOVA_DIR}config.xml`])
892+
return gulp.src([`${CORDOVA_DIST_DIR}config.xml`])
873893
.pipe(xmlTransformer([
874894
{ path: '//xmlns:name', text: pkg.productName },
875895
{ path: '//xmlns:description', text: pkg.description },
@@ -878,10 +898,10 @@ function cordova_configxml() {
878898
.pipe(xmlTransformer([
879899
{ path: '.', attr: { 'version': pkg.version } },
880900
]))
881-
.pipe(gulp.dest(CORDOVA_DIR));
901+
.pipe(gulp.dest(CORDOVA_DIST_DIR));
882902
}
883903
function cordova_depedencies() {
884-
process.chdir('cordova');
904+
process.chdir('dist_cordova');
885905
return gulp.src(['./package.json', './yarn.lock'])
886906
.pipe(gulp.dest('./'))
887907
.pipe(yarn({
@@ -905,12 +925,12 @@ function cordova_build(cb) {
905925
process.chdir('../');
906926
cb();
907927
});
908-
console.log('APK will be generated at cordova/platforms/android/app/build/outputs/apk/release/app-release.apk');
928+
console.log('APK will be generated at dist_cordova/platforms/android/app/build/outputs/apk/release/app-release.apk');
909929
}
910930
async function cordova_release() {
911931
const filename = await getReleaseFilename('android', 'apk');
912932
console.log(`Release APK : release/${filename}`);
913-
return gulp.src(`${CORDOVA_DIR}platforms/android/app/build/outputs/apk/release/app-release.apk`)
933+
return gulp.src(`${CORDOVA_DIST_DIR}platforms/android/app/build/outputs/apk/release/app-release.apk`)
914934
.pipe(rename(filename))
915935
.pipe(gulp.dest(RELEASE_DIR));
916936
}

0 commit comments

Comments
 (0)