Skip to content

Commit

Permalink
feat: update init tailwind bin (#8)
Browse files Browse the repository at this point in the history
Co-authored-by: khoilen <[email protected]>
  • Loading branch information
khoilen and khoilen authored Dec 18, 2024
1 parent a79c78a commit bfcfdd5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 26 deletions.
9 changes: 5 additions & 4 deletions apps/nt-stylesheet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ You can install **nt-stylesheet** via npm or pnpm.
### Using npm

```sh
npm install nt-stylesheet
npx nt-stylesheet
```

### Usage
Expand All @@ -35,15 +35,16 @@ You can customize nt-stylesheet by editing the `tailwind.config.js` file. Add yo

```js
/** @type {import('tailwindcss').Config} */
const ntTheme = require('nt-stylesheet/dist/theme.cjs')
const ntTheme = require('nt-stylesheet/dist/theme.cjs');

module.exports = {
content: ['*.{html,js}'],
theme: {
extend: ntTheme.theme.extend,
extend: ntTheme.extend,
},
plugins: [],
}
};

```

### Acknowledgements
Expand Down
62 changes: 45 additions & 17 deletions apps/nt-stylesheet/bin/init-tailwind.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
#!/usr/bin/env node

import fs from 'fs'
import { exec } from 'child_process'
import readline from 'readline'

const installPackage = (packageName) => {
return new Promise((resolve, reject) => {
exec(`npm install ${packageName}`, (error) => {
if (error) {
console.error(
`Error installing ${packageName}: ${error.message}`,
)
reject(error)
return
}
console.log(`${packageName} installed successfully!`)
resolve()
})
})
}

const createTailwindConfig = () => {
const tailwindConfigContent = `/** @type {import('tailwindcss').Config} */
const ntTheme = require('nt-stylesheet/dist/theme.cjs');
module.exports = {
content: ['*.{html,js}'],
theme: {
extend: ntTheme.theme.extend,
extend: ntTheme.extend,
},
plugins: [],
};
Expand Down Expand Up @@ -59,20 +76,31 @@ const createPostCSSConfig = () => {
)
}

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})
const initialize = async () => {
try {
await installPackage('nt-stylesheet')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})

rl.question(
'Do you want to initialize Tailwind CSS? (y/n) ',
(answer) => {
if (answer.toLowerCase() === 'y') {
createTailwindConfig()
createPostCSSConfig()
} else {
console.log('Tailwind CSS initialization skipped.')
}
rl.close()
},
)
rl.question(
'Do you want to initialize Tailwind CSS? (y/n) ',
(answer) => {
if (answer.toLowerCase() === 'y') {
createTailwindConfig()
createPostCSSConfig()
} else {
console.log(
'Tailwind CSS initialization skipped.',
)
}
rl.close()
},
)
} catch (error) {
console.error('Initialization failed:', error)
}
}

initialize()
7 changes: 2 additions & 5 deletions apps/nt-stylesheet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nt-stylesheet",
"version": "1.1.7",
"version": "1.1.8",
"description": "",
"packageManager": "[email protected]",
"scripts": {
Expand All @@ -19,10 +19,7 @@
"main": "./dist/theme.umd.cjs",
"module": "./dist/theme.js",
"exports": {
".": {
"import": "./dist/theme.js",
"require": "./dist/theme.umd.cjs"
}
"./dist/theme.cjs": "./dist/theme.cjs"
},
"devEngines": {
"node": "20.x "
Expand Down

0 comments on commit bfcfdd5

Please sign in to comment.