diff --git a/src/lib/js/constants.js b/src/lib/js/constants.js index f5af954..84246cb 100644 --- a/src/lib/js/constants.js +++ b/src/lib/js/constants.js @@ -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 @@ -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' diff --git a/tools/copy-assets.mjs b/tools/copy-assets.mjs new file mode 100644 index 0000000..73a0c9c --- /dev/null +++ b/tools/copy-assets.mjs @@ -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();