UNPKG

zz-shopify-components

Version:

Reusable Shopify components for theme projects

48 lines (39 loc) 1.42 kB
#!/usr/bin/env node const fs = require('fs'); const path = require('path'); const fse = require('fs-extra'); const COMPONENT_DIRS = ['sections', 'blocks', 'snippets', 'assets']; const ROOT_DIR = path.resolve(__dirname); // 组件库自身 const TARGET_DIR = process.cwd(); // 使用组件库的项目目录 // 读取 ignore 配置 let ignoreList = []; const configPath = path.join(ROOT_DIR, 'component.config.json'); if (fs.existsSync(configPath)) { try { const config = JSON.parse(fs.readFileSync(configPath, 'utf-8')); ignoreList = config.ignore || []; } catch (e) { console.warn('[postinstall] Failed to parse component.config.json', e); } } // 是否应忽略某个文件 const shouldIgnore = (relativePath) => { return ignoreList.includes(relativePath.replace(/\\/g, '/')); }; // 拷贝文件逻辑 COMPONENT_DIRS.forEach((dirName) => { const sourceDir = path.join(ROOT_DIR, dirName); const targetDir = path.join(TARGET_DIR, dirName); if (!fs.existsSync(sourceDir)) return; fse.readdirSync(sourceDir).forEach((file) => { const relPath = `${dirName}/${file}`; if (shouldIgnore(relPath)) { console.log(`[postinstall] Ignored: ${relPath}`); return; } const src = path.join(sourceDir, file); const dest = path.join(targetDir, file); fse.copySync(src, dest, { overwrite: true }); console.log(`[postinstall] Copied: ${relPath}`); }); });