Skip to content

Commit 312cbb5

Browse files
authored
Merge pull request #2109 from WalcoFPV/cordova_manifest_and_folders
Gulp cordova generation and cleaning
2 parents b9137a6 + 9f323f2 commit 312cbb5

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);
@@ -794,11 +795,14 @@ function cordova_dist() {
794795
const distTasks = [];
795796
const platforms = getPlatforms();
796797
if (platforms.indexOf('android') !== -1) {
797-
distTasks.push(cordova_clean);
798+
distTasks.push(clean_cordova);
798799
distTasks.push(cordova_copy_www);
799800
distTasks.push(cordova_locales_www);
800801
distTasks.push(cordova_resources);
801802
distTasks.push(cordova_include_www);
803+
distTasks.push(cordova_copy_src);
804+
distTasks.push(cordova_rename_src_config);
805+
distTasks.push(cordova_rename_src_package);
802806
distTasks.push(cordova_packagejson);
803807
distTasks.push(cordova_configxml);
804808
distTasks.push(cordova_depedencies);
@@ -826,49 +830,65 @@ function cordova_apps() {
826830
}
827831

828832

829-
function cordova_clean() {
830-
const patterns = ['./cordova/www/**', './cordova/resources/**'];
833+
function clean_cordova() {
834+
const patterns = [];
831835
if (cordovaDependencies) {
832-
patterns.push('./cordova/plugins/**');
833-
patterns.push('./cordova/platforms/**');
836+
patterns.push(`${CORDOVA_DIST_DIR}**`);
837+
} else {
838+
patterns.push(`${CORDOVA_DIST_DIR}www/**`);
839+
patterns.push(`${CORDOVA_DIST_DIR}resources/**`);
834840
}
835841
return del(patterns, { force: true });
836842
}
837843
function cordova_copy_www() {
838844
return gulp.src(`${DIST_DIR}**`, { base: DIST_DIR })
839-
.pipe(gulp.dest(`${CORDOVA_DIR}www/`));
845+
.pipe(gulp.dest(`${CORDOVA_DIST_DIR}www/`));
840846
}
841847
function cordova_locales_www(cb) {
842-
fs.renameSync(`${CORDOVA_DIR}www/_locales`, `${CORDOVA_DIR}www/i18n`);
843-
gulp.src(`${CORDOVA_DIR}www/js/localization.js`)
848+
fs.renameSync(`${CORDOVA_DIST_DIR}www/_locales`, `${CORDOVA_DIST_DIR}www/i18n`);
849+
gulp.src(`${CORDOVA_DIST_DIR}www/js/localization.js`)
844850
.pipe(replace('/_locales', './i18n'))
845-
.pipe(gulp.dest(`${CORDOVA_DIR}www/js`));
851+
.pipe(gulp.dest(`${CORDOVA_DIST_DIR}www/js`));
846852
cb();
847853
}
848854
function cordova_resources() {
849855
return gulp.src('assets/android/**')
850-
.pipe(gulp.dest(`${CORDOVA_DIR}resources/android/`));
856+
.pipe(gulp.dest(`${CORDOVA_DIST_DIR}resources/android/`));
851857
}
852858
function cordova_include_www() {
853-
return gulp.src(`${CORDOVA_DIR}www/main.html`)
859+
return gulp.src(`${CORDOVA_DIST_DIR}www/main.html`)
854860
.pipe(replace('<!-- CORDOVA_INCLUDE js/cordova_chromeapi.js -->', '<script type="text/javascript" src="./js/cordova_chromeapi.js"></script>'))
855861
.pipe(replace('<!-- CORDOVA_INCLUDE js/cordova_startup.js -->', '<script type="text/javascript" src="./js/cordova_startup.js"></script>'))
856862
.pipe(replace('<!-- CORDOVA_INCLUDE cordova.js -->', '<script type="text/javascript" src="cordova.js"></script>'))
857-
.pipe(gulp.dest(`${CORDOVA_DIR}www`));
863+
.pipe(gulp.dest(`${CORDOVA_DIST_DIR}www`));
864+
}
865+
function cordova_copy_src() {
866+
return gulp.src([`${CORDOVA_DIR}**`, `!${CORDOVA_DIR}config_template.xml`, `!${CORDOVA_DIR}package_template.json`])
867+
.pipe(gulp.dest(`${CORDOVA_DIST_DIR}`));
868+
}
869+
function cordova_rename_src_config() {
870+
return gulp.src(`${CORDOVA_DIR}config_template.xml`)
871+
.pipe(rename('config.xml'))
872+
.pipe(gulp.dest(`${CORDOVA_DIST_DIR}`));
873+
}
874+
function cordova_rename_src_package() {
875+
return gulp.src(`${CORDOVA_DIR}package_template.json`)
876+
.pipe(rename('package.json'))
877+
.pipe(gulp.dest(`${CORDOVA_DIST_DIR}`));
858878
}
859879
function cordova_packagejson() {
860-
return gulp.src(`${CORDOVA_DIR}package.json`)
880+
return gulp.src(`${CORDOVA_DIST_DIR}package.json`)
861881
.pipe(jeditor({
862882
'name': pkg.name,
863883
'description': pkg.description,
864884
'version': pkg.version,
865885
'author': pkg.author,
866886
'license': pkg.license,
867887
}))
868-
.pipe(gulp.dest(CORDOVA_DIR));
888+
.pipe(gulp.dest(CORDOVA_DIST_DIR));
869889
}
870890
function cordova_configxml() {
871-
return gulp.src([`${CORDOVA_DIR}config.xml`])
891+
return gulp.src([`${CORDOVA_DIST_DIR}config.xml`])
872892
.pipe(xmlTransformer([
873893
{ path: '//xmlns:name', text: pkg.productName },
874894
{ path: '//xmlns:description', text: pkg.description },
@@ -877,10 +897,10 @@ function cordova_configxml() {
877897
.pipe(xmlTransformer([
878898
{ path: '.', attr: { 'version': pkg.version } },
879899
]))
880-
.pipe(gulp.dest(CORDOVA_DIR));
900+
.pipe(gulp.dest(CORDOVA_DIST_DIR));
881901
}
882902
function cordova_depedencies() {
883-
process.chdir('cordova');
903+
process.chdir('dist_cordova');
884904
return gulp.src(['./package.json', './yarn.lock'])
885905
.pipe(gulp.dest('./'))
886906
.pipe(yarn({
@@ -904,12 +924,12 @@ function cordova_build(cb) {
904924
process.chdir('../');
905925
cb();
906926
});
907-
console.log('APK will be generated at cordova/platforms/android/app/build/outputs/apk/release/app-release.apk');
927+
console.log('APK will be generated at dist_cordova/platforms/android/app/build/outputs/apk/release/app-release.apk');
908928
}
909929
async function cordova_release() {
910930
const filename = await getReleaseFilename('android', 'apk');
911931
console.log(`Release APK : release/${filename}`);
912-
return gulp.src(`${CORDOVA_DIR}platforms/android/app/build/outputs/apk/release/app-release.apk`)
932+
return gulp.src(`${CORDOVA_DIST_DIR}platforms/android/app/build/outputs/apk/release/app-release.apk`)
913933
.pipe(rename(filename))
914934
.pipe(gulp.dest(RELEASE_DIR));
915935
}

0 commit comments

Comments
 (0)