Skip to content

Commit

Permalink
Merge pull request #22 from ci010/beta
Browse files Browse the repository at this point in the history
Not yet Beta

Former-commit-id: 7416b03
  • Loading branch information
ci010 authored Jun 22, 2019
2 parents 94bb008 + 2ebe59c commit 790924b
Show file tree
Hide file tree
Showing 164 changed files with 5,261 additions and 4,262 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"no-use-before-define": 0,
"no-await-in-loop": 0,
"no-alert": 1,
"no-throw-literal": "off",
"func-names": 0,
"no-underscore-dangle": 0,
"object-curly-new-line": 0,
Expand Down
7 changes: 0 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"**/node_modules": true
},
"vetur.format.defaultFormatter.js": "vscode-typescript",
"aliasFork.webpeckConfigPath": "./scripts/webpack.resolve.config.js",
"vetur.format.defaultFormatter.html": "js-beautify-html",
"vetur.format.defaultFormatterOptions": {
"js-beautify-html": {
Expand All @@ -35,10 +34,4 @@
"wrap_line_length": 100
}
},
"aliasFork.alias": {
"vue$": "vue\\dist\\vue.esm.js",
"static": "static",
"universal": "src\\universal",
"renderer": "src\\renderer"
},
}
7 changes: 7 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
"kind": "build",
"isDefault": true
}
},
{
"type": "npm",
"script": "lint",
"problemMatcher": [
"$eslint-compact"
]
}
]
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Infinity Studio
Copyright (c) 2019 ci010

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
111 changes: 102 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,47 @@ The renderer is/are just (a) browsers which communicate with main. It maintains

The project is mainly written by js. Though, by adding tricky typescript definition files (d.ts), we can have useful code snippets even for vue commit/dispatch! That really save my brain and improve the productivity. See the [store definition file](src/universal/store/store.d.ts) for more details.

#### LICENSE

[MIT](LICENSE)
## Dev

This project is designed to easy to dev... hopefully.

### Getting Started

*The installation might be the most hard part.*

The development environment require 3 things:

1. [Nodejs](https://nodejs.org/) version >= 10
2. python 2.7
3. msbuild (Sindows) , clang (MacOs), gcc (linux desktop)

#### Dev
#### Windows Env Tip

Require node 10, (not worked in node 11 & 12), [nodejs download](https://nodejs.org/)
If you have neither python 2.7 nor msbuild, you should try
[windows-build-tools](https://github.com/felixrieseberg/windows-build-tools). It really simplify the verbose installation process. You can just run `npm install --global windows-build-tools` and wait it done.

Require python 2.7, some cpp compiler to install native module.
*Notice that the visual studio installation process is really slow. Some time the process will FREEZE. You can terminate the installation process and run the installation command again.*

On Windows: please use msbuild tool to compile cpp. You can try install it by [windows-build-tools](https://github.com/felixrieseberg/windows-build-tools).
#### Mac Env Tip

On MacOS: install XCode.
Python 2.7 should be built in. You should install XCode in addition.

On Linux distr: Never tried. I don't have a linux desktop machine.
#### Linux Env Tip

Never tried. I don't have a linux desktop machine.

#### 解决中国国内安装依赖(如electron)太慢的办法

打开你的 git bash,在`npm i`前面加上`registry=https://registry.npm.taobao.org electron_mirror="https://npm.taobao.org/mirrors/electron/"`。使用国内阿里提供的npm以及electron的镜像。

最终输入的command也就是

```bash
registry=https://registry.npm.taobao.org electron_mirror="https://npm.taobao.org/mirrors/electron/" npm i
```

### General Process

``` bash
# optional on Windows to install build tools
Expand All @@ -85,7 +111,74 @@ npm run build
npm test
```

#### Credit
### Let Typescript Intellisense to help you

The launcher core is in [seperated project](https://github.com/ci010/ts-minecraft) written in typescript.

At the same time, the launcher core logic is guard by typescript definition file. Since the project enable the `checkJs` option in `jsconfig.json`. The vscode editor will perform type check on the vuex store part, which enable the type intellisense on usage of vuex.

For example, you will get intellisense during you write the vuex module:

![image](/misc/typehint0.png)

Also, the vscode will hint you in .vue files:

![](/misc/typehint1.png)

You may already notice that, in .vue file, it uses `$repo` but not `$store` property to access vuex store. This is just a redirect. `$repo` is just another reference of `$store`. It's necessary to let the type system accept my type definitoin.

Each vuex module has a corresponding definitoin file. If you want to add a state/getter/mutation/action to a module, you should firstly add the definition of that state/getter/mutation/action in the definition file.

The project overwrite the some vue/vuex definition. You can check [this file](/src/universal/store/store.d.ts) to see the implemantion detail.

### A better Dev experience with VSCode debugger

The project includes vscode debugger configs. You can add breakpoint on line and debug. Currently, VSCode debugger method only supports debug on main process.

(You can use chrome devtool for renderer process anyway)

We have two options now:

1. Electron: Main (npm)
2. Electron: Main (attach)

Please use the attch option since the first one not work now.

With attach option, you should first run `npm run dev`, and then attach debugger by VSCode debugger UI.

### Commit your code

This project follow the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0-beta.3/). In short, the first line of your commit message should be:

```
commit type: commit description
```

There are several avaiable commit type: `feat`, `fix`, `refactor`, `style`, `docs`, `chore`, `test`.

Refer from [this gist](https://gist.github.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716):

> feat: (new feature for the user, not a new feature for build script)
>
> fix: (bug fix for the user, not a fix to a build script)
>
> docs: (changes to the documentation)
>
> style: (formatting, missing semi colons, etc; no production code change)
>
> refactor: (refactoring production code, eg. renaming a variable)
>
> test: (adding missing tests, refactoring tests; no production code change)
>
> chore: (updating grunt tasks etc; no production code change)
**Your commit will be rejected if you do not follow these rules.**

## LICENSE

[MIT](LICENSE)

## Credit

[Jin](https://github.com/Indexyz), [LG](https://github.com/LasmGratel), [Phoebe](https://github.com/PhoebezZ), [Sumeng Wang](https://github.com/darkkingwsm), [Luca](https://github.com/LucaIsGenius), [Charles Tang](https://github.com/CharlesQT)

Expand Down
1 change: 1 addition & 0 deletions misc/typehint0.png.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add55b074a6f739103f24663b12c8fb351fa77ef
1 change: 1 addition & 0 deletions misc/typehint1.png.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d4d6614d6f10fdac341be84f84391b06e26ec2ea
2 changes: 1 addition & 1 deletion package-lock.json.REMOVED.git-id

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

31 changes: 24 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "voxelauncher",
"productName": "VoxeLauncher",
"version": "0.0.1-alpha.3",
"typings": "typings.d.ts",
"author": "cijhn@hotmail.com",
"description": "A great minecraft launcher in the feature",
"license": "MIT",
Expand All @@ -15,13 +14,15 @@
"build": "node scripts/build.js && electron-builder",
"build:dir": "node scripts/build.js && electron-builder --dir",
"build:clean": "cross-env BUILD_TARGET=clean node scripts/build.js",
"build:locale": "node scripts/build-locale.js",
"dev": "node scripts/dev-runner.js --no-lazy",
"pack": "npm run pack:main && npm run pack:renderer",
"pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config scripts/webpack.main.config.js",
"pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config scripts/webpack.renderer.config.js",
"lint": "eslint --ext .js,.vue src",
"lint:fix": "eslint --ext .js,.vue --fix src",
"test": " mocha test/e2e",
"test": "mocha test/e2e",
"release": "standard-version",
"install:native": "cross-env npm_config_runtime=electron electron-builder install-app-deps",
"postinstall": "npm run install:native"
},
Expand Down Expand Up @@ -89,15 +90,26 @@
"icon": "build/icons"
}
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"dependencies": {
"electron-updater": "^4.0.6",
"fast-html-parser": "^1.0.1",
"file-type": "^10.11.0",
"got": "^9.6.0",
"iconv-lite": "^0.4.18",
"lzma-native": "^4.0.3",
"in-gfw": "^1.2.0",
"lzma-native": "^4.0.5",
"treelike-task": "^0.0.15",
"ts-minecraft": "^5.0.22-beta",
"ts-minecraft": "^5.2.2",
"uuid": "^3.2.1",
"vue": "^2.6.10",
"vue-electron": "^1.0.6",
Expand All @@ -109,6 +121,8 @@
"yazl": "^2.5.1"
},
"devDependencies": {
"@commitlint/cli": "^8.0.0",
"@commitlint/config-conventional": "^8.0.0",
"babel-eslint": "^10.0.1",
"cfonts": "^1.1.3",
"chalk": "^1.1.3",
Expand All @@ -117,8 +131,8 @@
"css-loader": "^2.1.1",
"del": "^3.0.0",
"devtron": "^1.4.0",
"electron": "^4.2.0",
"electron-builder": "^20.40.2",
"electron": "^5.0.3",
"electron-builder": "^20.43.0",
"electron-debug": "^1.4.0",
"electron-devtools-installer": "^2.2.0",
"eslint": "^5.5.0",
Expand All @@ -130,11 +144,14 @@
"eslint-plugin-vue": "^5.2.2",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"husky": "^2.4.1",
"maven-artifact-version": "0.0.1",
"mini-css-extract-plugin": "^0.4.2",
"mocha": "^5.2.0",
"multispinner": "^0.2.1",
"require-dir": "^1.2.0",
"spectron": "^5.0.0",
"standard-version": "^6.0.1",
"style-loader": "^0.21.0",
"three": "^0.86.0",
"three-orbit-controls": "^82.1.0",
Expand All @@ -148,4 +165,4 @@
"webpack-dev-server": "^3.2.1",
"webpack-hot-middleware": "^2.22.2"
}
}
}
68 changes: 68 additions & 0 deletions scripts/build-locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const fs = require('fs');
const path = require('path');

const base = path.resolve(__dirname, '..', 'static', 'locales');

const files = fs.readdirSync(base).filter(f => f.endsWith('.json')).map(f => path.join(base, f));

function discover(dest, src) {
const keys = Object.keys(src);
for (const k of keys) {
// eslint-disable-next-line no-continue
if (k === '$schema') continue;
const v = src[k];
if (typeof v === 'object') {
if (!dest[k]) {
dest[k] = {};
}
discover(dest[k], v);
} else {
dest[k] = '';
}
}
}

function generateSchema(o) {
const type = typeof o;
if (type === 'object') {
const keys = Object.keys(o);
return {
type: 'object',
properties: keys.map(k => ({ [k]: generateSchema(o[k]) })).reduce((a, b) => ({ ...a, ...b })),
required: keys,
};
}
if (type === 'string') {
return { type: 'string' };
}
throw new Error(o);
}

function sorted(o) {
const result = {};
const keys = Object.keys(o).sort();
for (const key of keys) {
// eslint-disable-next-line no-continue
if (key === '$schema') continue;
if (typeof o[key] === 'object') {
o[key] = sorted(o[key]);
}
result[key] = o[key];
}
return result;
}

const powerLang = {};
Promise.all(files.map(processFile)).then(() => {
const schema = generateSchema(powerLang);
schema.$id = 'https://raw.githubusercontent.com/ci010/VoxeLauncher/master/static/locale.schema.json';
fs.writeFileSync(path.resolve(__dirname, '..', 'static', 'locale.schema.json'), JSON.stringify(schema, null, 4));
});

async function processFile(f) {
const b = await fs.promises.readFile(f);
const o = JSON.parse(b.toString());
discover(powerLang, o);
const result = { $schema: '../locale.schema.json', ...sorted(o) };
await fs.promises.writeFile(f, JSON.stringify(result, null, 4));
}
Loading

0 comments on commit 790924b

Please sign in to comment.