Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get all nuxt components #4

Merged
merged 3 commits into from
Jul 17, 2021
Merged
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
22 changes: 6 additions & 16 deletions dist/module.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
import glob from 'glob';
import { resolve } from 'path';
import consola from 'consola';
export default function stormModule(moduleOptions) {
if (process.env.NODE_ENV === 'production') {
return;
}
const { nuxt } = this;
let count = 0;
const logger = consola.withScope('nuxt:storm');
const components = glob.sync(`${nuxt.options.srcDir}/components/**/*.vue`).map(file => {
let name;
if (moduleOptions.nested) {
name = file.match(/components\/(.*?).vue$/)[1].replace(/\//g, '');
}
else {
name = file.match(/(\w*)\.vue$/)[1];
// If file is an index.vue file, use folder name instead
if (name === 'index') {
name = file.replace('/index.vue', '').split('/').reverse()[0];
}
}
count++;
return { name, file };
let components;
this.nuxt.hook('components:extend', dirs => {
components = [...dirs].map(file => {
count++;
return { name: file.pascalName, file: file.filePath };
});
});
const getComponents = () => components;
if (moduleOptions.nested) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuxt-storm",
"version": "1.0.8",
"version": "1.1.0",
"private": false,
"description": " PHPStorm support for NuxtJS components",
"repository": "https://github.com/fumeapp/nuxt-storm",
Expand Down
25 changes: 7 additions & 18 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
import glob from 'glob'
import { resolve } from 'path'
import consola from 'consola'

export default function stormModule (moduleOptions) {
if (process.env.NODE_ENV === 'production') {
return
}

const { nuxt } = this

let count = 0
const logger = consola.withScope('nuxt:storm')

const components = glob.sync(`${nuxt.options.srcDir}/components/**/*.vue`).map(file => {
let name
if (moduleOptions.nested) {
name = file.match(/components\/(.*?).vue$/)[1].replace(/\//g, '')
} else {
name = file.match(/(\w*)\.vue$/)[1]
// If file is an index.vue file, use folder name instead
if (name === 'index') {
name = file.replace('/index.vue', '').split('/').reverse()[0]
}
}
count++
return { name, file }
})
let components
this.nuxt.hook('components:extend', dirs => {
components = [...dirs].map(file => {
count++
return { name: file.pascalName, file: file.filePath}
})
});

const getComponents = () => components

Expand Down