Skip to content

Commit 368e63a

Browse files
committed
refactor: resolve conversations
1 parent 07984cd commit 368e63a

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

imageLoader.mjs renamed to generateImages.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import { fileURLToPath } from 'url';
43

54
import { fetchURL, write } from 'image-js';
65

76
import { defaultImages, defaultMasks } from './imageDataset.mjs';
87

9-
const __filename = fileURLToPath(import.meta.url);
10-
const __dirname = path.dirname(__filename);
8+
const __dirname = import.meta.dirname;
119

1210
export async function imageLoader() {
1311
const demoImagesDir = 'demoImages';
@@ -72,12 +70,14 @@ export async function imageLoader() {
7270
});
7371
}
7472
// Write data about newly created files.
75-
const outputPath = path.join(
76-
__dirname,
77-
'src/demo/contexts/demo/imageData.json',
73+
const outputPath = path.join(__dirname, 'src/demo/contexts/demo/generated');
74+
if (!fs.existsSync(outputPath)) {
75+
fs.mkdirSync(outputPath, { recursive: true });
76+
}
77+
fs.writeFileSync(
78+
`${outputPath}/imageData.json`,
79+
JSON.stringify(imageData, null, 2),
7880
);
79-
80-
fs.writeFileSync(outputPath, JSON.stringify(imageData, null, 2));
8181
} catch (error) {
8282
throw new Error(`Error in imageLoader: ${error.message}`);
8383
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"build": "docusaurus build",
77
"clear": "docusaurus clear",
88
"deploy": "docusaurus deploy",
9-
"generate-images": "node imageLoader.mjs",
9+
"generate-images": "node generateImages.mjs",
1010
"cspell": "cspell lint \"**/*.md\"",
1111
"eslint": "eslint --cache ./src ./docs",
1212
"eslint-fix": "npm run eslint -- --fix",

src/demo/contexts/demo/defaultImages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { UrlOption } from '../importImage/importImageContext';
22

3-
import dataset from './imageData.json';
3+
import dataset from './generated/imageData.json';
44

55
const defaultImages = dataset.images as UrlOption[];
66
const defaultMasks = dataset.masks as UrlOption[];

src/demo/contexts/demo/imageData.json renamed to src/demo/contexts/demo/generated/imageData.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,4 @@
117117
"value": "/demoImages/images/airport.png"
118118
}
119119
]
120-
}
120+
}

0 commit comments

Comments
 (0)