mirror of
https://github.com/billsonnn/nitro-converter.git
synced 2024-11-25 17:00:52 +01:00
Update things
This commit is contained in:
parent
3deddc713f
commit
4863141073
2
.gitignore
vendored
2
.gitignore
vendored
@ -54,4 +54,4 @@ Thumbs.db
|
||||
/assets
|
||||
|
||||
# Nitro
|
||||
/src/configuration.json
|
||||
configuration.json
|
||||
|
@ -35,7 +35,7 @@ You may set any of the urls to a local path on your system or a remote url. A lo
|
||||
|
||||
## Running the converter
|
||||
|
||||
**Make sure you run `yarn install` before first use.**
|
||||
**Make sure you run `yarn install && yarn build` before first use.**
|
||||
|
||||
To run the converter open a new terminal / console window in the main converter directory.
|
||||
|
||||
@ -43,6 +43,7 @@ The converter has a few different start commands:
|
||||
|
||||
| key | value |
|
||||
| ---------------------- | ---------------------------------------------------------- |
|
||||
| yarn build | Will run `tsc` and build .js from .ts |
|
||||
| yarn start | Will download and convert assets as set in the config |
|
||||
| yarn start:bundle | Will bundle decompressed `.nitro` assets (json / png) |
|
||||
| yarn start:extract | Will extract `.nitro` assets which can be used for editing |
|
||||
|
@ -17,7 +17,7 @@
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"start:dev": "ts-node-dev --respawn --transpile-only src/Main.ts",
|
||||
"start": "yarn build && node ./dist/Main.js",
|
||||
"start": "node ./dist/Main.js",
|
||||
"start:bundle": "yarn start --bundle",
|
||||
"start:extract": "yarn start --extract",
|
||||
"start:convert-swf": "yarn start --convert-swf"
|
||||
|
17
src/Main.ts
17
src/Main.ts
@ -1,5 +1,6 @@
|
||||
import 'reflect-metadata';
|
||||
import { container } from 'tsyringe';
|
||||
import { FileUtilities } from './common';
|
||||
import { Configuration } from './common/config/Configuration';
|
||||
import { IConverter } from './common/converters/IConverter';
|
||||
import { ConverterUtilities } from './converters/ConverterUtilities';
|
||||
@ -12,8 +13,12 @@ import { ProductDataConverter } from './converters/ProductDataConverter';
|
||||
|
||||
(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
const configurationContent = await FileUtilities.readFileAsString('./configuration.json');
|
||||
const config = container.resolve(Configuration);
|
||||
await config.init();
|
||||
|
||||
await config.init(JSON.parse(configurationContent));
|
||||
|
||||
const converters = [
|
||||
FurnitureDataConverter,
|
||||
@ -29,7 +34,7 @@ import { ProductDataConverter } from './converters/ProductDataConverter';
|
||||
const convertSwf = (process.argv.indexOf('--convert-swf') >= 0);
|
||||
const skip = (bundle || extract || convertSwf);
|
||||
|
||||
if(skip)
|
||||
if (skip)
|
||||
{
|
||||
const extractor = container.resolve(ConverterUtilities);
|
||||
|
||||
@ -40,7 +45,7 @@ import { ProductDataConverter } from './converters/ProductDataConverter';
|
||||
process.exit();
|
||||
}
|
||||
|
||||
for(const converterClass of converters)
|
||||
for (const converterClass of converters)
|
||||
{
|
||||
const converter = (container.resolve<any>(converterClass) as IConverter);
|
||||
|
||||
@ -52,4 +57,10 @@ import { ProductDataConverter } from './converters/ProductDataConverter';
|
||||
await utilities.downloadSwfTypes();
|
||||
|
||||
process.exit();
|
||||
}
|
||||
|
||||
catch (e)
|
||||
{
|
||||
console.error(e);
|
||||
}
|
||||
})();
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { singleton } from 'tsyringe';
|
||||
import * as configuration from '../../configuration.json';
|
||||
import { FileUtilities } from '../utils';
|
||||
|
||||
@singleton()
|
||||
@ -12,7 +11,7 @@ export class Configuration
|
||||
this._config = new Map<string, string>();
|
||||
}
|
||||
|
||||
public async init(): Promise<void>
|
||||
public async init(configuration: Object): Promise<void>
|
||||
{
|
||||
this.parseConfiguration(configuration);
|
||||
|
||||
@ -41,20 +40,20 @@ export class Configuration
|
||||
|
||||
private parseConfiguration(content: Object): boolean
|
||||
{
|
||||
if(!content) return false;
|
||||
if (!content) return false;
|
||||
|
||||
try
|
||||
{
|
||||
const regex = new RegExp(/\${(.*?)}/g);
|
||||
|
||||
for(const key of Object.keys(configuration))
|
||||
for (const key of Object.keys(content))
|
||||
{
|
||||
if(this._config.get(key))
|
||||
if (this._config.get(key))
|
||||
{
|
||||
if(!configuration[key].length) continue;
|
||||
if (!content[key].length) continue;
|
||||
}
|
||||
|
||||
this._config.set(key, this.interpolate(configuration[key], regex));
|
||||
this._config.set(key, this.interpolate(content[key], regex));
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -71,18 +70,18 @@ export class Configuration
|
||||
|
||||
private parseExternalVariables(content: string): boolean
|
||||
{
|
||||
if(!content || (content === '')) return false;
|
||||
if (!content || (content === '')) return false;
|
||||
|
||||
try
|
||||
{
|
||||
const regex = new RegExp(/\${(.*?)}/g);
|
||||
const lines: string[] = content.split('\n');
|
||||
|
||||
for(const line of lines)
|
||||
for (const line of lines)
|
||||
{
|
||||
const [ key, value ] = line.split('=');
|
||||
const [key, value] = line.split('=');
|
||||
|
||||
if(key.startsWith('landing.view')) continue;
|
||||
if (key.startsWith('landing.view')) continue;
|
||||
|
||||
this._config.set(key, this.interpolate((value || ''), regex));
|
||||
}
|
||||
@ -101,18 +100,18 @@ export class Configuration
|
||||
|
||||
public interpolate(value: string, regex: RegExp = null): string
|
||||
{
|
||||
if(!value || (typeof value === 'object')) return value;
|
||||
if(!regex) regex = new RegExp(/\${(.*?)}/g);
|
||||
if (!value || (typeof value === 'object')) return value;
|
||||
if (!regex) regex = new RegExp(/\${(.*?)}/g);
|
||||
|
||||
const pieces = value.match(regex);
|
||||
|
||||
if(pieces && pieces.length)
|
||||
if (pieces && pieces.length)
|
||||
{
|
||||
for(const piece of pieces)
|
||||
for (const piece of pieces)
|
||||
{
|
||||
const existing = this._config.get(this.removeInterpolateKey(piece));
|
||||
|
||||
if(existing) (value = value.replace(piece, existing));
|
||||
if (existing) (value = value.replace(piece, existing));
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,7 +125,7 @@ export class Configuration
|
||||
|
||||
public getValue(key: string, value: string = ''): string
|
||||
{
|
||||
if(this._config.has(key)) return this._config.get(key);
|
||||
if (this._config.has(key)) return this._config.get(key);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist"
|
||||
"dist",
|
||||
"src/configuration.json"
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user