Skip to content

Commit fe6a42c

Browse files
committed
Use local css-doodle file first
1 parent f8e9cda commit fe6a42c

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

bin/handler.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,20 @@ export async function handleGenerateShape(source) {
8484

8585
export async function handleSetConfig(field, value) {
8686
if (field === 'css-doodle') {
87-
const { result, error } = await fetchCssDoodleSource(value);
88-
if (error) {
89-
return console.error(error.message);
90-
}
91-
try {
92-
const libPath = path.join(configDownloadPath, `css-doodle-${value}.js`);
93-
fs.writeFileSync(libPath, result);
94-
config[field] = libPath;
95-
} catch (e) {
96-
return console.error(`error: failed to fetch css-doodle@${value}`);
87+
if (fs.existsSync(value)) {
88+
config[field] = path.resolve(value);
89+
} else {
90+
const { result, error } = await fetchCssDoodleSource(value);
91+
if (error) {
92+
return console.error(error.message);
93+
}
94+
try {
95+
const libPath = path.join(configDownloadPath, `css-doodle-${value}.js`);
96+
fs.writeFileSync(libPath, result);
97+
config[field] = libPath;
98+
} catch (e) {
99+
return console.error(`error: failed to fetch css-doodle@${value}`);
100+
}
97101
}
98102
} else {
99103
config[field] = value;

src/preview/server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { readFileSync } from 'node:fs';
2-
import { createServer } from 'http';
2+
import { createServer } from 'node:http';
3+
34
import { WebSocketServer } from 'ws';
45
import watch from 'node-watch';
6+
57
import { previewClient, getCssDoodleLib } from '../static.js';
68

79
const sourceFile = process.argv[2];

0 commit comments

Comments
 (0)