-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
380 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// https://mjtdev.medium.com/how-to-create-a-single-file-bundle-of-a-large-typescript-project-in-2023-5693c8b6b142 | ||
|
||
const {build} = require("esbuild"); | ||
const {peerDependencies} = require('./package.json'); | ||
|
||
const sharedConfig = { | ||
entryPoints: [ | ||
"./src/index.ts" | ||
], | ||
bundle: true, | ||
minify: false, | ||
external: Object.keys(peerDependencies), | ||
}; | ||
|
||
build({ | ||
...sharedConfig, | ||
platform: 'node', | ||
format: 'cjs', | ||
target: "node10.4", | ||
outfile: "dist/index.cjs.js", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env node | ||
|
||
const {convertMetaModel} = require("./dist/index.cjs.js"); | ||
|
||
const commander = require('commander'); | ||
const npmPackage = require('./package.json'); | ||
const fs = require('fs'); | ||
const path = require("path"); | ||
const program = new commander.Command(); | ||
|
||
program.version(npmPackage.version, '-v, --version'); | ||
|
||
program | ||
.description(`CLI to convert a JSON MetaModel file into a JSON DataModel file`) | ||
.option('-i, --input [file]', 'path to input JSON MetaModel file (required)') | ||
.option('-d, --datamodel [file]', 'path to target JSON DataModel file (required)') | ||
.option('-l, --log', 'enable logging (optional)'); | ||
|
||
program.on('--help', () => { | ||
// console.log(`\n\nXGF version: 10`); | ||
}); | ||
|
||
program.parse(process.argv); | ||
|
||
const options = program.opts(); | ||
|
||
function logInfo(msg) { | ||
if (options.log) { | ||
console.log(`[meta2data] ${msg}`); | ||
} | ||
} | ||
|
||
function logError(msg) { | ||
console.error(`[meta2data] ${msg}`); | ||
} | ||
|
||
if (!options.input) { | ||
logError(`Argument expected: -i`); | ||
process.exit(-1); | ||
} | ||
|
||
if (!options.datamodel) { | ||
logError(`Argument expected: -d`); | ||
process.exit(-1); | ||
} | ||
|
||
try { | ||
|
||
const metaModelSrc = options.input; | ||
const dataModelSrc = options.datamodel; | ||
|
||
logInfo(`\nReading JSON MetaModel file: ${metaModelSrc}`); | ||
|
||
const metaModelJSON = JSON.parse(fs.readFileSync(metaModelSrc)); | ||
|
||
const dataModelDir = path.dirname(dataModelSrc); | ||
if (dataModelDir !== "" && !fs.existsSync(dataModelDir)) { | ||
fs.mkdirSync(dataModelDir, {recursive: true}); | ||
} | ||
|
||
logInfo(`Writing target DataModel JSON: ${dataModelSrc}`); | ||
|
||
fs.writeFileSync(dataModelSrc, convertMetaModel(metaModelJSON)); | ||
|
||
process.exit(1); | ||
|
||
} catch (err) { | ||
logError(err); | ||
process.exit(-1); | ||
} | ||
|
||
function getBasePath(src) { | ||
const i = src.lastIndexOf("/"); | ||
return (i !== 0) ? src.substring(0, i + 1) : ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {MetaObjectParams} from "./MetaObjectParams"; | ||
import {MetaPropertySetParams} from "./MetaPropertySetParams"; | ||
|
||
/** | ||
* Legacy metadata model parameters. | ||
*/ | ||
export interface MetaModelParams { | ||
|
||
/** | ||
* ID of the project the model belongs to. | ||
*/ | ||
projectId: string, | ||
|
||
/** | ||
* Author of the model. | ||
*/ | ||
author: string, | ||
|
||
/** | ||
* Date the model was created. | ||
*/ | ||
createdAt: string, | ||
|
||
/** | ||
* Identifies the model schema. | ||
*/ | ||
schema: string, | ||
|
||
/** | ||
* Identifies the application that created the metadata model. | ||
*/ | ||
creatingApplication: string, | ||
|
||
/** | ||
* Metaobject parameters. | ||
*/ | ||
metaObjects: MetaObjectParams[], | ||
|
||
/** | ||
* Property set parameters. | ||
*/ | ||
propertySets: MetaPropertySetParams[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Legacy metadata object parameters. | ||
*/ | ||
export interface MetaObjectParams { | ||
|
||
/** | ||
* IDs of propery sets linked to the metadata object. | ||
*/ | ||
propertySetIds: string[]; | ||
|
||
/** | ||
* Property sets belonging to the metadata object. | ||
*/ | ||
propertySets?: string[]; | ||
|
||
/** | ||
* The original system ID of the metadata object. | ||
*/ | ||
originalSystemId?: string; | ||
|
||
/** | ||
* The ID of the metadata object. | ||
*/ | ||
id:string, | ||
|
||
/** | ||
* The name of the metadata object. | ||
*/ | ||
name: string, | ||
|
||
/** | ||
* The type of the metadata object. | ||
*/ | ||
type: string, | ||
|
||
/** | ||
* ID of the parent metadata object. | ||
*/ | ||
parent: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Legacy metadata property parameters. | ||
*/ | ||
export interface MetaPropertyParams { | ||
|
||
/** | ||
* The name of the property. | ||
* | ||
* @property name | ||
* @type {String} | ||
*/ | ||
name: string; | ||
|
||
/** | ||
* The type of the property. | ||
* | ||
* @property type | ||
* @type {Number|String} | ||
*/ | ||
type: string; | ||
|
||
/** | ||
* The value of the property. | ||
* | ||
* @property value | ||
* @type {*} | ||
*/ | ||
value: string; | ||
|
||
/** | ||
* The type of the property's value. | ||
* | ||
* @property valueType | ||
* @type {Number|String} | ||
*/ | ||
valueType: string; | ||
|
||
/** | ||
* Informative text to explain the property. | ||
* | ||
* @property name | ||
* @type {String} | ||
*/ | ||
description: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
import {MetaPropertyParams} from "./MetaPropertyParams"; | ||
|
||
/** | ||
* Legacy metadata property set parameters. | ||
*/ | ||
export interface MetaPropertySetParams { | ||
|
||
/** | ||
* Globally-unique ID for the metadata property set. | ||
*/ | ||
id: string; | ||
|
||
/** | ||
* ID of the corresponding object within the originating system, if any. | ||
*/ | ||
originalSystemId: string; | ||
|
||
/** | ||
* Human-readable name of the metadata property set. | ||
*/ | ||
name: string; | ||
|
||
/** | ||
* Type of the metadata property set. | ||
*/ | ||
type: string; | ||
|
||
/** | ||
* Properties within the metadata property set. | ||
*/ | ||
properties: MetaPropertyParams []; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type {DataModelParams, DataObjectParams, RelationshipParams} from "@xeokit/data"; | ||
import {IfcRelAggregates, ifcTypeCodes} from "@xeokit/ifctypes"; | ||
import {MetaModelParams} from "./MetaModelParams"; | ||
|
||
/*** | ||
* Converts a {@link @xeokit/metamodel!MetaModelParams | MetaModelParams} to a {@link @xeokit/data!DataModelParams | DataModelParams}. | ||
*/ | ||
export function convertMetaModel(metaModelParams: MetaModelParams): DataModelParams { | ||
const dataModelParams: DataModelParams = { | ||
id: "", | ||
objects: [], | ||
relationships: [], | ||
propertySets: [] | ||
}; | ||
if (metaModelParams.propertySets) { | ||
for (let i = 0, len = metaModelParams.propertySets.length; i < len; i++) { | ||
const propertySetParams = metaModelParams.propertySets[i]; | ||
if (!propertySetParams.properties) { // HACK: https://github.com/Creoox/creoox-ifc2gltfcxconverter/issues/8 | ||
propertySetParams.properties = []; | ||
} | ||
dataModelParams.propertySets.push(propertySetParams); | ||
} | ||
} | ||
if (metaModelParams.metaObjects) { | ||
for (let i = 0, len = metaModelParams.metaObjects.length; i < len; i++) { | ||
const metaObject = metaModelParams.metaObjects[i]; | ||
dataModelParams.objects.push({ | ||
id: metaObject.id, | ||
name: metaObject.name, | ||
type: 0//metaObject.type | ||
}); | ||
if (metaObject.parent) { | ||
dataModelParams.relationships.push(<RelationshipParams>{ | ||
relatingObjectId: metaObject.parent, | ||
relatedObjectId: metaObject.id, | ||
type: IfcRelAggregates | ||
}) | ||
} | ||
} | ||
} | ||
return dataModelParams; | ||
} |
Oops, something went wrong.