Skip to content

Commit

Permalink
feat(vue): init and lib generators
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Sep 6, 2023
1 parent 5610f2a commit c3d036d
Show file tree
Hide file tree
Showing 53 changed files with 2,315 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/generated/packages/vite/generators/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"uiFramework": {
"type": "string",
"description": "UI Framework to use for Vite.",
"enum": ["react", "none"],
"enum": ["react", "vue", "none"],
"default": "none",
"x-prompt": "What UI framework plugin should Vite use?"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/vite/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"uiFramework": {
"type": "string",
"description": "UI Framework to use for Vite.",
"enum": ["react", "none"],
"enum": ["react", "vue", "none"],
"default": "react",
"x-prompt": "What UI framework plugin should Vite use?"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/vite/generators/vitest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"uiFramework": {
"type": "string",
"enum": ["react", "none"],
"enum": ["react", "vue", "none"],
"default": "none",
"description": "UI framework to use with vitest."
},
Expand Down
14 changes: 14 additions & 0 deletions docs/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,20 @@
}
]
},
{
"name": "vue",
"id": "vue",
"description": "Vue package.",
"itemList": [
{
"id": "overview",
"path": "/packages/vue",
"name": "Overview of the Nx Vue Plugin",
"description": "The Nx Plugin for Vue contains generators for managing Vue applications and libraries within an Nx workspace. This page also explains how to configure Vue on your Nx workspace.",
"file": "shared/packages/vue/vue-plugin"
}
]
},
{
"name": "webpack",
"id": "webpack",
Expand Down
10 changes: 10 additions & 0 deletions docs/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,16 @@
"generators": ["init", "configuration", "vitest"]
}
},
{
"name": "vue",
"packageName": "vue",
"description": "The Vue plugin for Nx contains executors and generators for managing Vue applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
"path": "generated/packages/vite.json",
"schemas": {
"executors": [],
"generators": ["init", "library", "application", "component"]
}
},
{
"name": "web",
"packageName": "web",
Expand Down
64 changes: 64 additions & 0 deletions docs/shared/packages/vue/vue-plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: Overview of the Nx Vue Plugin
description: The Nx Plugin for Vue contains generators for managing Vue applications and libraries within an Nx workspace. This page also explains how to configure Vue on your Nx workspace.
---

{% callout type="caution" title="`@nx/vue` is not available yet" %}
The `@nx/vue` plugin is not available yet. It will be released soon.
{% /callout %}

The Nx plugin for [Vue](https://vuejs.org/).

## Setting up a new Nx workspace with Vue

You can create a new workspace that uses Vue with one of the following commands:

- Generate a new monorepo with a Vue app set up with Vue

```shell
npx create-nx-workspace@latest --preset=vue
```

## Add Vue to an existing workspace

There is a number of ways to use Vue in your existing workspace.

### Install the `@nx/vue` plugin

{% tabs %}
{% tab label="npm" %}

```shell
npm install -D @nx/vue
```

{% /tab %}
{% tab label="yarn" %}

```shell
yarn add -D @nx/vue
```

{% /tab %}
{% tab label="pnpm" %}

```shell
pnpm install -D @nx/vue
```

{% /tab %}
{% /tabs %}

### Generate a new project using Vue

To generate a Vue application, run the following:

```bash
nx g @nx/vue:app my-app
```

To generate a Vue library, run the following:

```bash
nx g @nx/vue:lib my-lib
```
2 changes: 1 addition & 1 deletion packages/vite/src/generators/configuration/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface ViteConfigurationGeneratorSchema {
uiFramework: 'react' | 'none';
uiFramework: 'react' | 'vue' | 'none';
compiler?: 'babel' | 'swc';
project: string;
newProject?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/generators/configuration/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"uiFramework": {
"type": "string",
"description": "UI Framework to use for Vite.",
"enum": ["react", "none"],
"enum": ["react", "vue", "none"],
"default": "none",
"x-prompt": "What UI framework plugin should Vite use?"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/generators/init/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface InitGeneratorSchema {
uiFramework: 'react' | 'none';
uiFramework: 'react' | 'vue' | 'none';
compiler?: 'babel' | 'swc';
includeLib?: boolean;
testEnvironment?: 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' | string;
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/generators/init/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"uiFramework": {
"type": "string",
"description": "UI Framework to use for Vite.",
"enum": ["react", "none"],
"enum": ["react", "vue", "none"],
"default": "react",
"x-prompt": "What UI framework plugin should Vite use?"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/generators/vitest/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface VitestGeneratorSchema {
project: string;
uiFramework: 'react' | 'none';
uiFramework: 'react' | 'vue' | 'none';
coverageProvider: 'v8' | 'c8' | 'istanbul';
inSourceTests?: boolean;
skipViteConfig?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/generators/vitest/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"uiFramework": {
"type": "string",
"enum": ["react", "none"],
"enum": ["react", "vue", "none"],
"default": "none",
"description": "UI framework to use with vitest."
},
Expand Down
25 changes: 18 additions & 7 deletions packages/vite/src/generators/vitest/vitest-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,24 @@ function updateTsConfig(
projectRoot: string
) {
updateJson(tree, joinPathFragments(projectRoot, 'tsconfig.json'), (json) => {
if (
json.references &&
!json.references.some((r) => r.path === './tsconfig.spec.json')
) {
json.references.push({
path: './tsconfig.spec.json',
});
if (options.uiFramework === 'vue') {
if (
json.references &&
!json.references.some((r) => r.path === './tsconfig.vitest.json')
) {
json.references.push({
path: './tsconfig.vitest.json',
});
}
} else {
if (
json.references &&
!json.references.some((r) => r.path === './tsconfig.spec.json')
) {
json.references.push({
path: './tsconfig.spec.json',
});
}
}

if (!json.compilerOptions?.types?.includes('vitest')) {
Expand Down
Empty file added packages/vue/docs/.gitkeep
Empty file.
18 changes: 17 additions & 1 deletion packages/vue/generators.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
{
"name": "Nx Vue",
"version": "0.1",
"generators": {}
"generators": {
"init": {
"factory": "./src/generators/init/init#vueInitSchematic",
"schema": "./src/generators/init/schema.json",
"description": "Initialize the `@nrwl/vue` plugin.",
"aliases": ["ng-add"],
"hidden": true
},

"library": {
"factory": "./src/generators/library/library",
"schema": "./src/generators/library/schema.json",
"aliases": ["lib"],
"x-type": "library",
"description": "Create a Vue library."
}
}
}
5 changes: 5 additions & 0 deletions packages/vue/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './src/utils/versions';
export { libraryGenerator } from './src/generators/library/library';
export { componentGenerator } from './src/generators/component/component';
export { type InitSchema } from './src/generators/init/schema';
export { vueInitGenerator } from './src/generators/init/init';
6 changes: 5 additions & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
"migrations": "./migrations.json"
},
"dependencies": {
"tslib": "^2.3.0"
"tslib": "^2.3.0",
"@nx/devkit": "file:../devkit",
"@nx/js": "file:../js",
"@nx/linter": "file:../linter",
"@nx/vite": "file:../web"
},
"publishConfig": {
"access": "public"
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`component --export should add to index.ts barrel 1`] = `
"export * from './lib/hello/hello';
"
`;

exports[`component should generate files 1`] = `
"<script setup lang="ts">
defineProps<{}>();
</script>
<template>
<div>
<p>Welcome to Hello!</p>
</div>
</template>
<style scoped>
div {
color: pink;
}
</style>
"
`;

exports[`component should generate files 2`] = `
"import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import Hello from '../hello';
describe('Hello', () => {
it('renders properly', () => {
const wrapper = mount(Hello, { props: {} });
expect(wrapper.text()).toContain('Welcome to Hello');
});
});
"
`;
Loading

0 comments on commit c3d036d

Please sign in to comment.