csdnsynchexo
Version:
支持csdn/博客园/掘金/segmentfault/腾讯云加社区等平台一键迁移hexo
51 lines (50 loc) • 1.65 kB
JavaScript
import program from 'commander';
import path from 'path';
import { run } from './core/index.js';
import { error, info } from './log/index.js';
// cli
import pkg from '../package.json' with { type: 'json' };
import fs from 'fs-extra';
export const cli = async () => {
program
.version(pkg.version)
.option('-c, --config [config]', '配置文件相对路径')
.option('-o, --output [output]', '本地生成博客源md文件路径')
.option('--userId [userId]', '用户id')
.option('--cookie [cookie]', 'cookie信息')
.option('--imgConfig, [imgConfig]', 'beta: 图片转存配置文件路径,详情请参考 https://picgo.github.io/PicGo-Core-Doc/zh/guide/config.html#%E9%BB%98%E8%AE%A4%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6')
.option('--type [type]', '网站类型,例如csdn juejin等')
.parse(process.argv);
let config = {};
if (program.config) {
// 配置文件
try {
const configPath = path.resolve(process.cwd(), program.config);
config = await fs.readJson(configPath);
}
catch (e) {
error(e);
}
}
else {
// 命令行
config = {
output: program.output,
userId: program.userId,
cookie: program.cookie,
type: program.type,
imgConfig: program.imgConfig,
};
}
info('版本', pkg.version);
info('运行配置:');
for (let [k, v] of Object.entries(config)) {
if (v) {
info(k, v);
}
}
info('\n');
await run(config);
};
cli();