pocka / figspec

Unofficial Figma spec viewer: Live Embed Kit - Live + Guides + Inspector

Home Page:https://pocka.github.io/figspec/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Script generates only an empty file

Tim-arts opened this issue · comments

Hello, I've tried to set up the figspec plugin into my project and everytime I'm running the command to generate the files I get this error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'fs' imported from C:\Users\path\to\scripts\generateStaticFigmaFile\index.mjs
at packageResolve (internal/modules/esm/resolve.js:650:9)
at moduleResolve (internal/modules/esm/resolve.js:691:18)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:784:11)
at Loader.resolve (internal/modules/esm/loader.js:100:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:246:28)
at ModuleWrap. (internal/modules/esm/module_job.js:47:40)
at link (internal/modules/esm/module_job.js:46:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
error Command failed with exit code 1.

I've tried to replace:
import * as fs from "fs/promises";
By:
import { promises as fs } from 'fs';

But when I execute the command, the folder contains only an empty file. Any idea how to fix this?

Updating Node has fixed the error but the generation succeeds with only one empty file created:

image

@pocka I've found the issue, it seems that the filesystem is struggling to create files containing ":" in their names. I've tried this and the files are actually being created:

// Current implementation
await Promise.all( files.map(async (file) => { await fs.writeFile(path.resolve(outDir, file.filename), file.data); }) );

// What works on my side
await Promise.all( files.map(async (file) => { await fs.writeFile(path.resolve(outDir, file.filename.replace(':', '-')), file.data); }) );

I'm aware the change is dirty, it's just an example. From what I could find double points are not allowed on windows, but should be allowed on linux: https://stackoverflow.com/questions/4814040/allowed-characters-in-filename

AFAIK, the script is tested/run only on Linux (maybe macOS too?). Since the script is for development and testing, feel free to create a PR for the files.