-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from juntossomosmais/feat/vuetify-wrapper
feat(Vuetify): creating vuetify wrapper generator
- Loading branch information
Showing
9 changed files
with
161 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { createVueComponent } from './vue' | ||
export { createVueComponent, createVuetifyComponent } from './vue' | ||
export { createReactComponent } from './react' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,59 @@ | ||
import { workspace, Uri } from 'vscode' | ||
|
||
import { TEMPLATES } from './templates' | ||
import { TEMPLATES, VueTemplates } from './templates' | ||
import { VUETIFY_TEMPLATES } from './vuetify/templates' | ||
|
||
export function createVue( | ||
storePath: string, | ||
name: string, | ||
templateFactory?: (name: string) => VueTemplates | ||
) { | ||
const TEMPLATE = templateFactory || TEMPLATES | ||
|
||
export function createVue(storePath: string, name: string) { | ||
workspace.fs.writeFile( | ||
Uri.file(`${storePath}/${name}.vue`), | ||
Buffer.from(TEMPLATES(name).vue) | ||
Buffer.from(TEMPLATE(name).vue) | ||
) | ||
} | ||
|
||
export function createScss(storePath: string, name: string) { | ||
export function createScss( | ||
storePath: string, | ||
name: string, | ||
templateFactory?: (name: string) => VueTemplates | ||
) { | ||
const TEMPLATE = templateFactory || TEMPLATES | ||
|
||
workspace.fs.writeFile( | ||
Uri.file(`${storePath}/${name}.scss`), | ||
Buffer.from(TEMPLATES(name).scss) | ||
Buffer.from(TEMPLATE(name).scss) | ||
) | ||
} | ||
|
||
export function createTest(storePath: string, name: string) { | ||
export function createTest( | ||
storePath: string, | ||
name: string, | ||
templateFactory?: (name: string) => VueTemplates | ||
) { | ||
const TEMPLATE = templateFactory || TEMPLATES | ||
|
||
workspace.fs.writeFile( | ||
Uri.file(`${storePath}/__tests__/${name}.spec.ts`), | ||
Buffer.from(TEMPLATES(name).test) | ||
Buffer.from(TEMPLATE(name).test) | ||
) | ||
} | ||
|
||
export const createFiles = (storePath: string, name: string) => { | ||
createVue(storePath, name) | ||
createScss(storePath, name) | ||
export const createFiles = ( | ||
storePath: string, | ||
name: string, | ||
templateFactory?: (name: string) => VueTemplates | ||
) => { | ||
createVue(storePath, name, templateFactory) | ||
createScss(storePath, name, templateFactory) | ||
createTest(storePath, name, templateFactory) | ||
} | ||
|
||
export const createVuetifyFiles = (storePath: string, name: string) => { | ||
createVue(storePath, name, VUETIFY_TEMPLATES) | ||
createScss(storePath, name, VUETIFY_TEMPLATES) | ||
createTest(storePath, name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { camelCaseName, VueTemplates } from '../templates' | ||
|
||
const className = (name: string): string => { | ||
return `${camelCaseName(name)}__wrapper` | ||
} | ||
|
||
export const VUETIFY_TEMPLATES = (name: string): VueTemplates => { | ||
return { | ||
vue: `<template> | ||
<!-- If you want to use v-model add ':value="value" @input="update" @change="update"' to wrapper tag --> | ||
<V${name} class="${className( | ||
name | ||
)}" v-bind="{ ...$props, ...$attrs }" v-on="$listeners"> | ||
<template v-for="(_, scopedSlotName) in $scopedSlots"#[scopedSlotName]="slotData"> | ||
<slot :name="scopedSlotName" v-bind="slotData" /> | ||
</template> | ||
<template v-for="(_, slotName) in $slots" #[slotName]> | ||
<slot :name="slotName" /> | ||
</template> | ||
</V${name}> | ||
</template> | ||
<script lang="ts"> | ||
// Remember to add V${name} import on '/plugins/vuetify/index.ts | ||
import Vue from 'vue' | ||
export default Vue.extend({ | ||
name: '${name}', | ||
// uncomment lines below if your wrapper uses v-model | ||
/* | ||
props: { | ||
value: {}, | ||
}, | ||
methods: { | ||
update(newValue) { | ||
this.$emit('input', newValue) | ||
this.$emit('change', newValue) | ||
}, | ||
}, | ||
*/ | ||
}) | ||
</script> | ||
<style lang="scss" src="./${name}.scss" scoped />`, | ||
scss: `// ${name}.scss | ||
.${className(name)} { | ||
} `, | ||
test: `import { mount } from '@vue/test-utils' | ||
import ${name} from '../${name}.vue' | ||
describe('${name}.vue', () => { | ||
const wrapper = mount(${name}) | ||
it('Should render component', () => { | ||
expect(wrapper.exists()).toBeTruthy() | ||
}) | ||
})`, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters