Skip to content

Commit

Permalink
Merge pull request #1039 from vuejs/nuxt
Browse files Browse the repository at this point in the history
Nuxt support. Fix #870. For nuxt/nuxt#4524
  • Loading branch information
octref authored Dec 26, 2018
2 parents 288f766 + a8cfbf5 commit c123302
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"eslint-plugin-vue": "^4.0.0",
"js-beautify": "^1.7.5",
"lodash": "^4.17.4",
"nuxt-helper-json": "^1.0.0",
"parse-gitignore": "^1.0.1",
"prettier": "^1.15.2",
"prettier-eslint": "^8.8.1",
Expand Down
23 changes: 18 additions & 5 deletions server/src/modes/template/tagProviders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { IHTMLTagProvider } from './common';
import * as ts from 'typescript';
import * as fs from 'fs';
import { join } from 'path';
import { getNuxtTagProvider } from './nuxtTags';

export let allTagProviders: IHTMLTagProvider[] = [
getHTML5TagProvider(),
Expand All @@ -42,14 +43,15 @@ export function getTagProviderSettings(workspacePath: string | null | undefined)
bootstrap: false,
buefy: false,
vuetify: false,
quasar: false
quasar: false,
nuxt: false
};
if (!workspacePath) {
return settings;
}
try {
const packagePath = ts.findConfigFile(workspacePath, ts.sys.fileExists, 'package.json');
if(!packagePath) {
if (!packagePath) {
return settings;
}
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8'));
Expand All @@ -71,14 +73,25 @@ export function getTagProviderSettings(workspacePath: string | null | undefined)
if (packageJson.dependencies['vuetify']) {
settings['vuetify'] = true;
}
if (
packageJson.dependencies['nuxt'] ||
packageJson.dependencies['nuxt-legacy'] ||
packageJson.dependencies['nuxt-edge']
) {
const nuxtTagProvider = getNuxtTagProvider(workspacePath);
if (nuxtTagProvider) {
settings['nuxt'] = true;
allTagProviders.push(nuxtTagProvider);
}
}

for(const dep in packageJson.dependencies) {
for (const dep in packageJson.dependencies) {
const runtimePkgPath = ts.findConfigFile(
workspacePath,
ts.sys.fileExists,
join('node_modules', dep, 'package.json')
);
);

if (!runtimePkgPath) {
continue;
}
Expand Down
43 changes: 43 additions & 0 deletions server/src/modes/template/tagProviders/nuxtTags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as fs from 'fs';
import * as path from 'path';
import { getExternalTagProvider } from './externalTagProviders';

const NUXT_VUE_APP_PATH = 'node_modules/@nuxt/vue-app';
const NUXT_EDGE_VUE_APP_PATH = 'node_modules/@nuxt/vue-app-edge';

export function getNuxtTagProvider(workspacePath: string) {
if (fs.existsSync(path.resolve(workspacePath, NUXT_VUE_APP_PATH, 'package.json'))) {
const { nuxtTags, nuxtAttributes } = getNuxtTagsAndAttributes(NUXT_VUE_APP_PATH);
return getExternalTagProvider('nuxt', nuxtTags, nuxtAttributes);
}

if (fs.existsSync(path.resolve(workspacePath, NUXT_EDGE_VUE_APP_PATH, 'package.json'))) {
const { nuxtTags, nuxtAttributes } = getNuxtTagsAndAttributes(NUXT_EDGE_VUE_APP_PATH);
return getExternalTagProvider('nuxt', nuxtTags, nuxtAttributes);
}
}

function getNuxtTagsAndAttributes(nuxtVueAppPath: string) {
let nuxtVer = '0.0.0';
try {
nuxtVer = require(path.resolve(nuxtVueAppPath, 'package.json')).version;
} catch (err) {}

if (nuxtVer < '2.4.0') {
const nuxtTags = require('nuxt-helper-json/nuxt-tags.json');
const nuxtAttributes = require('nuxt-helper-json/nuxt-attributes.json');

return {
nuxtTags,
nuxtAttributes
};
} else {
const nuxtTags = require(path.resolve(nuxtVueAppPath, 'vetur/nuxt-tags.json'));
const nuxtAttributes = require(path.resolve(nuxtVueAppPath, 'vetur/nuxt-attributes.json'));

return {
nuxtTags,
nuxtAttributes
};
}
}
5 changes: 5 additions & 0 deletions server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3109,6 +3109,11 @@ number-is-nan@^1.0.0:
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"
integrity sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=

nuxt-helper-json@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/nuxt-helper-json/-/nuxt-helper-json-1.0.0.tgz#7a8a78c2d49749bf39d01cc26b8234ea0a91bf6b"
integrity sha512-MwFMhg8Xwjlo7dJeAuUImJxVMwyGGXfSjE7COiw0cAT7bFVJrA11ZJCwLrqPZQBfuBq3QxL8Q3/GzqA0BDr+Ug==

nyc@^13.0.1:
version "13.1.0"
resolved "https://registry.yarnpkg.com/nyc/-/nyc-13.1.0.tgz#463665c7ff6b5798e322624a5eb449a678db90e3"
Expand Down

0 comments on commit c123302

Please sign in to comment.