Files
sveltesociety.dev/scripts/tarball.js
Lachlan Collins 156f65436c feat: Add script to check if packages pass publint (#523)
* Add zod schemas for CI validation

* Require npm field for components.json

* Remove svelte-layout-resizable

* Stricter Zod validation

* Stricter repository field validation

* Implement requested changes

* Add back accidentally removed field

* Move SvelteStore to templates.json

* Update category and tags

* Add script to get npm data

* Add script to get publint data

* Re-run updateNpm.js

* Re-run updatePublint.js

* Implement initial feedback

* Use npm.json data

* Update npm.js

* Switch async/await to then/catch

Co-authored-by: MacFJA <MacFJA@users.noreply.github.com>

* Fix prettier

* Run script

* Re-run updateNpm

* Also read tools.json

* Add @types/node

* Restructure npm.json output

* Fix updatePublint.js

* Display last update on components page

* Add to weekly workflow

* Clarify updating npm data

* Update src/lib/utils/injectNpmData.ts

Co-authored-by: MacFJA <MacFJA@users.noreply.github.com>

* Smaller date font, add version

* Improve error text

* Fix property title

* Move json to lib/data directory

* Fix npm.json path

* Also check tools.json

* Add to automated PR

* Add injectPublintData function

* Update publint

---------

Co-authored-by: MacFJA <MacFJA@users.noreply.github.com>
2023-12-18 13:26:25 +11:00

45 lines
1.4 KiB
JavaScript

// @ts-check
// Source: https://github.com/bluwy/publint/blob/master/site/src/utils/tarball.js
/** @typedef {{ name: string, buffer: ArrayBuffer }} TarballFile */
/**
* @param {TarballFile[]} files
* @return {import('publint').Vfs}
* */
export function createTarballVfs(files) {
return {
getDirName: (path) => path.replace(/\/[^/]*$/, ''),
getExtName: (path) => path.replace(/^.*\./, '.'),
isPathDir: async (path) => {
path = path.endsWith('/') ? path : path + '/';
return files.some((file) => file.name.startsWith(path));
},
isPathExist: async (path) => {
const pathDirVariant = path.endsWith('/') ? path : path + '/';
return files.some((file) => file.name === path || file.name.startsWith(pathDirVariant));
},
pathJoin: (...parts) =>
parts
.map((v) => (v.startsWith('./') ? v.slice(2) : v))
.join('/')
.replace('///', '/')
.replace('//', '/'), // TODO: optimize this please
pathRelative: (from, to) => to.replace(from, '').slice(1),
readDir: async (path) => {
path = path.endsWith('/') ? path : path + '/';
return files
.filter((file) => file.name.startsWith(path) && file.name !== path)
.map((file) => file.name.slice(path.length));
},
readFile: async (path) => {
const file = files.find((file) => file.name === path);
if (file) {
return new TextDecoder('utf-8').decode(file.buffer);
} else {
throw new Error(`Unable to read file at path: ${path}`);
}
}
};
}