1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-23 16:38:45 +01:00

switch to webpack

This commit is contained in:
Kyle Spearrin 2018-05-14 23:16:59 -04:00
parent 55ebf3ac64
commit ec049edfdf
9 changed files with 4319 additions and 58 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
node_modules node_modules
build
dist

4236
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,20 +15,35 @@
"url": "https://github.com/bitwarden/cli" "url": "https://github.com/bitwarden/cli"
}, },
"license": "GPL-3.0", "license": "GPL-3.0",
"scripts": {}, "scripts": {
"clean": "rimraf dist/**/*",
"build": "webpack --config webpack.config.js",
"build:watch": "webpack --config webpack.config.js --watch",
"build:prod": "cross-env NODE_ENV=production webpack --config webpack.config.js",
"build:prod:watch": "cross-env NODE_ENV=production webpack --config webpack.config.js --watch",
"lint": "tslint src/**/*.ts spec/**/*.ts || true",
"lint:fix": "tslint src/**/*.ts spec/**/*.ts --fix"
},
"bin": { "bin": {
"bw": "./src/bw.js" "bw": "./bw.js"
}, },
"devDependencies": { "devDependencies": {
"@types/commander": "^2.12.2", "@types/commander": "^2.12.2",
"@types/node": "^10.0.8" "@types/node": "^10.0.8",
"clean-webpack-plugin": "^0.1.17",
"copy-webpack-plugin": "^4.2.0",
"cross-env": "^5.1.4",
"ts-loader": "^3.5.0",
"tslint": "^5.9.1",
"tslint-loader": "^3.5.3",
"ts-node": "^6.0.3",
"typescript": "^2.7.1",
"webpack": "^3.10.0"
}, },
"dependencies": { "dependencies": {
"commander": "^2.15.1", "commander": "^2.15.1",
"node-fetch": "2.1.2", "node-fetch": "2.1.2",
"node-localstorage": "1.3.1", "node-forge": "0.7.1",
"tsconfig-paths": "3.3.2", "node-localstorage": "1.3.1"
"ts-node": "6.0.3",
"typescript": "^2.7.1"
} }
} }

View File

@ -1,6 +0,0 @@
#!/usr/bin/env node
require('tsconfig-paths').register();
require('ts-node').register();
const main = require('./main.ts');
new main.Main().run();

View File

@ -57,7 +57,7 @@ export class Main {
program: Program; program: Program;
constructor() { constructor() {
this.i18nService = new I18nService('en', '../locales'); this.i18nService = new I18nService('en', './locales');
this.platformUtilsService = new NodePlatformUtilsService(); this.platformUtilsService = new NodePlatformUtilsService();
this.cryptoFunctionService = new NodeCryptoFunctionService(); this.cryptoFunctionService = new NodeCryptoFunctionService();
this.storageService = new NodeStorageService('Bitwarden CLI'); this.storageService = new NodeStorageService('Bitwarden CLI');
@ -89,6 +89,11 @@ export class Main {
this.program = new Program(this); this.program = new Program(this);
} }
async run() {
await this.init();
this.program.run();
}
private async init() { private async init() {
this.containerService.attachToWindow(global); this.containerService.attachToWindow(global);
await this.environmentService.setUrlsFromStorage(); await this.environmentService.setUrlsFromStorage();
@ -96,13 +101,7 @@ export class Main {
await this.i18nService.init(locale); await this.i18nService.init(locale);
await this.authService.init(); await this.authService.init();
} }
async run() {
await this.init();
this.program.run();
}
} }
if (process.env.NODE_ENV === 'debug') { const main = new Main();
new Main().run(); main.run();
}

View File

@ -1,13 +1,13 @@
import * as program from 'commander'; import * as program from 'commander';
import { Main } from './bw';
import { DeleteCommand } from './commands/delete.command'; import { DeleteCommand } from './commands/delete.command';
import { GetCommand } from './commands/get.command'; import { GetCommand } from './commands/get.command';
import { ListCommand } from './commands/list.command'; import { ListCommand } from './commands/list.command';
import { LoginCommand } from './commands/login.command'; import { LoginCommand } from './commands/login.command';
import { SyncCommand } from './commands/sync.command'; import { SyncCommand } from './commands/sync.command';
import { Main } from './main';
import { Response } from './models/response'; import { Response } from './models/response';
import { CreateCommand } from './commands/create.command'; import { CreateCommand } from './commands/create.command';
import { EncodeCommand } from './commands/encode.command'; import { EncodeCommand } from './commands/encode.command';

View File

@ -13,7 +13,7 @@ export class I18nService extends BaseI18nService {
}); });
this.supportedTranslationLocales = [ this.supportedTranslationLocales = [
'en' 'en',
]; ];
} }
} }

View File

@ -2,8 +2,8 @@
"compilerOptions": { "compilerOptions": {
"pretty": true, "pretty": true,
"moduleResolution": "node", "moduleResolution": "node",
"target": "ES6", "target": "ES2016",
"module": "commonjs", "module": "es6",
"noImplicitAny": true, "noImplicitAny": true,
"allowJs": true, "allowJs": true,
"sourceMap": true, "sourceMap": true,
@ -24,8 +24,7 @@
"jslib/dist", "jslib/dist",
"jslib/spec", "jslib/spec",
"jslib/src/electron", "jslib/src/electron",
"jslib/src/angular/components/modal.component.ts", "jslib/src/angular",
"jslib/src/angular/dummy.module.ts",
"build" "build"
] ]
} }

74
webpack.config.js Normal file
View File

@ -0,0 +1,74 @@
const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
if (process.env.NODE_ENV == null) {
process.env.NODE_ENV = 'development';
}
const ENV = process.env.ENV = process.env.NODE_ENV;
const isVendorModule = (module) => {
if (!module.context) {
return false;
}
return module.context.indexOf('node_modules') !== -1;
};
const moduleRules = [
{
test: /\.ts$/,
enforce: 'pre',
loader: 'tslint-loader',
},
{
test: /\.ts$/,
loaders: ['ts-loader'],
exclude: path.resolve(__dirname, 'node_modules'),
},
];
const plugins = [
new CleanWebpackPlugin([
path.resolve(__dirname, 'build/*'),
]),
new CopyWebpackPlugin([
'./package.json',
{ from: './src/locales', to: 'locales' },
]),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(ENV),
'process.env.DEBUG': JSON.stringify(process.env.DEBUG),
}),
new webpack.BannerPlugin({
banner: '#!/usr/bin/env node',
raw: true
}),
];
const config = {
target: 'node',
node: {
__dirname: false,
__filename: false,
},
entry: {
'bw': './src/bw.ts',
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
jslib: path.join(__dirname, 'jslib/src'),
},
symlinks: false,
modules: [path.resolve('node_modules')],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'build'),
},
module: { rules: moduleRules },
plugins: plugins,
};
module.exports = config;