Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

feat: include vue-cli-plugin-chakra-ui #483

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/ten-eels-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'vue-cli-plugin-chakra-ui': minor
'nuxt-js': patch
'@chakra-ui/vue': patch
'@chakra-ui/nuxt': patch
'@chakra-ui/theme-vue': patch
'chakra-ui-docs': patch
---

feat: create version symlinking for vue-cli-plugin-chakra-ui
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ sw.js
**/lib/plugin.js
**/.nuxt
**/coverage
node_modules
node_modules
**/vue-cli-plugin/generator/template
1 change: 1 addition & 0 deletions examples/nuxt-js/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as icons from './utils/icons'

export default {
ssr: true,
// Target: https://go.nuxtjs.dev/config-target
target: 'static',

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@babel/runtime-corejs2": "^7.8.7",
"@chakra-ui/styled-system": "^1.12.2",
"@changesets/changelog-github": "^0.2.7",
"@changesets/cli": "^2.7.1",
"@changesets/cli": "^2.16.0",
"@changesets/get-github-info": "^0.4.4",
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
Expand Down Expand Up @@ -152,7 +152,7 @@
"mdx-vue": "^1.0.2",
"mdx-vue-loader": "^1.0.2",
"node-fetch": "^2.6.0",
"nuxt": "^2.15.7",
"nuxt": "2.13.3",
"portal-vue": "^2.1.6",
"prettier": "^1.19.1",
"prismjs": "^1.19.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/chakra-ui-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"vue": ">=2.6.10"
},
"devDependencies": {
"@emotion/css": "^11.0.0",
"@emotion/css": "^11.1.3",
"@fortawesome/fontawesome-common-types": "^0.2.36",
"rimraf": "^3.0.2",
"vue": "^2.6.12"
Expand Down
6 changes: 4 additions & 2 deletions packages/chakra-ui-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"name": "Kelvin Omereshone <[email protected]>"
}
],
"files": ["lib"],
"files": [
"lib"
],
"main": "lib/module.js",
"types": "types/index.d.ts",
"scripts": {
Expand All @@ -21,7 +23,7 @@
"dependencies": {
"@chakra-ui/theme-vue": "^0.3.2",
"@chakra-ui/vue": "^0.10.2",
"@emotion/css": "^11.0.0",
"@emotion/css": "^11.1.3",
"chakra-loader": "latest"
},
"peerDependencies": {
Expand Down
9 changes: 9 additions & 0 deletions packages/vue-cli-plugin/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2020 Kelvin Omereshone

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 changes: 39 additions & 0 deletions packages/vue-cli-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# vue-cli-plugin-chakra-ui 🔥

This plugin setups Chakra UI Vue in your Vue CLI generated project.

## Install Vue CLI 3 🔌
If you haven't yet installed vue-cli 3, install it like so:

```
npm install -g @vue/cli
```

or

```
yarn global add @vue/cli
```

>If you still need the legacy `vue init` functionality, you can install a global bridge by following the instructions [here](https://cli.vuejs.org/guide/creating-a-project.html#pulling-2-x-templates-legacy)

Generate a project using vue-cli 3.0:

```vue create my-app```

Before installing the chakra-ui plugin, make sure to commit or stash your changes in case you need to revert the changes.

## Usage 😎
To install the chakra-ui plugin simply navigate to your application's folder and add chakra-ui.

```
vue add chakra-ui
```

The plugin will install [`@chakra-ui/vue`](https://vue.chakra-ui.com) and it's peer dependency - [Emotion](https://emotion.sh)

> As of v1.0.0, If you chose to allow automatic import of Chakra UI components from the prompt in the installation, [Chakra-Loader](https://github.com/chakra-ui/chakra-loader) will be installed for you.

The plugin will also touch `main.js` and `App.vue` to set up your project for consumption of Chakra UI components.

MIT © [Chakra UI](https://github.com/chakra-ui)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const fs = require('fs')
module.exports = function addChakraLoaderConfig (api) {
let content = "const { ChakraLoaderPlugin } = require('chakra-loader')\n\n"
content += 'module.exports = {\n'
content += '\tconfigureWebpack: {\n'
content += '\t\tplugins: [\n'
content += '\t\t\tnew ChakraLoaderPlugin()\n'
content += '\t\t]\n'
content += '\t}\n'
content += '}\n'
fs.appendFileSync('vue.config.js', content)

api.exitLog('Auto import setup completed 🔥')
api.exitLog('You can use Chakra UI components without importing and registering them now')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = function registerChakraVuePlugin (api) {
const vueUseLine = '\n\nVue.use(Chakra)'

const fs = require('fs')

let contentMain = fs.readFileSync(api.entryFile, { encoding: 'utf-8' })

const lines = contentMain.split(/\r?\n/g).reverse()

// eslint-disable-next-line
const lastImportIndex = lines.findIndex(line => line.match(/^import/))

lines[lastImportIndex] += vueUseLine

// modify app
contentMain = lines.reverse().join('\n')

fs.writeFileSync(api.entryFile, contentMain, { encoding: 'utf-8' })
}
39 changes: 39 additions & 0 deletions packages/vue-cli-plugin/generator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const chakraPkg = require('@chakra-ui/vue/package.json')
const emotionPkg = require('@emotion/css/package.json')
const chakraLoaderPkg = require('chakra-loader/package.json')
const registerChakraVuePlugin = require('./helpers/register-chakra-vue-plugin')
const addChakraLoaderConfig = require('./helpers/add-chakra-loader-config')

module.exports = (api, options) => {
api.extendPackage({
dependencies: {
'@chakra-ui/vue': `^${chakraPkg.version}`,
'@emotion/css': `^${emotionPkg.version}`
}
})

if (options.addChakraLoader) {
api.extendPackage({
devDependencies: {
'chakra-loader': `^${chakraLoaderPkg.version}`
}
})
}

api.injectImports(api.entryFile, 'import Chakra from \'@chakra-ui/vue\'')

api.render('./template', {
hasVueRouter: options.hasVueRouter,
hasChakraLoader: options.addChakraLoader
})
api.onCreateComplete(() => {
registerChakraVuePlugin(api)

if (options.addChakraLoader) {
addChakraLoaderConfig(api)
}
})

api.exitLog('Chakra UI Vue is ready')
api.exitLog('Join the community on Discord - https://discord.gg/Tv8Jca')
}
26 changes: 26 additions & 0 deletions packages/vue-cli-plugin/generator/template/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<c-theme-provider>
<c-reset />
<%_ if (hasVueRouter) { _%>
<router-view />
<%_ } else { _%>
<!--Your application goes here -->
<%_ } _%>
</c-theme-provider>
</template>

<script>
<%_ if (!hasChakraLoader) { _%>
import { CThemeProvider, CReset } from "@chakra-ui/vue";
<%_ } _%>

export default {
name: "App",
<%_ if (!hasChakraLoader) { _%>
components: {
CThemeProvider,
CReset
}
<%_ } _%>
};
</script>
1 change: 1 addition & 0 deletions packages/vue-cli-plugin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = (api, options) => { }
39 changes: 39 additions & 0 deletions packages/vue-cli-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "vue-cli-plugin-chakra-ui",
"version": "1.0.3",
"description": "Vue CLI plugin to add Chakra UI Vue",
"main": "index.js",
"scripts": {
"test": "null"
},
"repository": {
"type": "git",
"url": "git+https://github.com/chakra-ui/vue-cli-plugin-chakra-ui.git"
},
"bugs": "https://github.com/chakra-ui/vue-cli-plugin-chakra-ui/issues",
"homepage": "https://github.com/chakra-ui/vue-cli-plugin-chakra-ui#readme",
"author": "Kelvin Omereshone <[email protected]>",
"license": "MIT",
"keywords": [
"vue",
"cli",
"vue-cli",
"ui",
"design-system",
"vue-components",
"uikit",
"accessible",
"components",
"emotion",
"library",
"styled-system"
],
"devDependencies": {
"@changesets/cli": "^2.16.0"
},
"dependencies": {
"@chakra-ui/vue": "^0.10.1",
"@emotion/css": "^11.1.3",
"chakra-loader": "^1.0.3"
}
}
18 changes: 18 additions & 0 deletions packages/vue-cli-plugin/prompts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = [
{
name: 'addChakraLoader',
type: 'confirm',
message: 'Auto import Chakra components?',
description: 'This will allow you to use Chakra components without manually importing and registering them.',
default: false,
validate: input => !!input
},
{
name: 'hasVueRouter',
type: 'confirm',
message: 'Is your project already setup with Vue Router?',
description: 'This will affect how App.vue is setup for you',
default: false,
validate: input => !!input
}
]
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@chakra-ui/nuxt": "^0.4.2",
"@chakra-ui/theme-vue": "^0.3.2",
"@chakra-ui/vue": "^0.10.2",
"@emotion/css": "^11.0.0",
"@emotion/css": "^11.1.3",
"@mdx-js/vue-loader": "^1.6.1",
"@nuxtjs/dotenv": "^1.4.0",
"@nuxtjs/emotion": "^0.1.0",
Expand Down
Loading