strata-css 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/strata.js +148 -92
  2. package/package.json +1 -1
package/bin/strata.js CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  const fs = require('fs')
6
6
  const path = require('path')
7
+ const readline = require('readline')
7
8
  const chokidar = require('chokidar')
8
9
  const strata = require('../src/index')
9
10
  const { getWatchFiles } = require('../src/scanner/scanner')
@@ -11,6 +12,20 @@ const { getWatchFiles } = require('../src/scanner/scanner')
11
12
  const args = process.argv.slice(2)
12
13
  const cwd = process.cwd()
13
14
 
15
+ function ask(rl, question) {
16
+ return new Promise(resolve => rl.question(question, resolve))
17
+ }
18
+
19
+ function askYesNo(rl, question, defaultYes = true) {
20
+ const hint = defaultYes ? '[Y/n]' : '[y/N]'
21
+ return new Promise(resolve => {
22
+ rl.question(`${question} ${hint} `, answer => {
23
+ if (!answer.trim()) return resolve(defaultYes)
24
+ resolve(answer.trim().toLowerCase().startsWith('y'))
25
+ })
26
+ })
27
+ }
28
+
14
29
  function loadConfig(cwd) {
15
30
  const configPath = path.resolve(cwd, 'strata.config.js')
16
31
  const configPathCjs = path.resolve(cwd, 'strata.config.cjs')
@@ -151,118 +166,159 @@ function detectFramework(cwd) {
151
166
  return 'generic'
152
167
  }
153
168
 
154
- // ─── Script injection ─────────────────────────────────────────────────
155
- function injectScripts(cwd, framework) {
156
- const pkgPath = path.resolve(cwd, 'package.json')
157
- const strataWatch = 'node node_modules/strata-css/bin/strata.js --watch'
158
- const strataBuild = 'node node_modules/strata-css/bin/strata.js --build'
159
-
160
- try {
161
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
162
- if (!pkg.scripts) pkg.scripts = {}
169
+ // ─── Init ─────────────────────────────────────────────────────────────
170
+ async function init() {
171
+ const isESM = isESMProject(cwd)
172
+ const framework = detectFramework(cwd)
173
+ const output = detectOutputPath(cwd)
163
174
 
164
- const frameworkDev = {
165
- 'astro': 'astro dev',
166
- 'laravel': 'vite',
167
- 'next': 'next dev',
168
- 'sveltekit': 'vite dev',
169
- 'nuxt': 'nuxt dev',
170
- 'react-vite': 'vite',
171
- 'vue-vite': 'vite',
172
- 'generic': pkg.scripts.dev || 'npm start'
173
- }
175
+ const frameworkDev = {
176
+ 'astro': 'astro dev',
177
+ 'laravel': 'vite',
178
+ 'next': 'next dev',
179
+ 'sveltekit': 'vite dev',
180
+ 'nuxt': 'nuxt dev',
181
+ 'react-vite': 'vite',
182
+ 'vue-vite': 'vite',
183
+ 'generic': 'npm start'
184
+ }
174
185
 
175
- const frameworkBuild = {
176
- 'astro': 'astro build',
177
- 'laravel': 'vite build',
178
- 'next': 'next build',
179
- 'sveltekit': 'vite build',
180
- 'nuxt': 'nuxt build',
181
- 'react-vite': 'vite build',
182
- 'vue-vite': 'vite build',
183
- 'generic': pkg.scripts.build || 'npm run build'
184
- }
186
+ const frameworkBuild = {
187
+ 'astro': 'astro build',
188
+ 'laravel': 'vite build',
189
+ 'next': 'next build',
190
+ 'sveltekit': 'vite build',
191
+ 'nuxt': 'nuxt build',
192
+ 'react-vite': 'vite build',
193
+ 'vue-vite': 'vite build',
194
+ 'generic': 'npm run build'
195
+ }
185
196
 
186
- const devCmd = frameworkDev[framework]
187
- const buildCmd = frameworkBuild[framework]
197
+ const rl = readline.createInterface({
198
+ input: process.stdin,
199
+ output: process.stdout
200
+ })
188
201
 
189
- const hasConcurrently = pkg.dependencies?.['concurrently'] ||
190
- pkg.devDependencies?.['concurrently']
202
+ console.log('')
203
+ console.log(' strata Setup initiated.')
204
+ console.log('')
205
+ console.log(` ◼ Framework detected : ${framework}`)
206
+ console.log(` ◼ Project type : ${isESM ? 'ESM' : 'CommonJS'}`)
207
+ console.log(` ◼ Output path : ${output}`)
208
+ console.log('')
209
+
210
+ const installConcurrently = await askYesNo(rl,
211
+ ' deps Install concurrently for clean parallel dev?')
212
+
213
+ const updateScripts = await askYesNo(rl,
214
+ ' scripts Auto-update package.json dev and build scripts?')
215
+
216
+ console.log('')
217
+ console.log(' html Where is your main HTML or layout file?')
218
+ console.log(' Examples:')
219
+ console.log(' src/layouts/Layout.astro')
220
+ console.log(' resources/views/layouts/app.blade.php')
221
+ console.log(' src/App.jsx')
222
+ console.log(' index.html')
223
+ const htmlFile = await ask(rl,
224
+ ' Path (leave blank to skip): ')
225
+
226
+ rl.close()
227
+ console.log('')
228
+
229
+ // Create config files
230
+ const configFile = isESM ? 'strata.config.cjs' : 'strata.config.js'
231
+ const postcssFile = isESM ? 'postcss.config.cjs' : 'postcss.config.js'
191
232
 
192
- if (hasConcurrently) {
193
- pkg.scripts.dev = `concurrently "${devCmd}" "${strataWatch}"`
194
- } else {
195
- pkg.scripts.dev = `${strataWatch} & ${devCmd}`
196
- }
233
+ const configContent = `module.exports = {\n content: ["./src/**/*.{html,jsx,tsx,vue,astro,svelte,js,ts}"],\n input: "./strata.css",\n output: "${output}"\n}\n`
234
+ const postcssContent = `module.exports = {\n plugins: [\n require('strata-css'),\n require('autoprefixer')\n ]\n}\n`
235
+ const strataCssContent = `@strata base;\n@strata components;\n@strata utilities;\n`
197
236
 
198
- pkg.scripts.build = `${strataBuild} && ${buildCmd}`
199
- pkg.scripts['strata:watch'] = strataWatch
200
- pkg.scripts['strata:build'] = strataBuild
237
+ fs.writeFileSync(path.resolve(cwd, configFile), configContent)
238
+ fs.writeFileSync(path.resolve(cwd, postcssFile), postcssContent)
239
+ fs.writeFileSync(path.resolve(cwd, 'strata.css'), strataCssContent)
201
240
 
202
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2))
203
- return true
204
- } catch (e) {
205
- return false
241
+ console.log(` ✔ Created: ${configFile}`)
242
+ console.log(` ✔ Created: strata.css`)
243
+ console.log(` ✔ Created: ${postcssFile}`)
244
+
245
+ // Install concurrently
246
+ if (installConcurrently) {
247
+ console.log(' ◼ Installing concurrently...')
248
+ require('child_process').execSync(
249
+ 'npm install --save-dev concurrently',
250
+ { stdio: 'inherit', cwd }
251
+ )
252
+ console.log(' ✔ concurrently installed')
206
253
  }
207
- }
208
254
 
209
- // ─── Init ─────────────────────────────────────────────────────────────
210
- function init() {
211
- const isESM = isESMProject(cwd)
212
- const output = detectOutputPath(cwd)
213
- const framework = detectFramework(cwd)
255
+ // Update package.json scripts
256
+ if (updateScripts) {
257
+ const strataWatch = 'node node_modules/strata-css/bin/strata.js --watch'
258
+ const strataBuild = 'node node_modules/strata-css/bin/strata.js --build'
259
+ const devCmd = frameworkDev[framework] || 'npm start'
260
+ const buildCmd = frameworkBuild[framework] || 'npm run build'
214
261
 
215
- console.log('[Strata] Initializing project...')
216
- console.log(`[Strata] Detected: ${isESM ? 'ESM' : 'CommonJS'} project`)
217
- console.log(`[Strata] Framework: ${framework}`)
262
+ const pkgPath = path.resolve(cwd, 'package.json')
263
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
264
+ if (!pkg.scripts) pkg.scripts = {}
218
265
 
219
- const configFile = isESM ? 'strata.config.cjs' : 'strata.config.js'
220
- const postcssFile = isESM ? 'postcss.config.cjs' : 'postcss.config.js'
266
+ const hasConcurrently = installConcurrently ||
267
+ pkg.dependencies?.['concurrently'] ||
268
+ pkg.devDependencies?.['concurrently']
221
269
 
222
- const configContent = `module.exports = {\n content: ["./src/**/*.{html,jsx,tsx,vue,astro,svelte,js,ts}"],\n input: "./strata.css",\n output: "${output}"\n}\n`
223
- const postcssContent = `module.exports = {\n plugins: [\n require('strata-css'),\n require('autoprefixer')\n ]\n}\n`
224
- const strataCssContent = `@strata base;\n@strata components;\n@strata utilities;\n`
270
+ pkg.scripts.dev = hasConcurrently
271
+ ? `concurrently "${strataWatch}" "${devCmd}"`
272
+ : `${strataWatch} & ${devCmd}`
273
+ pkg.scripts.build = `${strataBuild} && ${buildCmd}`
274
+ pkg.scripts['strata:watch'] = strataWatch
275
+ pkg.scripts['strata:build'] = strataBuild
225
276
 
226
- fs.writeFileSync(path.resolve(cwd, configFile), configContent)
227
- fs.writeFileSync(path.resolve(cwd, postcssFile), postcssContent)
228
- fs.writeFileSync(path.resolve(cwd, 'strata.css'), strataCssContent)
277
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2))
278
+ console.log(' ✔ Updated: package.json scripts')
279
+ }
229
280
 
230
- console.log(`[Strata] Created: ${configFile}`)
231
- console.log(`[Strata] Created: strata.css`)
232
- console.log(`[Strata] Created: ${postcssFile}`)
233
-
234
- const injected = injectScripts(cwd, framework)
235
-
236
- if (injected) {
237
- let hasConcurrently = false
238
- try {
239
- const pkg = JSON.parse(fs.readFileSync(path.resolve(cwd, 'package.json'), 'utf8'))
240
- hasConcurrently = !!(pkg.dependencies?.['concurrently'] || pkg.devDependencies?.['concurrently'])
241
- } catch {}
242
-
243
- console.log(`[Strata] Updated package.json scripts:`)
244
- console.log(`[Strata] dev → runs Strata watcher + framework dev server`)
245
- console.log(`[Strata] build → runs Strata build then framework build`)
246
- console.log(`[Strata] strata:watch → node node_modules/strata-css/bin/strata.js --watch`)
247
- console.log(`[Strata] strata:build node node_modules/strata-css/bin/strata.js --build`)
248
-
249
- if (!hasConcurrently) {
250
- console.log(`[Strata]`)
251
- console.log(`[Strata] Tip: install concurrently for cleaner parallel dev:`)
252
- console.log(`[Strata] npm install --save-dev concurrently`)
281
+ // Inject CSS link and theme into HTML file
282
+ if (htmlFile && htmlFile.trim()) {
283
+ const htmlPath = path.resolve(cwd, htmlFile.trim())
284
+ if (fs.existsSync(htmlPath)) {
285
+ let content = fs.readFileSync(htmlPath, 'utf8')
286
+ const cssLink = `\t\t<link rel="stylesheet" href="/strata.output.css">`
287
+ const themeAttr = 'data-st-theme="light"'
288
+
289
+ if (!content.includes('strata.output.css')) {
290
+ content = content.replace('</head>', `${cssLink}\n\t</head>`)
291
+ }
292
+ if (!content.includes('data-st-theme')) {
293
+ content = content.replace('<html', `<html ${themeAttr}`)
294
+ }
295
+
296
+ fs.writeFileSync(htmlPath, content)
297
+ console.log(` ✔ Updated: ${htmlFile.trim()}`)
298
+ } else {
299
+ console.log(` ✗ File not found: ${htmlFile.trim()} — skipped`)
253
300
  }
254
- } else {
255
- console.log(`[Strata] Warning: could not update package.json scripts — update manually.`)
256
301
  }
257
302
 
258
- console.log(`[Strata] Done! Next steps:`)
259
- console.log(`[Strata] 1. Add <link rel="stylesheet" href="/strata.output.css"> to your HTML`)
260
- console.log(`[Strata] 2. Add data-st-theme="light" to your <html> tag`)
261
- console.log(`[Strata] 3. Run: npm run dev`)
303
+ // Run initial build
304
+ console.log(' ◼ Running initial build...')
305
+ await strata.build(
306
+ path.resolve(cwd, 'strata.css'),
307
+ path.resolve(cwd, output.replace('./', '')),
308
+ { cwd }
309
+ )
310
+ console.log(' ✔ Initial build complete')
311
+
312
+ console.log('')
313
+ console.log(' strata Setup complete!')
314
+ console.log('')
315
+ console.log(' next Your project is ready.')
316
+ console.log(' Run npm run dev to start.')
317
+ console.log('')
262
318
  }
263
319
 
264
320
  // ─── Run ──────────────────────────────────────────────────────────────
265
- if (args[0] === 'init') init()
321
+ if (args[0] === 'init') init().catch(console.error)
266
322
  else if (args.includes('--watch')) watch()
267
323
  else if (args.includes('--minify')) build(true, true)
268
324
  else if (args.includes('--build')) build(false, true)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strata-css",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "_versioningNote": "Stable: 1.0.0 / 1.1.0 / 2.0.0 | Beta: 1.1.0-beta.1 / 1.1.0-beta.2",
5
5
  "description": "A modern CSS framework combining Bootstrap components with Tailwind JIT processing",
6
6
  "main": "src/index.js",