Skip to content

Commit

Permalink
add nuxt plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckyMaler committed Sep 9, 2020
1 parent e9a1f83 commit bab1e75
Show file tree
Hide file tree
Showing 46 changed files with 3,125 additions and 47 deletions.
5 changes: 5 additions & 0 deletions apps/nuxt-e2e/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
name: 'nuxt-e2e',
preset: '../../jest.config.js',
coverageDirectory: '../../coverage/apps/nuxt-e2e',
};
87 changes: 87 additions & 0 deletions apps/nuxt-e2e/tests/nuxt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { tags } from '@angular-devkit/core';
import {
checkFilesExist,
ensureNxProject,
runNxCommandAsync,
uniq,
} from '@nrwl/nx-plugin/testing';
describe('nuxt e2e', () => {
it('should generate app', async (done) => {
const appName = uniq('app');
ensureNxProject('@nx-plus/nuxt', 'dist/libs/nuxt');
await runNxCommandAsync(`generate @nx-plus/nuxt:app ${appName}`);

const lintResult = await runNxCommandAsync(`lint ${appName}`);
expect(lintResult.stdout).toContain('All files pass linting.');

const testResult = await runNxCommandAsync(`test ${appName}`);
expect(testResult.stderr).toContain(tags.stripIndent`
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
`);

const e2eResult = await runNxCommandAsync(`e2e ${appName}-e2e --headless`);
expect(e2eResult.stdout).toContain('All specs passed!');

await runNxCommandAsync(`build ${appName}`);
expect(() =>
checkFilesExist(
`dist/apps/${appName}/utils.js`,
`dist/apps/${appName}/server.js`,
`dist/apps/${appName}/routes.json`,
`dist/apps/${appName}/router.scrollBehavior.js`,
`dist/apps/${appName}/router.js`,
`dist/apps/${appName}/middleware.js`,
`dist/apps/${appName}/loading.html`,
`dist/apps/${appName}/jsonp.js`,
`dist/apps/${appName}/index.js`,
`dist/apps/${appName}/empty.js`,
`dist/apps/${appName}/client.js`,
`dist/apps/${appName}/App.js`,
`dist/apps/${appName}/views`,
`dist/apps/${appName}/vetur`,
`dist/apps/${appName}/mixins`,
`dist/apps/${appName}/dist`,
`dist/apps/${appName}/components`
)
).not.toThrow();

done();
}, 300000);

describe('--directory subdir', () => {
it('should generate app', async (done) => {
const appName = uniq('app');
ensureNxProject('@nx-plus/nuxt', 'dist/libs/nuxt');
await runNxCommandAsync(
`generate @nx-plus/nuxt:app ${appName} --directory subdir`
);

await runNxCommandAsync(`build subdir-${appName}`);
expect(() =>
checkFilesExist(
`dist/apps/subdir/${appName}/utils.js`,
`dist/apps/subdir/${appName}/server.js`,
`dist/apps/subdir/${appName}/routes.json`,
`dist/apps/subdir/${appName}/router.scrollBehavior.js`,
`dist/apps/subdir/${appName}/router.js`,
`dist/apps/subdir/${appName}/middleware.js`,
`dist/apps/subdir/${appName}/loading.html`,
`dist/apps/subdir/${appName}/jsonp.js`,
`dist/apps/subdir/${appName}/index.js`,
`dist/apps/subdir/${appName}/empty.js`,
`dist/apps/subdir/${appName}/client.js`,
`dist/apps/subdir/${appName}/App.js`,
`dist/apps/subdir/${appName}/views`,
`dist/apps/subdir/${appName}/vetur`,
`dist/apps/subdir/${appName}/mixins`,
`dist/apps/subdir/${appName}/dist`,
`dist/apps/subdir/${appName}/components`
)
).not.toThrow();

done();
}, 300000);
});
});
13 changes: 13 additions & 0 deletions apps/nuxt-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"include": [],
"files": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
]
}
9 changes: 9 additions & 0 deletions apps/nuxt-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
5 changes: 5 additions & 0 deletions libs/nuxt/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../.eslintrc",
"rules": {},
"ignorePatterns": ["!**/*"]
}
153 changes: 153 additions & 0 deletions libs/nuxt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Nx Plus Nuxt

> First class support for [Nuxt](https://nuxtjs.org/) in your [Nx](https://nx.dev/) workspace.
<div align="center">
<img src="https://raw.githubusercontent.com/ZachJW34/nx-plus/master/libs/nuxt/nx-plus-nuxt.png">
</div>

## Contents

- [Prerequisite](#prerequisite)
- [Getting Started](#getting-started)
- [Schematics (i.e. code generation)](#schematics-ie-code-generation)
- [Builders (i.e. task runners)](#builders-ie-task-runners)
- [Configuring Nuxt.js](#configuring-nuxtjs)
- [Updating Nx Plus Nuxt](#updating-nx-plus-nuxt)

## Prerequisite

If you have not already, [create an Nx workspace](https://github.com/nrwl/nx#creating-an-nx-workspace) with the following:

```
npx create-nx-workspace@^10.0.0
```

When creating your Nx workspace you may be prompted to choose a preset, **we do not support the `oss` preset at this time**.

## Getting Started

### Install Plugin

```
# npm
npm install @nx-plus/nuxt --save-dev
# yarn
yarn add @nx-plus/nuxt --dev
```

### Generate Your App

```
nx g @nx-plus/nuxt:app my-app
```

### Serve Your App

```
nx serve my-app
```

## Schematics (i.e. code generation)

### Application

`nx g @nx-plus/nuxt:app <name> [options]`

| Arguments | Description |
| --------- | --------------------- |
| `<name>` | The name of your app. |

| Options | Default | Description |
| ------------------ | --------- | ---------------------------------------------- |
| `--tags` | - | Tags to use for linting (comma-delimited). |
| `--directory` | `apps` | A directory where the project is placed. |
| `--unitTestRunner` | `jest` | Test runner to use for unit tests. |
| `--e2eTestRunner` | `cypress` | Test runner to use for end to end (e2e) tests. |
| `--skipFormat` | `false` | Skip formatting files. |

## Builders (i.e. task runners)

### Dev Server

`nx serve <name> [options]`

| Arguments | Description |
| --------- | --------------------- |
| `<name>` | The name of your app. |

| Options | Default | Description |
| ----------------- | ------- | ----------------------------------------------------- |
| `--browserTarget` | - | Target to serve. |
| `--dev` | `true` | Define the development or production mode of Nuxt.js. |

### Browser

`nx build <name> [options]`

| Arguments | Description |
| --------- | --------------------- |
| `<name>` | The name of your app. |

| Options | Default | Description |
| ------------ | ------- | ------------------------------------------------------- |
| `--buildDir` | - | Define the dist directory for your Nuxt.js application. |

### Configuring Nuxt.js

By default, Nuxt.js is configured to cover most use cases. This default configuration can be overwritten with the `nuxt.config.js` file. For more information see the [NuxtJS documentation](https://nuxtjs.org/guides/directory-structure/nuxt-config#nuxtconfigjs).

### Linting

`nx lint <name> [options]`

We use `@nrwl/linter` for linting, so the options are as documented [here](https://github.com/nrwl/nx/blob/master/docs/angular/api-linter/builders/lint.md#lint).

### Unit Testing

`nx test <name> [options]`

We use `@nrwl/jest` for unit testing, so the options are as documented [here](https://github.com/nrwl/nx/blob/master/docs/angular/api-jest/builders/jest.md#jest).

### E2E Testing

`nx e2e <name> [options]`

We use `@nrwl/cypress` for e2e testing, so the options are as documented [here](https://github.com/nrwl/nx/blob/master/docs/angular/api-cypress/builders/cypress.md#cypress).

## Updating Nx Plus Nuxt

Nx Plus Nuxt provides migrations which help you stay up to date with the latest version of Nx Plus Nuxt.

Not only do we migrate the version of Nx Plus Nuxt, but we also update the versions of dependencies which we install such as `nuxt` and `@nuxt/types`.

We recommend waiting for Nx Plus Nuxt to update these dependencies for you as we verify that these versions work together.

### How to Migrate

#### Generate migrations.json

All you have to do to update Nx Plus Nuxt to the latest version is run the following:

```
nx migrate @nx-plus/nuxt
nx migrate @nx-plus/nuxt@version # you can also specify version
```

This will fetch the specified version of `@nx-plus/nuxt`, analyze the dependencies and fetch all the dependent packages. The process will keep going until the whole tree of dependencies is resolved. This will result in:

- `package.json` being updated
- `migrations.json` being generated

At this point, no packages have been installed, and no other files have been touched.

Now, you can inspect `package.json` to see if the changes make sense and install the packages by running `npm install` or `yarn`.

#### Run Migrations

`migrations.json` contains the transformations that must run to prepare the workspace to the newly installed versions of packages. To run all the migrations, invoke:

```
nx migrate --run-migrations=migrations.json
```
15 changes: 15 additions & 0 deletions libs/nuxt/builders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../../node_modules/@angular-devkit/architect/src/builders-schema.json",
"builders": {
"browser": {
"implementation": "./src/builders/browser/builder",
"schema": "./src/builders/browser/schema.json",
"description": "browser builder"
},
"server": {
"implementation": "./src/builders/server/builder",
"schema": "./src/builders/server/schema.json",
"description": "server builder"
}
}
}
13 changes: 13 additions & 0 deletions libs/nuxt/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "../../node_modules/@angular-devkit/schematics/collection-schema.json",
"name": "nuxt",
"version": "0.0.1",
"schematics": {
"application": {
"factory": "./src/schematics/application/schematic",
"schema": "./src/schematics/application/schema.json",
"description": "application schematic",
"aliases": ["app"]
}
}
}
10 changes: 10 additions & 0 deletions libs/nuxt/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
name: 'nuxt',
preset: '../../jest.config.js',
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
coverageDirectory: '../../coverage/libs/nuxt',
globals: { 'ts-jest': { tsConfig: '<rootDir>/tsconfig.spec.json' } },
};
Binary file added libs/nuxt/nx-plus-nuxt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions libs/nuxt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@nx-plus/nuxt",
"version": "0.0.1",
"main": "src/index.js",
"schematics": "./collection.json",
"builders": "./builders.json",
"description": "Nuxt plugin for Nx",
"repository": {
"type": "git",
"url": "git+https://github.com/ZachJW34/nx-plus.git"
},
"keywords": [
"nx",
"nuxt",
"vuex",
"jest",
"cypress",
"monorepo"
],
"author": "Bucky Maler <[email protected]> (http://buckymaler.com/)",
"contributors": [
"Zachary Williams <[email protected]> (https://github.com/ZachJW34/)"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/ZachJW34/nx-plus/issues"
},
"homepage": "https://github.com/ZachJW34/nx-plus/tree/master/libs/nuxt#readme",
"peerDependencies": {
"@nrwl/workspace": "^10.0.0"
},
"dependencies": {
"@angular-devkit/architect": "0.1000.7",
"@angular-devkit/core": "10.0.7",
"@angular-devkit/schematics": "10.0.7",
"@nrwl/cypress": "^10.0.0",
"@nrwl/jest": "^10.0.0",
"@nrwl/linter": "^10.0.0",
"rxjs": "6.5.5"
}
}
Loading

0 comments on commit bab1e75

Please sign in to comment.