Skip to content

Commit

Permalink
Refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Nov 7, 2024
1 parent 7c10417 commit e75374d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const {peerDependencies} = require('./package.json');

const sharedConfig = {
entryPoints: [
"./src/cityjson2dtx.ts"
"./src/cityjson2xgf.ts"
],
bundle: true,
minify: false,
Expand All @@ -17,5 +17,5 @@ build({
platform: 'node',
format: 'cjs',
target: "node10.4",
outfile: "dist/cityjson2dtx.cjs.js",
outfile: "dist/cityjson2xgf.cjs.js",
});
49 changes: 49 additions & 0 deletions packages/cityjson2xgf/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@xeokit/cityjson2xgf",
"private": false,
"version": "0.1.0",
"description": ".BIM loader for xeokit",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"module": "dist/index.js",
"scripts": {
"test": "jest --passWithNoTests",
"dist": "node build.js ; tsc",
"lint": "eslint . --fix",
"docs": "typedoc --json ../../docs/json/cityjson2xgf.json --options typedoc.json --validation.invalidLink false",
"publish": "npm publish --access public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/xeokit/sdk.git"
},
"author": "Lindsay Kay",
"license": "SEE LICENSE IN LICENSE.md",
"bugs": {
"url": "https://github.com/xeokit/sdk/issues"
},
"homepage": "https://xeokit.io",
"files": [
"src/",
"dist/",
"README.md",
"package.json"
],
"keywords": [],
"dependencies": {
"@xeokit/config": "^0.1.0",
"@xeokit/core": "^0.1.0",
"@xeokit/data": "^0.1.0",
"@xeokit/scene": "^0.1.0",
"@xeokit/cityjson": "^0.1.0",
"@xeokit/xgf": "^0.1.0",
"commander": "^11.0.0"
},
"peerDependencies": {

},
"devDependencies": {
"@jest/globals": "^29.5.0",
"jest-html-reporter": "^3.10.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Data} from "@xeokit/data";
import {Scene} from "@xeokit/scene";
import {SDKError} from "@xeokit/core";
import {loadCityJSON} from "@xeokit/cityjson";
import {saveDTX} from "dtx";
import {saveXGF} from "packages/xgf";

const commander = require('commander');
const npmPackage = require('./package.json');
Expand All @@ -15,24 +15,24 @@ program.version(npmPackage.version, '-v, --version');

program
.option('-i, --input [file]', 'path to input CityJSON file')
.option('-o, --output [file]', 'path to output DTX file');
.option('-o, --output [file]', 'path to output XGF file');

program.on('--help', () => {
console.log(`\n\nDTX version: 10`);
console.log(`\n\nXGF version: 10`);
});

program.parse(process.argv);

const options = program.opts();

if (options.input === undefined) {
console.error('[cityjson2dtx] Error: please specify a path to a CityJSON input file (-i).');
console.error('[cityjson2xgf] Error: please specify a path to a CityJSON input file (-i).');
program.help();
process.exit(1);
}

if (options.output === undefined) {
console.error('[cityjson2dtx] Error: please specify output DTX file path (-o).');
console.error('[cityjson2xgf] Error: please specify output XGF file path (-o).');
program.help();
process.exit(1);
}
Expand All @@ -45,15 +45,15 @@ function log(msg) {

async function main() {

log(`[cityjson2dtx] Running cityjson2dtx v${npmPackage.version}...`);
log(`[cityjson2dtx] Reading CityJSON file ${options.input}...`);
log(`[cityjson2xgf] Running cityjson2xgf v${npmPackage.version}...`);
log(`[cityjson2xgf] Reading CityJSON file ${options.input}...`);

let fileData;

try {
fileData = fs.readFileSync(options.input);
} catch (err) {
console.error(`[cityjson2dtx] Error reading CityJSON file: ${err}`);
console.error(`[cityjson2xgf] Error reading CityJSON file: ${err}`);
process.exit(1);
}

Expand All @@ -64,34 +64,34 @@ async function main() {
});

if (dataModel instanceof SDKError) {
console.error(`[cityjson2dtx] Error converting CityJSON file: ${dataModel.message}`);
console.error(`[cityjson2xgf] Error converting CityJSON file: ${dataModel.message}`);
process.exit(1);
} else {
const scene = new Scene();
const sceneModel = scene.createModel({
id: "foo"
});
if (sceneModel instanceof SDKError) {
console.error(`[cityjson2dtx] Error converting CityJSON file: ${sceneModel.message}`);
console.error(`[cityjson2xgf] Error converting CityJSON file: ${sceneModel.message}`);
process.exit(1);
} else {
loadCityJSON({fileData, dataModel, sceneModel}).then(() => {
sceneModel.build().then(() => {
dataModel.build();
const dtxArrayBuffer = saveDTX({dataModel, sceneModel});
const xgfArrayBuffer = saveXGF({dataModel, sceneModel});
const outputDir = getBasePath(options.output).trim();
if (outputDir !== "" && !fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, {recursive: true});
}
fs.writeFileSync(options.output, Buffer.from(dtxArrayBuffer));
log(`[cityjson2dtx] Created DTX file: ${options.output}`);
fs.writeFileSync(options.output, Buffer.from(xgfArrayBuffer));
log(`[cityjson2xgf] Created XGF file: ${options.output}`);
process.exit(0);
}).catch((err) => {
console.error(`[cityjson2dtx] Error converting CityJSON file: ${err}`);
console.error(`[cityjson2xgf] Error converting CityJSON file: ${err}`);
process.exit(1);
});
}).catch((err) => {
console.error(`[cityjson2dtx] Error converting CityJSON file: ${err}`);
console.error(`[cityjson2xgf] Error converting CityJSON file: ${err}`);
process.exit(1);
});
}
Expand All @@ -106,4 +106,4 @@ function getBasePath(src) {
main().catch(err => {
console.error('Error:', err);
process.exit(1);
});
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* [![npm version](https://badge.fury.io/js/%40xeokit%2Fifcviewer.svg)](https://badge.fury.io/js/%40xeokit%2Fifcviewer)
* [![](https://data.jsdelivr.com/v1/package/npm/@xeokit/cityjson2dtx/badge)](https://www.jsdelivr.com/package/npm/@xeokit/ifcviewer)
* [![](https://data.jsdelivr.com/v1/package/npm/@xeokit/cityjson2xgf/badge)](https://www.jsdelivr.com/package/npm/@xeokit/ifcviewer)
*
* <img style="padding:0px; padding-top:30px; padding-bottom:30px;" src="media://images/tree_view_icon.png"/>
*
* <br>
*
* ## cityjson2dtx
* ## cityjson2xgf
*
* Node CLI tool to convert CityJSON files into [DTX](https://xeokit.github.io/sdk/docs/pages/GLOSSARY.html#dtx) files.
* Node CLI tool to convert CityJSON files into [XGF](https://xeokit.github.io/sdk/docs/pages/GLOSSARY.html#xgf) files.
*
* ## Features
*
Expand All @@ -17,17 +17,17 @@
* ## Installation
*
* ````bash
* npm install @xeokit/cityjson2dtx
* npm install @xeokit/cityjson2xgf
* ````
*
* ## Usage
*
* TODO
*
* ````bash
* cityjson2dtx -i model.json -o model.dtx
* cityjson2xgf -i model.json -o model.xgf
* ````
*
* @module @xeokit/cityjson2dtx
* @module @xeokit/cityjson2xgf
*/
export * from "./cityjson2dtx"
export * from "./cityjson2xgf"
File renamed without changes.
File renamed without changes.

0 comments on commit e75374d

Please sign in to comment.