Skip to content

Commit f777185

Browse files
committed
Fix @tomic/cli handling names as shortnames #1071
1 parent fc2927f commit f777185

File tree

6 files changed

+13
-12
lines changed

6 files changed

+13
-12
lines changed

browser/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ This changelog covers all five packages, as they are (for now) updated as a whol
4040

4141
- [#983](https://github.com/atomicdata-dev/atomic-server/issues/983) Give clear error when name collisions are found in an ontology.
4242
- Generates class definitions that enables doing: `resource.props.name = 'New Name'`;
43-
43+
-
4444
### @tomic/svelte
4545

4646
- [#700](https://github.com/atomicdata-dev/atomic-server/issues/700) Update to Svelte 5. There are significant changes to the API.

browser/cli/src/generateBaseObject.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const generateBaseObject = async (
2020

2121
const classes = dedupe(ontology.props.classes ?? []);
2222
const properties = dedupe(ontology.props.properties ?? []);
23-
const name = camelCaseify(ontology.title);
23+
const name = camelCaseify(ontology.props.shortname);
2424

2525
const baseObj = {
2626
classes: await listToObj(classes, 'classes'),
@@ -45,7 +45,7 @@ const listToObj = async (
4545
list.map(async subject => {
4646
const resource = await store.getResource(subject);
4747

48-
return [camelCaseify(resource.title), subject];
48+
return [camelCaseify(resource.get(core.properties.shortname)), subject];
4949
}),
5050
);
5151

browser/cli/src/generateClassExports.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Resource, urls } from '@tomic/lib';
1+
import { Resource, urls, type Core } from '@tomic/lib';
22
import { atomicConfig } from './config.js';
33
import { ReverseMapping } from './generateBaseObject.js';
44
import { store } from './store.js';
@@ -17,24 +17,24 @@ const NAMESPACE_TEMPLATE = `
1717
`;
1818

1919
export const generateClassExports = (
20-
ontology: Resource,
20+
ontology: Resource<Core.Ontology>,
2121
reverseMapping: ReverseMapping,
2222
): string => {
2323
const classes = ontology.getArray(urls.properties.classes) as string[];
2424

2525
const body = classes
2626
.map(subject => {
27-
const res = store.getResourceLoading(subject);
27+
const res = store.getResourceLoading<Core.Class>(subject);
2828
const objectPath = reverseMapping[subject];
2929

30-
return createExportLine(res.title, objectPath);
30+
return createExportLine(res.props.shortname, objectPath);
3131
})
3232
.join('\n');
3333

3434
if (atomicConfig.useNamespaces) {
3535
return NAMESPACE_TEMPLATE.replace(
3636
Inserts.NamespaceName,
37-
capitalize(ontology.title),
37+
capitalize(ontology.props.shortname),
3838
).replace(Inserts.NamespaceBody, body);
3939
} else {
4040
return body;

browser/cli/src/generateIndex.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { store } from './store.js';
22
import { camelCaseify, getExtension } from './utils.js';
33
import { atomicConfig } from './config.js';
4+
import type { Core } from '@tomic/lib';
45

56
enum Inserts {
67
MODULE_ALIAS = '{{1}}',
@@ -31,9 +32,9 @@ export const generateIndex = (
3132
inludeExternals: boolean,
3233
) => {
3334
const names = ontologies.map(x => {
34-
const res = store.getResourceLoading(x);
35+
const res = store.getResourceLoading<Core.Ontology>(x);
3536

36-
return camelCaseify(res.title);
37+
return camelCaseify(res.props.shortname);
3738
});
3839

3940
if (inludeExternals) {

browser/cli/src/generateOntology.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const generateOntology = async (
7272
.replace(Inserts.PROP_SUBJECT_TO_NAME_MAPPING, subToNameStr);
7373

7474
return {
75-
filename: `${camelCaseify(ontology.title)}.ts`,
75+
filename: `${camelCaseify(ontology.props.shortname)}.ts`,
7676
content,
7777
};
7878
};

browser/cli/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getTsconfig } from 'get-tsconfig';
22

33
export const camelCaseify = (str: string) =>
4-
str.replace(/-([a-z])/g, g => {
4+
str.replace(/-([a-z0-9])/g, g => {
55
return g[1].toUpperCase();
66
});
77

0 commit comments

Comments
 (0)