Skip to content

Commit

Permalink
fix: no such file or directory:public/data
Browse files Browse the repository at this point in the history
  • Loading branch information
chennlang committed Jun 26, 2024
1 parent 71311fd commit 4dd5219
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ node_modules
dist
dist-ssr
*.local
public
**/server/public/data/**
walk-file
vscode-plugin
117 changes: 55 additions & 62 deletions packages/server/bin/service.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,76 @@
#!/usr/bin/env node

const server = require('../src/index')
const path = require('path')
const AnalyPluginNames = require('../plugins/analy-plugin-names')
const { program } = require('commander');

const server = require("../src/index");
const path = require("path");
const AnalyPluginNames = require("../plugins/analy-plugin-names");
const { program } = require("commander");

// 默认配置
const defaultConfig = {
root: '',
ignore: ['**/node_modules/**', '**/dist/**'],
extensions: ['.js', '.ts','.tsx','.vue', '.json', 'jsx'],
alias: {
'@@/': '/',
'~~/': '/',
'@/': '/src/',
'~/': '/src/',
},
outputPath: path.resolve(__dirname, '../public/data'),
server: {
port: 8088,
host: 'localhost',
openBrowser: false,
},
plugins: [
AnalyPluginNames,
],
}

root: "",
ignore: ["**/node_modules/**", "**/dist/**"],
extensions: [".js", ".ts", ".tsx", ".vue", ".json", "jsx"],
alias: {
"@@/": "/",
"~~/": "/",
"@/": "/src/",
"~/": "/src/",
},
outputPath: path.resolve(__dirname, "../public/data"),
server: {
port: 8088,
host: "localhost",
openBrowser: false,
},
plugins: [AnalyPluginNames],
};

program
.version(`${require('../package').version}`, '-v, --version')
.option('-c, --config [file]', 'config file path')
.option('-r, --root [file]', 'root path');
.version(`${require("../package").version}`, "-v, --version")
.option("-c, --config [file]", "config file path")
.option("-r, --root [file]", "root path");

program.parse(process.argv);

function isObject (v) {
return Object.prototype.toString.call(v) === '[object Object]'
function isObject(v) {
return Object.prototype.toString.call(v) === "[object Object]";
}

function isArray (v) {
return Object.prototype.toString.call(v) === '[object Array]'
function isArray(v) {
return Object.prototype.toString.call(v) === "[object Array]";
}

function mergeConfig (config, target) {
const appendAttrs = [
'ignore',
'plugins',
'server',
]
const res = {}
Object.keys(config).forEach(attr => {
// replace attrs
if (!appendAttrs.includes(attr)) {
res[attr] = target[attr] || config[attr]
} else {
// need merger
if (isObject(config[attr]) && isObject(target[attr])) {
res[attr] = Object.assign(config[attr], target[attr])
} else if (isArray(config[attr]) && isArray(target[attr])) {
res[attr] = config[attr].concat(target[attr])
} else {
res[attr] = target[attr] || config[attr]
}
}

})
return res
function mergeConfig(config, target) {
const appendAttrs = ["ignore", "plugins", "server"];
const res = {};
Object.keys(config).forEach((attr) => {
// replace attrs
if (!appendAttrs.includes(attr)) {
res[attr] = target[attr] || config[attr];
} else {
// need merger
if (isObject(config[attr]) && isObject(target[attr])) {
res[attr] = Object.assign(config[attr], target[attr]);
} else if (isArray(config[attr]) && isArray(target[attr])) {
res[attr] = config[attr].concat(target[attr]);
} else {
res[attr] = target[attr] || config[attr];
}
}
});
return res;
}

let config = defaultConfig
let config = defaultConfig;
if (program._optionValues.config) {
const configPath = program._optionValues.config
config = mergeConfig(config, require(path.resolve(process.cwd(), configPath)))
const configPath = program._optionValues.config;
config = mergeConfig(
config,
require(path.resolve(process.cwd(), configPath))
);
}
if (program._optionValues.root) {
config.root = path.resolve(process.cwd(), program._optionValues.root)
config.root = path.resolve(process.cwd(), program._optionValues.root);
}

server.start(config)

server.start(config);
4 changes: 1 addition & 3 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
"files": [
"bin",
"libs",
"public/assets",
"public/favicon.png",
"public/index.html",
"public",
"src",
"plugins"
],
Expand Down
Binary file added packages/web/public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4dd5219

Please sign in to comment.