Skip to content
Merged
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
30 changes: 18 additions & 12 deletions packages/fes-plugin-vuex/src/helper.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
import { join } from 'node:path';
import { parser, winPath } from '@fesjs/utils';
import { readdirSync, readFileSync, statSync } from 'fs';
import { join } from 'path';

/**
* 获取文件夹所有JS文件路径
* @param {string} dir
*/
function getDirFilePaths(dir) {
if (!existsSync(dir)) {
return [];
}
const dirs = readdirSync(dir);
let pathList = [];
for (const name of dirs) {
const path = winPath(join(dir, name));
const info = statSync(path);
if (info.isDirectory()) {
pathList = pathList.concat(getDirFilePaths(path));
} else if (path.endsWith('.js')) {
}
else if (path.endsWith('.js')) {
pathList.push(path);
}
}
Expand All @@ -29,8 +33,8 @@ function pathToHump(path, root) {
return path
.replace(root, '')
.replace('.js', '')
.replace(RegExp('(/|\\.|-|_)\\S', 'g'), (text) => text[1].toUpperCase())
.replace(/\S/, (text) => text.toLowerCase());
.replace(RegExp('(/|\\.|-|_)\\S', 'g'), text => text[1].toUpperCase())
.replace(/\S/, text => text.toLowerCase());
}

/**
Expand All @@ -45,7 +49,7 @@ function getModelTypes(ast, name, namespace = '') {
getters: {},
};
let namespaced = false;
if (ast.type !== 'ObjectExpression') return types;
if (ast.type !== 'ObjectExpression') { return types; }
ast.properties.forEach((node) => {
if (node.key.name === 'namespaced' && node.value.value) {
namespaced = true;
Expand All @@ -56,7 +60,6 @@ function getModelTypes(ast, name, namespace = '') {
if (namespaced) {
type = types[node.key.name][name];
if (!type) {
// eslint-disable-next-line no-multi-assign
type = types[node.key.name][name] = {};
}
}
Expand All @@ -77,7 +80,8 @@ function getModelTypes(ast, name, namespace = '') {
...subTypes[key],
...types[key][name],
};
} else {
}
else {
types[key] = {
...subTypes[key],
...types[key],
Expand Down Expand Up @@ -112,8 +116,9 @@ function parseModel(paths = [], root) {
sourceType: 'module',
plugins: ['jsx', 'typescript'],
});
ast = ast.program.body.filter((body) => body.type === 'ExportDefaultDeclaration')[0];
} catch (err) { }
ast = ast.program.body.filter(body => body.type === 'ExportDefaultDeclaration')[0];
}
catch (err) { }
if (ast) {
const { mutations, actions, getters } = getModelTypes(ast.declaration, moduleName);
MUTATION_TYPES = {
Expand Down Expand Up @@ -155,9 +160,10 @@ export function parseStore(root) {
const modelPaths = [];
const pluginPaths = [];
paths.forEach((path) => {
if (path.indexOf('plugin') > -1) {
if (path.includes('plugin')) {
pluginPaths.push(path);
} else {
}
else {
modelPaths.push(path);
}
});
Expand Down