Skip to content

Commit

Permalink
Merge pull request #479 from wavesplatform/client-530-release
Browse files Browse the repository at this point in the history
Client 530 release
  • Loading branch information
tsigel authored Feb 19, 2018
2 parents 17f42aa + a2fa20c commit 8fcc0ae
Show file tree
Hide file tree
Showing 43 changed files with 1,003 additions and 332 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"globals": {
"Waves": true,
"BigNumber": true,
"Clipboard": true,
"identityImg": true,
"angular": true,
"jQuery": true,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
*.pfx
**/**/.DS_Store
WavesGUI.iml
/.cache-download
28 changes: 27 additions & 1 deletion electron/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { app, BrowserWindow, screen, protocol } from 'electron';
import { app, BrowserWindow, screen, protocol, Menu } from 'electron';
import { ISize, IMetaJSON } from './package';
import { format } from 'url';
import { readFile, stat, writeFile } from 'fs';
import { join } from 'path';

import BrowserWindowConstructorOptions = Electron.BrowserWindowConstructorOptions;
import MenuItemConstructorOptions = Electron.MenuItemConstructorOptions;

const CONFIG = {
META_PATH: join(app.getPath('userData'), 'meta.json'),
Expand All @@ -25,6 +26,26 @@ const CONFIG = {
}
};

const MENU_LIST: MenuItemConstructorOptions[] = [
{
label: 'Application',
submenu: [
{ label: 'Quit', accelerator: 'Command+Q', click: () => app.quit() }
]
} as MenuItemConstructorOptions, {
label: 'Edit',
submenu: [
{ label: 'Undo', accelerator: 'CmdOrCtrl+Z', selector: 'undo:' },
{ label: 'Redo', accelerator: 'Shift+CmdOrCtrl+Z', selector: 'redo:' },
{ type: 'separator' },
{ label: 'Cut', accelerator: 'CmdOrCtrl+X', selector: 'cut:' },
{ label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:' },
{ label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:' },
{ label: 'Select All', accelerator: 'CmdOrCtrl+A', selector: 'selectAll:' }
]
} as MenuItemConstructorOptions
];


class Main {

Expand All @@ -49,6 +70,10 @@ class Main {
this.mainWindow = null;
});

this.mainWindow.webContents.on('will-navigate', function (event) {
event.preventDefault();
});

const onChangeWindow = Main.asyncHandler(() => {
const [x, y] = this.mainWindow.getPosition();
const [width, height] = this.mainWindow.getSize();
Expand Down Expand Up @@ -85,6 +110,7 @@ class Main {
private onAppReady() {
this.replaceProtocol();
this.createWindow();
Menu.setApplicationMenu(Menu.buildFromTemplate(MENU_LIST));
}

private onActivate() {
Expand Down
59 changes: 31 additions & 28 deletions gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import * as concat from 'gulp-concat';
import * as babel from 'gulp-babel';
import { exec, execSync } from 'child_process';
import { download, getFilesFrom, prepareHTML, run, task } from './ts-scripts/utils';
import { join } from 'path';
import { copy as fsCopy, mkdirp, outputFile, readFile, readJSON, readJSONSync, writeFile } from 'fs-extra';
import { join, sep } from 'path';
import { copy as fsCopy, outputFile, readFile, readJSON, readJSONSync, writeFile } from 'fs-extra';
import { IMetaJSON, IPackageJSON } from './ts-scripts/interface';
import * as templateCache from 'gulp-angular-templatecache';
import * as htmlmin from 'gulp-htmlmin';

const zip = require('gulp-zip');
const s3 = require('gulp-s3');

const meta: IMetaJSON = readJSONSync('ts-scripts/meta.json');
const pack: IPackageJSON = readJSONSync('package.json');
const meta: IMetaJSON = readJSONSync(join(__dirname, 'ts-scripts', 'meta.json'));
const pack: IPackageJSON = readJSONSync(join(__dirname, 'package.json'));
const configurations = Object.keys(meta.configurations);
const AWS = {
key: process.env.AWS_ACCESS_KEY_ID,
Expand All @@ -22,7 +22,7 @@ const AWS = {
};

const SOURCE_FILES = getFilesFrom(join(__dirname, 'src'), '.js');
const IMAGE_LIST = getFilesFrom(join(__dirname, 'src/img'), ['.png', '.svg', '.jpg']);
const IMAGE_LIST = getFilesFrom(join(__dirname, 'src', 'img'), ['.png', '.svg', '.jpg']);
const JSON_LIST = getFilesFrom(join(__dirname, 'src'), '.json');

const taskHash = {
Expand All @@ -32,8 +32,8 @@ const taskHash = {
zip: []
};

const tmpJsPath = './dist/tmp/js';
const tmpCssPath = './dist/tmp/css';
const tmpJsPath = join(__dirname, 'dist', 'tmp', 'js');
const tmpCssPath = join(__dirname, 'dist', 'tmp', 'css');
const vendorName = 'vendors.js';
const bundleName = 'bundle.js';
const templatesName = 'templates.js';
Expand All @@ -49,12 +49,12 @@ const getFileName = (name, type) => {
};


const indexPromise = readFile(join(__dirname, 'src/index.html'), { encoding: 'utf8' });
const indexPromise = readFile(join(__dirname, 'src', 'index.html'), { encoding: 'utf8' });

task('load-trading-view', (done) => {
Promise.all(meta.tradingView.files.map((relativePath) => {
const url = `${meta.tradingView.domain}/${relativePath}`;
return download(url, join(__dirname, `dist/tmp/trading-view/${relativePath}`)).then(() => {
return download(url, join(__dirname, 'dist', 'tmp', 'trading-view', relativePath)).then(() => {
console.log(`Download "${relativePath}" done`);
});
})).then(() => done());
Expand All @@ -64,11 +64,9 @@ task('load-trading-view', (done) => {

configurations.forEach((configName) => {

const config = meta.configurations[configName];

['normal', 'min'].forEach((type) => {

const targetPath = `./dist/${buildName}/${configName}/${type}`;
const targetPath = join(__dirname, 'dist', buildName, configName, type);
const jsFileName = getName(`${pack.name}-${buildName}-${configName}-${pack.version}.js`);
const jsFilePath = join(targetPath, 'js', jsFileName);
const taskPostfix = `${buildName}-${configName}-${type}`;
Expand All @@ -77,14 +75,14 @@ task('load-trading-view', (done) => {
task(`concat-${taskPostfix}`, [type === 'min' ? 'uglify' : 'babel'], function (done) {
const stream = gulp.src([vendorPath, getName(bundlePath), getName(templatePath)])
.pipe(concat(jsFileName))
.pipe(gulp.dest(`${targetPath}/js`));
.pipe(gulp.dest(join(targetPath, 'js')));

stream.on('end', function () {
readFile(`${targetPath}/js/${jsFileName}`, { encoding: 'utf8' }).then((file) => {
readFile(join(targetPath, 'js', jsFileName), { encoding: 'utf8' }).then((file) => {
if (buildName === 'desktop') {
file = `(function () {\nvar module = undefined;\n${file}})();`;
}
outputFile(`${targetPath}/js/${jsFileName}`, file)
outputFile(join(targetPath, 'js', jsFileName), file)
.then(() => done());
});
});
Expand All @@ -97,27 +95,28 @@ task('load-trading-view', (done) => {
}

task(`copy-${taskPostfix}`, copyDeps, function (done) {
const reg = new RegExp(`(.*?\\${sep}src)`);
let forCopy = JSON_LIST.map((path) => {
return fsCopy(path, path.replace(/(.*?\/src)/, `${targetPath}`));
return fsCopy(path, path.replace(reg, `${targetPath}`));
}).concat(fsCopy(join(__dirname, 'src/fonts'), `${targetPath}/fonts`));

if (buildName === 'desktop') {
forCopy.push(fsCopy(join(__dirname, 'electron/main.js'), `${targetPath}/main.js`));
forCopy.push(fsCopy(join(__dirname, 'electron/package.json'), `${targetPath}/package.json`));
forCopy.push(fsCopy(join(__dirname, 'electron/icons/icon128x128.png'), `${targetPath}/img/icon.png`));
forCopy.push(fsCopy(join(__dirname, '/dist/tmp/trading-view'), `${targetPath}/trading-view`));
forCopy.push(fsCopy(join(__dirname, 'electron', 'main.js'), join(targetPath, 'main.js')));
forCopy.push(fsCopy(join(__dirname, 'electron', 'package.json'), join(targetPath, 'package.json')));
forCopy.push(fsCopy(join(__dirname, 'electron', 'icons', 'icon128x128.png'), join(targetPath, 'img', 'icon.png')));
forCopy.push(fsCopy(join(__dirname, 'dist', 'tmp', 'trading-view'), join(targetPath, 'trading-view')));
}

Promise.all([
Promise.all(meta.copyNodeModules.map((path) => {
return fsCopy(join(__dirname, path), `${targetPath}/${path}`);
})) as Promise<any>,
fsCopy(join(__dirname, 'src/img'), `${targetPath}/img`).then(() => {
const images = IMAGE_LIST.map((path) => path.replace(/(.*?\/src)/, ''));
return writeFile(`${targetPath}/img/images-list.json`, JSON.stringify(images));
const images = IMAGE_LIST.map((path) => path.replace(reg, ''));
return writeFile(join(targetPath, 'img', 'images-list.json'), JSON.stringify(images));
}),
fsCopy(cssPath, `${targetPath}/css/${cssName}`),
fsCopy('LICENSE', `${targetPath}/LICENSE`),
fsCopy(cssPath, join(targetPath, 'css', cssName)),
fsCopy('LICENSE', join(`${targetPath}`, 'LICENSE')),
].concat(forCopy)).then(() => {
done();
}, (e) => {
Expand All @@ -139,7 +138,7 @@ task('load-trading-view', (done) => {
connection: configName,
scripts: [jsFilePath],
styles: [
`${targetPath}/css/${pack.name}-styles-${pack.version}.css`
join(targetPath, 'css', `${pack.name}-styles-${pack.version}.css`)
],
type: buildName
});
Expand Down Expand Up @@ -208,7 +207,7 @@ task('templates', function () {
});

task('concat-style', ['less'], function () {
return gulp.src(meta.stylesheets.concat(join(__dirname, tmpCssPath, 'style.css')))
return gulp.src(meta.stylesheets.concat(join(tmpCssPath, 'style.css')))
.pipe(concat(cssName))
.pipe(gulp.dest(tmpCssPath));
});
Expand All @@ -234,7 +233,7 @@ task('eslint', function (done) {
});

task('less', function () {
execSync('sh scripts/less.sh');
execSync(`sh ${join('scripts', 'less.sh')}`);
});

task('babel', ['concat-develop'], function () {
Expand All @@ -252,9 +251,13 @@ task('babel', ['concat-develop'], function () {
});

task('uglify', ['babel', 'templates'], function (done) {
const PATH_HASH = {
bin: join(__dirname, 'node_modules', '.bin', 'uglifyjs'),
out: join(__dirname, 'dist', 'tmp', 'js')
};
const run = function (path, name) {
return new Promise((resolve, reject) => {
exec(`./node_modules/.bin/uglifyjs ${path} -o ./dist/tmp/js/${name}`, (err, l1, l2) => {
exec(`${PATH_HASH.bin} ${path} -o ${join(PATH_HASH.out, name)}`, (err, l1, l2) => {
if (err) {
reject(err);
} else {
Expand Down
Loading

0 comments on commit 8fcc0ae

Please sign in to comment.