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.
- package/bin/strata.js +148 -92
- 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
|
-
// ───
|
|
155
|
-
function
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
187
|
-
|
|
197
|
+
const rl = readline.createInterface({
|
|
198
|
+
input: process.stdin,
|
|
199
|
+
output: process.stdout
|
|
200
|
+
})
|
|
188
201
|
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
//
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
220
|
-
|
|
266
|
+
const hasConcurrently = installConcurrently ||
|
|
267
|
+
pkg.dependencies?.['concurrently'] ||
|
|
268
|
+
pkg.devDependencies?.['concurrently']
|
|
221
269
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
227
|
-
|
|
228
|
-
|
|
277
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2))
|
|
278
|
+
console.log(' ✔ Updated: package.json scripts')
|
|
279
|
+
}
|
|
229
280
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
|
|
259
|
-
console.log(
|
|
260
|
-
|
|
261
|
-
|
|
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
|
+
"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",
|