Skip to content

Commit

Permalink
fix: local file fetch in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchappell committed Dec 31, 2024
1 parent 59cdbe8 commit 5aa734c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib/js/constants.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pkg from '../../../package.json' with { type: 'json' }
import { uuid } from './common/utils/index.mjs'

const isProd = import.meta.env?.PROD
const { env, resolve } = import.meta

const name = pkg.name
export const version = pkg.version
Expand All @@ -13,9 +13,9 @@ export const POLYFILLS = [
{ name: 'mutationObserver', src: '//cdn.jsdelivr.net/npm/mutationobserver-shim/dist/mutationobserver.min.js' },
{ name: 'fetch', src: 'https://unpkg.com/unfetch/polyfill' },
]
export const SVG_SPRITE_URL = isProd
export const SVG_SPRITE_URL = env?.PROD
? `https://cdn.jsdelivr.net/npm/formeo@${version}/dist/${formeoSpriteId}.svg`
: `assets/img/${formeoSpriteId}.svg`
: resolve(`../../lib/icons/${formeoSpriteId}.svg`)
export const FALLBACK_SVG_SPRITE_URL = `https://draggable.github.io/formeo/assets/img/${formeoSpriteId}.svg`
export const CSS_URL = `https://cdn.jsdelivr.net/npm/formeo@${version}/dist/formeo.min.css`
export const FALLBACK_CSS_URL = 'https://draggable.github.io/formeo/assets/css/formeo.min.css'
Expand Down
61 changes: 61 additions & 0 deletions tools/copy-assets.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// copyDir.mjs
import { promises as fs } from 'node:fs';
import { join, basename, resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

const __dirname = dirname(fileURLToPath(import.meta.url));

const projectRoot = resolve(__dirname, '..');



const targets = [
{
src: resolve(projectRoot, 'src/lib/icons/formeo-sprite.svg'),
dest: resolve(projectRoot, 'dist/demo/assets/img/'),
},
{
src: resolve(projectRoot, 'src/lib/icons/formeo-sprite.svg'),
dest: resolve(projectRoot, 'dist/'),
},
{
src: resolve(projectRoot, 'node_modules', '@draggable/formeo-languages/dist/lang/*'),
dest: resolve(projectRoot, 'dist/demo/assets/lang'),
},
{
src: resolve(projectRoot, 'dist/formeo.umd.js'),
dest: resolve(projectRoot, 'dist/demo/assets/js/'),
rename: 'formeo.min.js',
},
{
src: resolve(projectRoot, 'dist/formeo.umd.js'),
dest: resolve(projectRoot, 'dist/'),
rename: 'formeo.min.js',
},
{
src: resolve(projectRoot, 'dist/formeo.min.css'),
dest: resolve(projectRoot, 'dist/demo/assets/css/'),
},
]

async function copyFile(src, dest, rename = null) {
for await (const file of fs.glob(src)) {
const destPath = rename ? join(dest, rename) : join(dest, basename(file));
await fs.mkdir(dirname(destPath), { recursive: true });
await fs.copyFile(file, destPath);
}
}

// Entry point
async function main() {
for (const target of targets) {
try {
await copyFile(target.src, target.dest, target.rename);
console.log(`Copied ${basename(target.src)} to ${target.dest}`);
} catch (error) {
console.error(`Error copying file: ${error.message}`);
}
}
}

main();

0 comments on commit 5aa734c

Please sign in to comment.