strata-css 1.0.0 → 1.0.2

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 (3) hide show
  1. package/bin/strata.js +66 -28
  2. package/package.json +2 -2
  3. package/src/index.js +11 -12
package/bin/strata.js CHANGED
@@ -11,9 +11,19 @@ const { getWatchFiles } = require('../src/scanner/scanner')
11
11
  const args = process.argv.slice(2)
12
12
  const cwd = process.cwd()
13
13
 
14
- function loadConfig() {
15
- const configPath = path.resolve(cwd, 'strata.config.js')
16
- try { return require(configPath) } catch { return {} }
14
+ function loadConfig(cwd) {
15
+ const configPath = path.resolve(cwd, 'strata.config.js')
16
+ const configPathCjs = path.resolve(cwd, 'strata.config.cjs')
17
+
18
+ if (fs.existsSync(configPathCjs)) {
19
+ try { return require(configPathCjs) } catch {}
20
+ }
21
+
22
+ if (fs.existsSync(configPath)) {
23
+ try { return require(configPath) } catch {}
24
+ }
25
+
26
+ return {}
17
27
  }
18
28
 
19
29
  // ─── JS minifier ──────────────────────────────────────────────────────
@@ -38,7 +48,7 @@ function minifyJS(src) {
38
48
  // --minify → minified CSS + minified JS (smallest possible output)
39
49
 
40
50
  async function build(cssMinify = false, jsMinify = true) {
41
- const config = loadConfig()
51
+ const config = loadConfig(cwd)
42
52
  const inputFile = config.input || path.join(cwd, 'strata.css')
43
53
  const outputFile = config.output || path.join(cwd, 'dist', 'strata.output.css')
44
54
 
@@ -78,7 +88,7 @@ async function watch() {
78
88
  console.log('[Strata] Starting in watch mode...')
79
89
  await build(false, false) // unminified for dev
80
90
 
81
- const config = loadConfig()
91
+ const config = loadConfig(cwd)
82
92
  const contentGlobs = config.content || ['./src/**/*.{html,jsx,tsx,vue,astro,svelte,js,ts}']
83
93
  const inputFile = config.input || path.join(cwd, 'strata.css')
84
94
  const watchFiles = [inputFile, ...getWatchFiles(contentGlobs)]
@@ -100,28 +110,56 @@ async function watch() {
100
110
  console.log('[Strata] Watching for changes...')
101
111
  }
102
112
 
103
- // ─── Init ─────────────────────────────────────────────────────────────
104
- function init() {
105
- console.log('[Strata] Initializing project...')
106
-
107
- const files = {
108
- 'strata.config.js': `module.exports = {\n content: ["./src/**/*.{html,jsx,tsx,vue,astro,svelte,js,ts}"],\n input: "./strata.css",\n output: "./dist/strata.output.css"\n}\n`,
109
- 'strata.css': `@strata base;\n@strata components;\n@strata utilities;\n`,
110
- 'postcss.config.js':`module.exports = { plugins: [require('strata-css'), require('autoprefixer')] }\n`,
113
+ // ─── ESM / framework helpers ──────────────────────────────────────────
114
+ function isESMProject(cwd) {
115
+ try {
116
+ const pkg = JSON.parse(fs.readFileSync(path.resolve(cwd, 'package.json'), 'utf8'))
117
+ return pkg.type === 'module'
118
+ } catch {
119
+ return false
111
120
  }
121
+ }
112
122
 
113
- for (const [filename, content] of Object.entries(files)) {
114
- const filePath = path.join(cwd, filename)
115
- if (fs.existsSync(filePath)) {
116
- console.log(`[Strata] Skipped (exists): ${filename}`)
117
- } else {
118
- fs.writeFileSync(filePath, content)
119
- console.log(`[Strata] Created: ${filename}`)
120
- }
121
- }
123
+ function detectOutputPath(cwd) {
124
+ try {
125
+ const pkg = JSON.parse(fs.readFileSync(path.resolve(cwd, 'package.json'), 'utf8'))
126
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies }
127
+ if (deps['astro']) return './public/strata.output.css'
128
+ if (deps['laravel-vite-plugin']) return './public/strata.output.css'
129
+ if (deps['next']) return './public/strata.output.css'
130
+ if (deps['react']) return './public/strata.output.css'
131
+ if (deps['vue']) return './public/strata.output.css'
132
+ if (deps['@sveltejs/kit']) return './public/strata.output.css'
133
+ } catch {}
134
+ return './dist/strata.output.css'
135
+ }
122
136
 
123
- fs.mkdirSync(path.join(cwd, 'dist'), { recursive: true })
124
- console.log('\n[Strata] Done! Run: npm run dev')
137
+ // ─── Init ─────────────────────────────────────────────────────────────
138
+ function init() {
139
+ const isESM = isESMProject(cwd)
140
+ const output = detectOutputPath(cwd)
141
+
142
+ console.log('[Strata] Initializing project...')
143
+ console.log(`[Strata] Detected: ${isESM ? 'ESM' : 'CommonJS'} project`)
144
+
145
+ const configFile = isESM ? 'strata.config.cjs' : 'strata.config.js'
146
+ const postcssFile = isESM ? 'postcss.config.cjs' : 'postcss.config.js'
147
+
148
+ const configContent = `module.exports = {\n content: ["./src/**/*.{html,jsx,tsx,vue,astro,svelte,js,ts}"],\n input: "./strata.css",\n output: "${output}"\n}\n`
149
+ const postcssContent = `module.exports = {\n plugins: [\n require('strata-css'),\n require('autoprefixer')\n ]\n}\n`
150
+ const strataCssContent = `@strata base;\n@strata components;\n@strata utilities;\n`
151
+
152
+ fs.writeFileSync(path.resolve(cwd, configFile), configContent)
153
+ fs.writeFileSync(path.resolve(cwd, postcssFile), postcssContent)
154
+ fs.writeFileSync(path.resolve(cwd, 'strata.css'), strataCssContent)
155
+
156
+ console.log(`[Strata] Created: ${configFile}`)
157
+ console.log(`[Strata] Created: strata.css`)
158
+ console.log(`[Strata] Created: ${postcssFile}`)
159
+ console.log(`[Strata] Done! Next steps:`)
160
+ console.log(`[Strata] 1. Add <link rel="stylesheet" href="/strata.output.css"> to your HTML`)
161
+ console.log(`[Strata] 2. Add data-st-theme="light" to your <html> tag`)
162
+ console.log(`[Strata] 3. Run: node node_modules/strata-css/bin/strata.js --build`)
125
163
  }
126
164
 
127
165
  // ─── Run ──────────────────────────────────────────────────────────────
@@ -132,8 +170,8 @@ else if (args.includes('--build')) build(false, true)
132
170
  else console.log(`
133
171
  Strata CSS
134
172
 
135
- strata init scaffold a new project
136
- strata --watch development mode (unminified, fast rebuild)
137
- strata --build production build (minified JS, readable CSS)
138
- strata --minify production build (minified CSS + JS, smallest output)
173
+ strata-css init scaffold a new project
174
+ strata-css --watch development mode (unminified, fast rebuild)
175
+ strata-css --build production build (minified JS, readable CSS)
176
+ strata-css --minify production build (minified CSS + JS, smallest output)
139
177
  `)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strata-css",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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",
@@ -10,7 +10,7 @@
10
10
  "./package.json": "./package.json"
11
11
  },
12
12
  "bin": {
13
- "strata": "bin/strata.js"
13
+ "strata-css": "bin/strata.js"
14
14
  },
15
15
  "files": [
16
16
  "src/",
package/src/index.js CHANGED
@@ -22,19 +22,18 @@ let cachedConfigPath = null
22
22
  let cachedConfigMtime = 0
23
23
 
24
24
  function loadConfig(cwd) {
25
- const configPath = path.resolve(cwd, 'strata.config.js')
26
- let mtime = 0
27
- try { mtime = fs.statSync(configPath).mtimeMs } catch {}
28
- if (cachedConfig && cachedConfigPath === configPath && cachedConfigMtime === mtime) {
29
- return cachedConfig
25
+ const configPath = path.resolve(cwd, 'strata.config.js')
26
+ const configPathCjs = path.resolve(cwd, 'strata.config.cjs')
27
+
28
+ if (fs.existsSync(configPathCjs)) {
29
+ try { return require(configPathCjs) } catch {}
30
30
  }
31
- try {
32
- delete require.cache[require.resolve(configPath)]
33
- cachedConfig = require(configPath)
34
- cachedConfigPath = configPath
35
- cachedConfigMtime = mtime
36
- } catch { cachedConfig = {} }
37
- return cachedConfig
31
+
32
+ if (fs.existsSync(configPath)) {
33
+ try { return require(configPath) } catch {}
34
+ }
35
+
36
+ return {}
38
37
  }
39
38
 
40
39
  // ─── Base CSS ─────────────────────────────────────────────────────────