Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
duduluu committed Jun 12, 2019
1 parent da054e6 commit 8b8cdff
Show file tree
Hide file tree
Showing 31 changed files with 541 additions and 28 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Expand Up @@ -255,5 +255,11 @@ paket-files/

# Reflection
/Reflection/RimWorldWin64_Data
/*/lib
/coverage
/*/coverage
/dist
/*/dist
/lib
/*/lib
/types
/*/types
1 change: 1 addition & 0 deletions Reflection/README.md
@@ -0,0 +1 @@
# Rimtrans/Reflection
Binary file not shown.
Binary file added Reflection/References/Assembly-CSharp.dll
Binary file not shown.
Binary file added Reflection/References/NAudio.dll
Binary file not shown.
Binary file added Reflection/References/NVorbis.dll
Binary file not shown.
Binary file not shown.
Binary file added Reflection/References/UnityEngine.Networking.dll
Binary file not shown.
Binary file added Reflection/References/UnityEngine.UI.dll
Binary file not shown.
Binary file added Reflection/References/UnityEngine.dll
Binary file not shown.
Binary file added Reflection/References/UnityEngine.dll.mdb
Binary file not shown.
File renamed without changes.
8 changes: 4 additions & 4 deletions Reflection/Reflection.csproj
Expand Up @@ -7,8 +7,11 @@
</PropertyGroup>

<ItemGroup>
<Compile Remove="lib\**" />
<Compile Remove="RimWorldWin64_Data\**" />
<EmbeddedResource Remove="lib\**" />
<EmbeddedResource Remove="RimWorldWin64_Data\**" />
<None Remove="lib\**" />
<None Remove="RimWorldWin64_Data\**" />
</ItemGroup>

Expand All @@ -18,10 +21,7 @@

<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>RimWorldWin64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath>References\Assembly-CSharp.dll</HintPath>
</Reference>
</ItemGroup>

Expand Down
14 changes: 10 additions & 4 deletions Reflection/package.json
@@ -1,7 +1,13 @@
{
"name": "@rimtrans/type-info",
"name": "@rimtrans/reflection",
"description": "A dotnet core command line tool for getting type info in .dll file.",
"version": "4.0.0-alpha.1",
"private": true,
"version": "1.0.2282",
"main": "type-info.json",
"types": "type-info.d.ts"
"scripts": {
"clean": "rimraf ./lib",
"build:win": "dotnet publish --self-contained -c Release -r win-x64 -o ./lib/win",
"build:linux": "dotnet publish --self-contained -c Release -r linux-x64 -o ./lib/linux",
"build:osx": "dotnet publish --self-contained -c Release -r osx-x64 -o ./lib/osx",
"build": "yarn build:win && yarn build:linux && yarn build:osx"
}
}
13 changes: 13 additions & 0 deletions executable/babel.config.js
@@ -0,0 +1,13 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: '12.2.0',
},
},
],
'@babel/preset-typescript',
],
};
25 changes: 25 additions & 0 deletions executable/package.json
@@ -0,0 +1,25 @@
{
"name": "@rimtrans/executable",
"description": "The executable entry for RimTrans",
"version": "4.0.0-alpha.1",
"private": true,
"main": "lib/index.js",
"types": "types/index.d.ts",
"scripts": {
"clean": "rimraf ./types && rimraf ./lib",
"build:types": "tsc",
"build:babel": "babel ./src -x .ts -d ./lib",
"pkg:win": "pkg ./lib/main.js -t node12-win-x64 -o ./lib/win/RimTrans",
"pkg:linux": "pkg ./lib/main.js -t node12-linux-x64 -o ./lib/linux/RimTrans",
"pkg:osx": "pkg ./lib/main.js -t node12-macos-x64 -o ./lib/osx/RimTrans",
"pkg": "yarn pkg:win && yarn pkg:linux && yarn pkg:osx",
"build": "yarn build:types && yarn build:babel && yarn pkg"
},
"devDependencies": {
"pkg": "^4.4.0"
},
"dependencies": {
"chalk": "^2.4.2",
"time-stamp": "^2.2.0"
}
}
3 changes: 3 additions & 0 deletions executable/src/index.ts
@@ -0,0 +1,3 @@
import * as logger from './logger';

export { logger };
41 changes: 41 additions & 0 deletions executable/src/logger.ts
@@ -0,0 +1,41 @@
/* eslint-disable no-console,@typescript-eslint/no-explicit-any */
import chalk from 'chalk';
import timestamp from 'time-stamp';

export type Log = (message?: any, ...optionalParams: any[]) => void;

export const info: Log = (message, ...optionalParams) => {
console.log(
timestamp('YYYY-MM-DD HH:mm:ss.ms'),
chalk.cyanBright('INFO'),
message,
...optionalParams,
);
};

export const success: Log = (message, ...optionalParams) => {
console.log(
new Date().toLocaleString(),
chalk.greenBright('SUCCESS'),
message,
...optionalParams,
);
};

export const warn: Log = (message, ...optionalParams) => {
console.warn(
new Date().toLocaleString(),
chalk.yellowBright('WARN'),
message,
...optionalParams,
);
};

export const error: Log = (message, ...optionalParams) => {
console.error(
new Date().toLocaleString(),
chalk.redBright('ERROR'),
message,
...optionalParams,
);
};
43 changes: 43 additions & 0 deletions executable/src/main.ts
@@ -0,0 +1,43 @@
import pth from 'path';
import * as logger from './logger';

interface Env {
readonly filename: string;
readonly dirname: string;
readonly cwd: string;
readonly execPath: string;
readonly argv0: string;
readonly argv1: string;
readonly mainFilename?: string;
readonly isPkg: boolean;
readonly entrypoint?: string;
readonly defaultEntrypoint?: string;
}

function getEnv(): Env {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { pkg } = process as any;

return {
filename: __filename,
dirname: __dirname,
cwd: process.cwd(),
execPath: process.execPath,
argv0: process.argv[0],
argv1: process.argv[1],
mainFilename: require.main && require.main.filename,
isPkg: !!pkg,
entrypoint: pkg && pkg.entrypoint,
defaultEntrypoint: pkg && pkg.defaultEntrypoint,
};
}

const ENV = getEnv();
const INSTALLATION_DIRECTORY = ENV.isPkg ? pth.basename(ENV.execPath) : ENV.dirname;

async function main(): Promise<void> {
logger.info(ENV);
logger.info(INSTALLATION_DIRECTORY);
}

main().catch(logger.error);
11 changes: 11 additions & 0 deletions executable/tsconfig.json
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationDir": "types",
"declarationMap": true,
"emitDeclarationOnly": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "src/**/*.test.ts"]
}
2 changes: 1 addition & 1 deletion extractor/babel.config.js
Expand Up @@ -4,7 +4,7 @@ module.exports = {
'@babel/preset-env',
{
targets: {
node: 'current',
node: '12.2.0',
},
},
],
Expand Down
10 changes: 7 additions & 3 deletions extractor/package.json
@@ -1,11 +1,15 @@
{
"name": "@rimtrans/extractor",
"description": "The extractor library for RimTrans.",
"version": "4.0.0-alpha.1",
"private": true,
"main": "src/index.ts",
"main": "lib/index.js",
"types": "types/index.d.ts",
"scripts": {
"clean": "rimraf ./lib",
"build": "babel ./src -x .ts -d ./lib",
"clean": "rimraf ./types && rimraf ./lib",
"build:types": "tsc",
"build:babel": "babel ./src -x .ts -d ./lib",
"build": "yarn build:types && yarn build:babel",
"test": "jest"
},
"dependencies": {
Expand Down
11 changes: 11 additions & 0 deletions extractor/tsconfig.json
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationDir": "types",
"declarationMap": true,
"emitDeclarationOnly": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "src/**/*.test.ts"]
}
1 change: 0 additions & 1 deletion lerna.json
Expand Up @@ -3,7 +3,6 @@
"useWorkspaces": true,
"version": "independent",
"ignoreChanges": [
"Reflection/**",
"**/scripts/**",
"**/tests/**",
"**/__tests__/**",
Expand Down
14 changes: 14 additions & 0 deletions package.json
@@ -1,6 +1,7 @@
{
"name": "rimtrans",
"description": "RimTrans: a translation tool for RimWorld Core and Mods.",
"version": "4.0.0-alpha.1",
"main": "index.js",
"repository": "git@github.com:RimWorld-zh/RimTrans.git",
"author": "duduluu <duduluu@outlook.com>",
Expand All @@ -9,6 +10,12 @@
"workspaces": [
"*"
],
"scripts": {
"clean": "rimraf ./lib && lerna run clean",
"build": "lerna run build",
"archive": "yarn ts ./scripts/archive",
"ts": "ts-node -r tsconfig-paths/register -P ./scripts/tsconfig.json"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
Expand All @@ -18,11 +25,14 @@
"@huiji/eslint-config-typescript": "^0.1.0",
"@huiji/shared-utils": "^1.1.0",
"@types/jest": "^24.0.13",
"@types/ncp": "^2.0.1",
"@types/node": "^12.0.7",
"@types/rimraf": "^2.0.2",
"compressing": "^1.4.0",
"eslint": "^5.16.0",
"eslint-plugin-import": "^2.17.3",
"jest": "^24.8.0",
"ncp": "^2.0.0",
"rimraf": "^2.6.3",
"stylelint": "^10.1.0",
"stylelint-config-standard": "^18.3.0",
Expand All @@ -31,5 +41,9 @@
"tsconfig-paths": "^3.8.0",
"tslib": "^1.10.0",
"typescript": "^3.5.1"
},
"engines": {
"node": ">=12.2.0",
"yarn": ">=1.16.0"
}
}
53 changes: 53 additions & 0 deletions scripts/archive.ts
@@ -0,0 +1,53 @@
/* eslint-disable no-console,no-restricted-syntax,no-await-in-loop */
import fs from 'fs';
import { genPathResolve } from '@huiji/shared-utils';
import { ncp } from 'ncp';
import compressing from 'compressing';

const resolvePath = genPathResolve(__dirname, '..');

const platforms = ['win', 'linux', 'osx'];
const { npm_package_version: version } = process.env;

async function copyDir(src: string, dest: string): Promise<void> {
return new Promise<void>((resolve, reject) =>
ncp(src, dest, error => (error ? reject(error) : resolve())),
);
}

const LIB = 'lib';
const EXECUTABLE = 'executable';
const REFLECTION = 'Reflection';

async function archive(): Promise<void> {
for (const platform of platforms) {
const folder = `rimtrans-v${version}-${platform}`;
await fs.promises.mkdir(resolvePath(LIB, folder), { recursive: true });

// copy executable
await copyDir(resolvePath(EXECUTABLE, LIB, platform), resolvePath(LIB, folder));
// copy reflection
await copyDir(
resolvePath(REFLECTION, LIB, platform),
resolvePath(LIB, folder, REFLECTION),
);

// compress
if (platform === 'win') {
await compressing.zip.compressDir(
resolvePath(LIB, folder),
resolvePath(LIB, `${folder}.zip`),
);
} else {
await compressing.tgz.compressDir(
resolvePath(LIB, folder),
resolvePath(LIB, `${folder}.tar.gz`),
);
}

// TODO upload file to github release
// https://developer.github.com/v3/repos/releases/
}
}

archive().catch(console.error);
6 changes: 6 additions & 0 deletions scripts/tsconfig.json
@@ -0,0 +1,6 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "commonjs"
}
}
7 changes: 7 additions & 0 deletions type-info/package.json
@@ -0,0 +1,7 @@
{
"name": "@rimtrans/type-info",
"version": "4.0.0-alpha.1",
"main": "type-info.json",
"types": "type-info.d.ts",
"private": true
}
File renamed without changes.
File renamed without changes.

0 comments on commit 8b8cdff

Please sign in to comment.