Skip to content

Commit

Permalink
changed README.md and build changes before
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodegress committed Jan 26, 2023
1 parent 796ad92 commit eedf403
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 25 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ rw-toml is avaliable via npm.
npm install rw-toml
````

## Usage
rw-toml are mostlt used by another project named [rw-build](https://github.com/zerodegress/rw-build),which is a CLI Rusted Warfare mod builder running on [Node.js](https://nodejs.org).

## License
rw-toml is licensed under the GNU-GPL v3 license agreement. See the LICENSE file for more information.
20 changes: 12 additions & 8 deletions lib/builder/classic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Optional } from "../optional";
import { Builder } from ".";
import { Result } from "../result";
import { StandardIni, CommonToml } from "../config";
export declare function normalize(pat: string): string;
export interface FileLike {
filename: string;
dirname: string;
Expand All @@ -11,14 +12,14 @@ export declare class PathLike {
constructor(path: string);
}
export declare enum ClassicSourceFileType {
TOML = 0,
TXT = 1,
PNG = 2,
JPEG = 3,
OGG = 4,
WAV = 5,
MP3 = 6,
UNKNOWN_ASSET = 7
TOML = "TOML",
TXT = "TXT",
PNG = "PNG",
JPEG = "JPEG",
OGG = "OGG",
WAV = "WAV",
MP3 = "MP3",
UNKNOWN_ASSET = "UNKNOWN_ASSET"
}
export declare class ClassicSourceFile {
private type;
Expand All @@ -34,6 +35,9 @@ export declare class ClassicSourceFile {
isUnknownAsset(): boolean;
toml(callback: (content: CommonToml) => void): ClassicSourceFile;
txt(callback: (content: string) => void): ClassicSourceFile;
image(callback: (content: PathLike) => void): ClassicSourceFile;
soundOrMusic(callback: (content: PathLike) => void): ClassicSourceFile;
unknownAsset(callback: (content: PathLike) => void): ClassicSourceFile;
}
export declare class ClassicSource implements FileLike {
filename: string;
Expand Down
109 changes: 92 additions & 17 deletions lib/builder/classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClassicBuilderSync = exports.ClassicTarget = exports.ClassicTargetFile = exports.CopyFromSource = exports.ClassicTargetFileType = exports.ClassicSource = exports.ClassicSourceFile = exports.ClassicSourceFileType = exports.PathLike = void 0;
exports.ClassicBuilderSync = exports.ClassicTarget = exports.ClassicTargetFile = exports.CopyFromSource = exports.ClassicTargetFileType = exports.ClassicSource = exports.ClassicSourceFile = exports.ClassicSourceFileType = exports.PathLike = exports.normalize = void 0;
const optional_1 = require("../optional");
const path_browserify_1 = __importDefault(require("path-browserify"));
const normalize_path_1 = __importDefault(require("normalize-path"));
const result_1 = require("../result");
const config_1 = require("../config");
function normalize(pat) {
return (0, normalize_path_1.default)(path_browserify_1.default.normalize(pat));
}
exports.normalize = normalize;
class PathLike {
constructor(path) {
this.path = path;
Expand All @@ -16,18 +21,21 @@ class PathLike {
exports.PathLike = PathLike;
var ClassicSourceFileType;
(function (ClassicSourceFileType) {
ClassicSourceFileType[ClassicSourceFileType["TOML"] = 0] = "TOML";
ClassicSourceFileType[ClassicSourceFileType["TXT"] = 1] = "TXT";
ClassicSourceFileType[ClassicSourceFileType["PNG"] = 2] = "PNG";
ClassicSourceFileType[ClassicSourceFileType["JPEG"] = 3] = "JPEG";
ClassicSourceFileType[ClassicSourceFileType["OGG"] = 4] = "OGG";
ClassicSourceFileType[ClassicSourceFileType["WAV"] = 5] = "WAV";
ClassicSourceFileType[ClassicSourceFileType["MP3"] = 6] = "MP3";
ClassicSourceFileType[ClassicSourceFileType["UNKNOWN_ASSET"] = 7] = "UNKNOWN_ASSET";
ClassicSourceFileType["TOML"] = "TOML";
ClassicSourceFileType["TXT"] = "TXT";
ClassicSourceFileType["PNG"] = "PNG";
ClassicSourceFileType["JPEG"] = "JPEG";
ClassicSourceFileType["OGG"] = "OGG";
ClassicSourceFileType["WAV"] = "WAV";
ClassicSourceFileType["MP3"] = "MP3";
ClassicSourceFileType["UNKNOWN_ASSET"] = "UNKNOWN_ASSET";
})(ClassicSourceFileType = exports.ClassicSourceFileType || (exports.ClassicSourceFileType = {}));
class ClassicSourceFile {
constructor(type, content) {
this.type = type;
if (content instanceof PathLike) {
content.path = normalize(content.path);
}
this.content = content;
}
static toml(content) {
Expand Down Expand Up @@ -65,7 +73,7 @@ class ClassicSourceFile {
return this.type == ClassicSourceFileType.TXT;
}
isImage() {
return this.type == ClassicSourceFileType.PNG;
return this.type == ClassicSourceFileType.PNG || this.type == ClassicSourceFileType.JPEG;
}
isSoundOrMusic() {
return this.type == ClassicSourceFileType.OGG || this.type == ClassicSourceFileType.MP3 || this.type == ClassicSourceFileType.WAV;
Expand Down Expand Up @@ -95,15 +103,49 @@ class ClassicSourceFile {
}
return this;
}
image(callback) {
if (this.isImage()) {
if (this.content instanceof PathLike) {
callback(this.content);
}
else {
throw new Error('internal error');
}
}
return this;
}
soundOrMusic(callback) {
if (this.isSoundOrMusic()) {
if (this.content instanceof PathLike) {
callback(this.content);
}
else {
throw new Error('internal error');
}
}
return this;
}
unknownAsset(callback) {
if (this.isUnknownAsset()) {
if (this.content instanceof PathLike) {
callback(this.content);
}
else {
throw new Error('internal error');
}
}
return this;
}
}
exports.ClassicSourceFile = ClassicSourceFile;
class ClassicSource {
constructor(filename, dirname, path, content) {
this.filename = filename;
this.dirname = dirname;
this.path = path;
this.dirname = normalize(dirname);
this.path = normalize(path);
this.target = (0, optional_1.none)();
if (content instanceof PathLike) {
content.path = normalize(content.path);
this.sourceFile = ClassicSourceFile.asset(content);
}
else if (typeof content == 'object') {
Expand Down Expand Up @@ -166,7 +208,9 @@ exports.ClassicTargetFile = ClassicTargetFile;
class ClassicTarget {
constructor(filename, dirname, source, targetFile) {
this.filename = filename;
this.dirname = dirname;
this.dirname = normalize(dirname);
source.dirname = normalize(source.dirname);
source.path = normalize(source.path);
this.source = source;
this.targetFile = targetFile;
}
Expand Down Expand Up @@ -209,9 +253,9 @@ class ClassicBuilderSync {
});
(0, optional_1.optional)(this.context.sources.find((value) => value.path == path)).some((source) => {
source.built((target) => { throw (0, result_1.ok)({ source, target }); }).unbuilt(() => {
this.buildSync(path).ok((target) => { throw (0, result_1.ok)({ source, target }); }).err((error) => { throw (0, result_1.err)(error); });
this.buildSync(path, starterPath).ok((target) => { throw (0, result_1.ok)({ source, target }); }).err((error) => { throw (0, result_1.err)(error); });
});
}).none(() => { throw (0, result_1.err)(new Error('requirement does not exists')); });
}).none(() => { throw (0, result_1.err)(new Error(`requirement "${path}" does not exists`)); });
throw new Error('unreachable!');
}
catch (result) {
Expand Down Expand Up @@ -257,7 +301,20 @@ class ClassicBuilderSync {
return value.join();
}
else {
return value.toString();
let outputValue = value.toString();
if (secMain == 'core' && key == 'copyFrom') {
let requirePath = normalize(value.toString().trim());
if (requirePath.startsWith('/')) {
requirePath = requirePath.replace(/^\//, '');
outputValue = 'ROOT:' + requirePath;
}
else {
requirePath = normalize(path_browserify_1.default.join(source.dirname, requirePath));
outputValue = requirePath;
}
this.requireSync(requirePath, starterPath != undefined ? starterPath : source.path).err((error) => { throw (0, result_1.err)(error); });
}
return outputValue.replace(/\.toml$/, '.ini');
}
})();
});
Expand All @@ -268,8 +325,26 @@ class ClassicBuilderSync {
break;
}
}
const target = new ClassicTarget(source.filename.replace('.toml', '.ini'), source.dirname, source, ClassicTargetFile.ini(ini));
const target = new ClassicTarget(source.filename.replace(/\.toml$/, '.ini'), source.dirname, source, ClassicTargetFile.ini(ini));
source.target = (0, optional_1.some)(target);
this.context.targets.push(target);
throw (0, result_1.ok)(target);
}).txt((content) => {
const target = new ClassicTarget(source.filename, source.dirname, source, ClassicTargetFile.txt(content));
source.target = (0, optional_1.some)(target);
this.context.targets.push(target);
throw (0, result_1.ok)(target);
}).image((content) => {
const target = new ClassicTarget(source.filename, source.dirname, source, ClassicTargetFile.asset());
this.context.targets.push(target);
throw (0, result_1.ok)(target);
}).soundOrMusic((content) => {
const target = new ClassicTarget(source.filename, source.dirname, source, ClassicTargetFile.asset());
this.context.targets.push(target);
throw (0, result_1.ok)(target);
}).unknownAsset((content) => {
const target = new ClassicTarget(source.filename, source.dirname, source, ClassicTargetFile.asset());
this.context.targets.push(target);
throw (0, result_1.ok)(target);
});
}).none(() => { throw (0, result_1.err)(new Error('source does not exists')); });
Expand Down

0 comments on commit eedf403

Please sign in to comment.