Skip to content

Commit

Permalink
optimized the package.json import
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshrvel committed Jan 14, 2019
1 parent d4e6f09 commit 0f4b42d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/constants/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const APP_TITLE = `${description}`;

export const APP_IDENTIFIER = `${name}`;

export const APP_GITHUB_URL = repository.url.replace(/.git$/, '');
export const APP_GITHUB_URL = repository.url.replace(/^git\+|\.git/g, '');

export const APP_GITHUB_RELEASES_URL = `${APP_GITHUB_URL}/releases`;

Expand Down
25 changes: 24 additions & 1 deletion app/utils/pkginfo.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
'use strict';

module.exports.pkginfo = require('../../package.json');
let _pkginfo = {};

// eslint-disable-next-line no-undef
if (typeof PKG_INFO !== 'undefined' && PKG_INFO !== null) {
// eslint-disable-next-line no-undef
_pkginfo = PKG_INFO;
} else {
_pkginfo = {
version: process.env.npm_package_version,
productName: process.env.npm_package_productName,
description: process.env.npm_package_description,
name: process.env.npm_package_name,
author: {
name: process.env.npm_package_author_name,
email: process.env.npm_package_author_email
},
repository: {
url: process.env.npm_package_repository_url
},
homepage: process.env.npm_package_homepage
};
}

export const pkginfo = _pkginfo;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/ganeshrvel/openmtp.git"
"url": "git+https://github.com/ganeshrvel/openmtp.git"
},
"author": {
"name": "Ganesh Rathinavel",
Expand Down
17 changes: 14 additions & 3 deletions webpack/config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import path from 'path';
import webpack from 'webpack';
import { PATHS } from '../app/utils/paths';
import { pkginfo } from '../app/utils/pkginfo';

const pkg = require('../package.json');

export default {
externals: [...Object.keys(JSON.stringify(pkginfo.dependencies) || {})],
externals: [...Object.keys(pkg.dependencies || {})],

module: {
rules: [
Expand Down Expand Up @@ -51,7 +52,17 @@ export default {
NODE_ENV: 'production'
}),

new webpack.DefinePlugin({}),
new webpack.DefinePlugin({
PKG_INFO: {
productName: JSON.stringify(pkg.productName),
description: JSON.stringify(pkg.description),
name: JSON.stringify(pkg.name),
author: JSON.stringify(pkg.author),
version: JSON.stringify(pkg.version),
repository: JSON.stringify(pkg.repository),
homepage: JSON.stringify(pkg.homepage)
}
}),

new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),

Expand Down
5 changes: 3 additions & 2 deletions webpack/config.renderer.dev.dll.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import path from 'path';
import merge from 'webpack-merge';
import baseConfig from './config.base';
import { PATHS } from '../app/utils/paths';
import { pkginfo } from '../app/utils/pkginfo';

const pkg = require('../package.json');

const dll = path.join(PATHS.root, 'dll');

Expand All @@ -28,7 +29,7 @@ export default merge.smart(baseConfig, {
module: require('./config.renderer.dev.babel').default.module,

entry: {
renderer: Object.keys(JSON.stringify(pkginfo.dependencies) || {})
renderer: Object.keys(pkg.dependencies || {})
},

output: {
Expand Down

0 comments on commit 0f4b42d

Please sign in to comment.