Skip to content

Commit

Permalink
fix(build): Fix build webpack scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
pcholuj committed Apr 7, 2020
1 parent 9639988 commit 37b2617
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 21 deletions.
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"build:main": "npx gulp typescript:main",
"build:module": "npx gulp typescript:module",
"build:check": "node scripts/check.js",
"webpack": "npx webpack",
"webpack": "npx gulp build:webpack",
"webpack:profile": "npx webpack --profile --json > .stats.json",
"webpack:analyze": "npm run webpack:profile && npx webpack-bundle-analyzer .stats.json build/browser/",
"lint": "tslint -p tsconfig.tslint.json",
Expand Down Expand Up @@ -105,6 +105,7 @@
"webpack-bundle-analyzer": "^3.6.1",
"webpack-cli": "^3.3.10",
"webpack-node-externals": "^1.7.2",
"webpack-stream": "^5.2.1",
"webpack-subresource-integrity": "^1.4.0"
},
"keywords": [
Expand Down
32 changes: 31 additions & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const replace = require('gulp-replace');
const del = require('del');
const version = require('../package.json').version;
const sourcemaps = require('gulp-sourcemaps');
const webpack = require('webpack-stream');
const webpackCfg = require('./../webpack.config.js') ;

const WEBPACK_DEST = 'build/browser';

gulp.task('build:clean', function () {
return del([
Expand Down Expand Up @@ -31,6 +35,32 @@ gulp.task('typescript:modules', () => {
.pipe(gulp.dest('build/module'));
});

gulp.task('build:webpack:umd', () => {
const conf = webpackCfg.umd;
console.log();
return gulp.src(conf.entry)
.pipe(webpack(conf))
.pipe(gulp.dest(conf.output.path));
});

gulp.task('build:webpack:esm', () => {
const conf = webpackCfg.esm;

return gulp.src(conf.entry)
.pipe(webpack(conf))
.pipe(gulp.dest(conf.output.path));
});

gulp.task('build:webpack:prod', () => {
const conf = webpackCfg.prod;

return gulp.src(conf.entry)
.pipe(webpack(conf))
.pipe(gulp.dest(conf.output.path));
});

gulp.task('build:webpack', gulp.series(['build:webpack:umd', 'build:webpack:esm', 'build:webpack:prod']));

gulp.task('build:typescript', gulp.series(['build:clean', 'typescript:main', 'typescript:modules']));

gulp.task('build', gulp.series(['build:typescript']));
gulp.task('build', gulp.series(['build:typescript', 'build:webpack']));
38 changes: 21 additions & 17 deletions src/lib/api/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,9 @@ export class CloudClient {
*/
private _token: string;

/**
* Flag for in-app browser setup
* (in-app browsers are not supporting new window so we need to save token to session cache)
*
* @private
* @memberof CloudClient
*/
private _isInAppBrowser = false;

constructor(session: Session, options?: ClientOptions) {
this.session = session;

if (this.session.prefetch && this.session.prefetch.settings && this.session.prefetch.settings.inapp_browser) {
this._isInAppBrowser = this.session.prefetch.settings.inapp_browser;
}

this.cloudApiUrl = session.urls.cloudApiUrl;

if (options && options.sessionCache) {
Expand All @@ -86,7 +73,7 @@ export class CloudClient {
if (token) return token;
}

if (this._isInAppBrowser) {
if (this.isInAppBrowser) {
return sessionStorage.getItem(PICKER_KEY);
}

Expand All @@ -98,13 +85,30 @@ export class CloudClient {
localStorage.setItem(PICKER_KEY, key);
}

if (this._isInAppBrowser) {
if (this.isInAppBrowser) {
sessionStorage.setItem(PICKER_KEY, key);
}

this._token = key;
}

/**
* Return information is inappbrowser flag is set
*
* @readonly
* @memberof CloudClient
*/
private get isInAppBrowser() {
if (this.session
&& this.session.prefetch
&& this.session.prefetch.settings
&& this.session.prefetch.settings.inapp_browser) {
return this.session.prefetch.settings.inapp_browser;
}

return false;
}

list(clouds: any, cancelTokenInput?: any) {
const payload: any = {
apikey: this.session.apikey,
Expand All @@ -113,7 +117,7 @@ export class CloudClient {
token: this.token,
};

if (this._isInAppBrowser) {
if (this.isInAppBrowser) {
payload.appurl = this.currentAppUrl();
}

Expand Down Expand Up @@ -206,7 +210,7 @@ export class CloudClient {
localStorage.removeItem(PICKER_KEY);
}

if (this._isInAppBrowser) {
if (this.isInAppBrowser) {
sessionStorage.removeItem(PICKER_KEY);
}
}
Expand Down
4 changes: 2 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const config = {
new webpack.BannerPlugin({ banner }),
new webpack.DefinePlugin({
'process.env.NODE_ENV': 'production',
'@{VERSION}' : `${require("./package.json").version}`,
'@{VERSION}' : `${require('./package.json').version}`,
}),
new webpack.NormalModuleReplacementPlugin(/^.*\.node\.js$/, (result) => {
if (result.resource) {
Expand Down Expand Up @@ -87,4 +87,4 @@ const prod = merge({}, config, {
],
});

module.exports = [umd, esm, prod];
module.exports = { umd, esm, prod };

0 comments on commit 37b2617

Please sign in to comment.