Skip to content

Commit

Permalink
Gulp fails randomly.
Browse files Browse the repository at this point in the history
Streams do not return a promise. Thus gulp can not wait for them.

closes 233
  • Loading branch information
thsmi committed Apr 12, 2020
1 parent 88e2178 commit e6fbcb7
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 57 deletions.
87 changes: 58 additions & 29 deletions gulp/gulpfile.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,95 +17,123 @@ const path = require('path');
const BUILD_DIR_APP = path.join(common.BASE_DIR_BUILD, "electron/resources");
const BASE_DIR_APP = "./src/app/";

const WIN_ARCH = "x64";
const WIN_PLATFORM = "win32";
const LINUX_ARCH = "x64";
const LINUX_PLATFORM = "linux";
const MAC_ARCH = "x64";
const MAC_PLATFORM = "mas";

/**
* Copies and updates the package.json inside the build directory.
* It is typically used by other tools like the electron-packager.
*
* @returns {Stream}
* a stream to be consumed by gulp
*/
async function packageDefinition() {
function packageDefinition() {

"use strict";

const BASE_PATH = ".";

await src([
return src([
BASE_PATH + "/package.json"
], { base: BASE_PATH }).pipe(dest(BUILD_DIR_APP));
}

/**
* Copies the license file into the build directory.
*
* @returns {Stream}
* a stream to be consumed by gulp
*/
async function packageLicense() {
function packageLicense() {
"use strict";

await src([
return src([
"./LICENSE.md"
]).pipe(dest(BUILD_DIR_APP));
}


/**
* Copies the jquery sources into the build directory.
*
* @returns {Stream}
* a stream to be consumed by gulp
*/
async function packageJQuery() {
function packageJQuery() {
"use strict";

await common.packageJQuery(
return common.packageJQuery(
BUILD_DIR_APP + "/libs/jquery");
}

/**
* Copies the codemirror sources into the build directory.
*
* @returns {Stream}
* a stream to be consumed by gulp
*/
async function packageCodeMirror() {
function packageCodeMirror() {
"use strict";

await common.packageCodeMirror(
return common.packageCodeMirror(
`${BUILD_DIR_APP}/libs/CodeMirror`);
}

/**
* Copies the bootstrap sources into the build directory.
*
* @returns {Stream}
* a stream to be consumed by gulp
**/
async function packageBootstrap() {
function packageBootstrap() {
"use strict";

await common.packageBootstrap(
return common.packageBootstrap(
`${BUILD_DIR_APP}/libs/bootstrap`);
}

/**
* Copies the material design icons into the build directory.
*
* @returns {Stream}
* a stream to be consumed by gulp
*/
async function packageMaterialIcons() {
function packageMaterialIcons() {
"use strict";

await common.packageMaterialIcons(
return common.packageMaterialIcons(
`${BUILD_DIR_APP}/libs/material-icons`);
}

/**
* Copies the source files into the app/ directory...
*
* @returns {Stream}
* a stream to be consumed by gulp
*/
async function packageSrc() {
function packageSrc() {
"use strict";

await src([
return src([
BASE_DIR_APP + "/**"
]).pipe(dest(BUILD_DIR_APP));
}

/**
* The common files need to go into the app/lib directory...
*
* @returns {Stream}
* a stream to be consumed by gulp
*/
async function packageCommon() {
function packageCommon() {
"use strict";

await src([
return src([
common.BASE_DIR_COMMON + "/**",
// Filter out the editor wrapper
"!" + common.BASE_DIR_COMMON + "/editor",
"!" + common.BASE_DIR_COMMON + "/editor/**",
// Filter out the rfc documents
"!" + common.BASE_DIR_COMMON + "/libSieve/**/rfc*.txt",
"!" + common.BASE_DIR_COMMON + "/libSieve/**/tests/",
Expand All @@ -121,8 +149,8 @@ async function packageWin32() {

const options = {
dir: BUILD_DIR_APP,
arch: "ia32",
platform: "win32",
arch: WIN_ARCH,
platform: WIN_PLATFORM,
download: {
cacheRoot: path.join(common.BASE_DIR_BUILD, "/electron/cache")
},
Expand All @@ -144,8 +172,8 @@ async function packageLinux() {

const options = {
dir: BUILD_DIR_APP,
arch: "x64",
platform: "linux",
arch: LINUX_ARCH,
platform: LINUX_PLATFORM,
download: {
cache: path.join(common.BASE_DIR_BUILD, "/electron/cache")
},
Expand All @@ -168,8 +196,8 @@ async function packageMacOS() {

const options = {
dir: BUILD_DIR_APP,
arch: "x64",
platform: "mas",
arch: MAC_ARCH,
platform: MAC_PLATFORM,
download: {
cache: path.join(common.BASE_DIR_BUILD, "/electron/cache")
},
Expand All @@ -187,6 +215,7 @@ async function packageMacOS() {
/**
* Updates the addons version.
*/
// eslint-disable-next-line require-await
async function updateVersion() {
"use strict";

Expand Down Expand Up @@ -224,8 +253,8 @@ async function zipWin32() {

const version = (await common.getPackageVersion()).join(".");

const source = path.resolve(path.join(common.BASE_DIR_BUILD, "/electron/out/sieve-win32-ia32"));
const destination = path.join(common.BASE_DIR_BUILD, `sieve-${version}-win32-ia32.zip`);
const source = path.resolve(path.join(common.BASE_DIR_BUILD, `/electron/out/sieve-${WIN_PLATFORM}-${WIN_ARCH}`));
const destination = path.join(common.BASE_DIR_BUILD, `sieve-${version}-${WIN_PLATFORM}-${WIN_ARCH}.zip`);

await common.compress(source, destination);
}
Expand All @@ -238,8 +267,8 @@ async function zipLinux() {

const version = (await common.getPackageVersion()).join(".");

const source = path.resolve(path.join(common.BASE_DIR_BUILD, "/electron/out/sieve-linux-x64"));
const destination = path.join(common.BASE_DIR_BUILD, `sieve-${version}-linux-x64.zip`);
const source = path.resolve(path.join(common.BASE_DIR_BUILD, `/electron/out/sieve-${LINUX_PLATFORM}-${LINUX_ARCH}`));
const destination = path.join(common.BASE_DIR_BUILD, `sieve-${version}-${LINUX_PLATFORM}-${LINUX_ARCH}.zip`);

const options = {
permissions: {
Expand Down
36 changes: 25 additions & 11 deletions gulp/gulpfile.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const INDEX_PATCH = 2;
async function deleteRecursive(dir) {
"use strict";

if (! existsSync(dir))
if (!existsSync(dir))
return;

const items = await readdir(dir, { withFileTypes: true });
Expand Down Expand Up @@ -73,11 +73,14 @@ async function clean() {
*
* @param {string} destination
* where to place the jquery sources
*
* @returns {Stream}
* a stream to be consumed by gulp
*/
async function packageJQuery(destination) {
function packageJQuery(destination) {
"use strict";

await src([
return src([
BASE_DIR_JQUERY + "/jquery.min.js"
], { base: BASE_DIR_JQUERY }).pipe(
dest(destination));
Expand All @@ -88,11 +91,14 @@ async function packageJQuery(destination) {
*
* @param {string} destination
* where to place the codemirror sources
*
* @returns {Stream}
* a stream to be consumed by gulp
*/
async function packageCodeMirror(destination) {
function packageCodeMirror(destination) {
"use strict";

await src([
return src([
BASE_DIR_CODEMIRROR + "/addon/edit/**",
BASE_DIR_CODEMIRROR + "/addon/search/**",
BASE_DIR_CODEMIRROR + "/lib/**",
Expand All @@ -109,11 +115,14 @@ async function packageCodeMirror(destination) {
*
* @param {string} destination
* where to place the bootstrap sources
*
* @returns {Stream}
* a stream to be consumed by gulp
**/
async function packageBootstrap(destination) {
function packageBootstrap(destination) {
"use strict";

await src([
return src([
BASE_DIR_BOOTSTRAP + "/css/*.min.css",
BASE_DIR_BOOTSTRAP + "/js/*.bundle.min.js"
], { base: BASE_DIR_BOOTSTRAP }).pipe(
Expand All @@ -125,11 +134,14 @@ async function packageBootstrap(destination) {
*
* @param {string} destination
* where to place the material design sources
*
* @returns {Stream}
* a stream to be consumed by gulp
*/
async function packageMaterialIcons(destination) {
function packageMaterialIcons(destination) {
"use strict";

await src([
return src([
BASE_DIR_MATERIALICONS + "/material-design-icons.css",
BASE_DIR_MATERIALICONS + "/fonts/MaterialIcons-Regular.woff2"
], { base: BASE_DIR_MATERIALICONS }).pipe(dest(destination));
Expand Down Expand Up @@ -279,7 +291,7 @@ async function compressDirectory(zip, dir, options) {

if (item.isDirectory()) {
zip.addEmptyDirectory(metaPath);
compressDirectory(zip, realPath, options);
await compressDirectory(zip, realPath, options);
continue;
}

Expand Down Expand Up @@ -323,12 +335,14 @@ async function compress(source, destination, options) {
await unlink(destination);
}

logger.info(`Compressing ${path.basename(destination)}`);
logger.info(`Collecting files ${source}`);

const zip = new yazl.ZipFile();

await compressDirectory(zip, source, options);

logger.info(`Compressing files ${path.basename(destination)}`);

await new Promise((resolve) => {
zip.outputStream
.pipe(createWriteStream(destination))
Expand Down
Loading

1 comment on commit e6fbcb7

@thsmi
Copy link
Owner Author

@thsmi thsmi commented on e6fbcb7 Apr 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.