UNPKG

@winstonblewup/sass-utils

Version:

My first mini scss utilitary framework

53 lines (42 loc) 1.7 kB
const fs = require('fs'); const path = require('path'); const cwd = process.env.INIT_CWD; const stylesDir = path.join(cwd, 'src/styles'); const scssEntry = path.join(stylesDir, 'main.scss'); const publicDir = path.join(cwd, 'public'); const importLine = `@use "@winstonblewup/sass-utils" as *;`; const pkgPath = path.join(cwd, 'package.json'); let hasSass = false; let pkg = {}; try { if (fs.existsSync(pkgPath)) { pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8')); hasSass = (pkg.devDependencies && pkg.devDependencies['sass']) || (pkg.dependencies && pkg.dependencies['sass']); } } catch (_) {} if (!hasSass) { console.error('❌ Erreur : Sass n\'est pas installé dans ce projet. Exécutez : npm install --save-dev sass'); process.exit(1); } if (!fs.existsSync(stylesDir)) { fs.mkdirSync(stylesDir, { recursive: true }); } if (!fs.existsSync(scssEntry)) { fs.writeFileSync(scssEntry, importLine); } if (!fs.existsSync(publicDir)) { fs.mkdirSync(publicDir, { recursive: true }); } if (!pkg.scripts) pkg.scripts = {}; pkg.scripts['build:css'] = 'sass --load-path=node_modules src/styles/main.scss public/build.css'; pkg.scripts['watch:css'] = 'sass --watch src/styles/main.scss public/build.css'; fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2)); const sourceReadme = path.join(__dirname, 'README.md'); const destReadme = path.join(cwd, 'README-sass-utils.md'); if (fs.existsSync(sourceReadme)) { fs.copyFileSync(sourceReadme, destReadme); console.log(`✅ README copié vers ${destReadme}`); } console.log('✅ Installation terminée. Lancez "npm run build:css" pour compiler votre CSS.');