awstats-cli
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -1,8 +0,9 @@ | ||
const fs = require('fs') | ||
const { existsSync } = require('fs') | ||
const { join } = require('path') | ||
const git = require('simple-git') | ||
const spawn = require('cross-spawn') | ||
const logger = require('../utils/logger') | ||
const { removeAll, resolvePath, fileCopy } = require('../utils') | ||
const { resolvePath, DeepClone, SetVersion } = require('../utils') | ||
const options = { stdio: 'inherit' } | ||
module.exports = function (dirname) { | ||
@@ -30,23 +31,31 @@ if (!dirname) dirname = '' | ||
try { | ||
const themeConfigExists = join(localPath, 'config.yml') | ||
if (fs.existsSync(themeConfigExists)) { | ||
logger.warn('Already Initialize pass') | ||
return | ||
} | ||
removeAll(localPath) | ||
if (existsSync(HomePageConfigFilePath)) { | ||
logger.warn('Already Initialize pass') | ||
return | ||
} | ||
git() | ||
.clone(repoURL, localPath) | ||
.then(() => { | ||
fileCopy(PkgFilePath, RootPkgFilePath) | ||
spawn('npm', ['install'], { cwd: initPath, stdio: 'inherit' }) | ||
fileCopy(configFilePath, RootConfigFilePath) | ||
fileCopy(HomePageConfigFilePath, RootHomePageConfigFilePath) | ||
logger.info('Clone success') | ||
}) | ||
} catch (error) { | ||
logger.err('Clone failure') | ||
logger.err(error) | ||
// 删除多余的文件 | ||
spawn.sync('rm', ['-rf', localPath], options) | ||
// 克隆默认主题 | ||
spawn.sync('git', ['clone', repoURL, localPath], options) | ||
if (!existsSync(HomePageConfigFilePath)) { | ||
logger.err('Initialization failed. Please try again later') | ||
return | ||
} | ||
// // 复制默认信息文件 | ||
spawn.sync('cp', ['-rf', PkgFilePath, RootPkgFilePath], options) | ||
spawn.sync('cp', ['-rf', configFilePath, RootConfigFilePath], options) | ||
spawn.sync('cp', ['-rf', HomePageConfigFilePath, RootHomePageConfigFilePath], options) | ||
// 安装 AWStatas | ||
const newOptions = DeepClone(options) | ||
newOptions.cwd = initPath | ||
spawn.sync('npm', ['install', 'awstats', '--save'], newOptions) | ||
SetVersion() | ||
logger.info('Clone success') | ||
} |
{ | ||
"name": "awstats-cli", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Command line interface for AWStats", | ||
@@ -24,4 +24,3 @@ "main": "./bin/AWStats", | ||
"commander": "^8.1.0", | ||
"cross-spawn": "^7.0.3", | ||
"simple-git": "^2.45.1" | ||
"cross-spawn": "^7.0.3" | ||
}, | ||
@@ -28,0 +27,0 @@ "engines": { |
@@ -5,4 +5,11 @@ <h1 align="center"><a href="https://github.com/lete114/AWStats-cli" target="_blank">AWStats-cli</a></h1> | ||
<p align="center"> | ||
<a href="https://github.com/lete114/AWStats-cli/releases/"><img src="https://img.shields.io/github/package-json/v/lete114/AWStats-cli/master?color=%23e58a8a&label=master" alt="master"></a> | ||
<a href="https://github.com/lete114/AWStats-cli/blob/master/LICENSE"><img src="https://img.shields.io/github/license/lete114/AWStats-cli?color=FF5531" alt="MIT License"></a> | ||
<a href="https://github.com/lete114/AWStats-cli/releases/"> | ||
<img src="https://img.shields.io/github/package-json/v/lete114/AWStats-cli/master?color=%23e58a8a&label=master" alt="master"> | ||
</a> | ||
<a href="https://github.com/lete114/AWStats-cli/releases/"> | ||
<img src="https://img.shields.io/github/package-json/v/lete114/AWStats-cli/dev?color=%231ab1ad&label=dev" alt="dev"> | ||
</a> | ||
<a href="https://github.com/lete114/AWStats-cli/blob/master/LICENSE"> | ||
<img src="https://img.shields.io/github/license/lete114/AWStats-cli?color=FF5531" alt="MIT License"> | ||
</a> | ||
</p> | ||
@@ -9,0 +16,0 @@ |
@@ -15,5 +15,3 @@ { | ||
}, | ||
"dependencies": { | ||
"awstats": "^1.0.0" | ||
} | ||
"dependencies": {} | ||
} |
@@ -1,3 +0,3 @@ | ||
const { join, resolve } = require('path') | ||
const fs = require('fs') | ||
const { join } = require('path') | ||
const { writeFileSync } = require('fs') | ||
@@ -14,37 +14,16 @@ /** | ||
/** | ||
* 复制文件 | ||
* @param {*} sourcesPath 原文件路径 | ||
* @param {*} attachPath 指定输出路径 | ||
*/ | ||
function fileCopy(sourcesPath, attachPath) { | ||
fs.stat(sourcesPath, (err, stat) => { | ||
if (err) throw err | ||
if (stat.isFile()) { | ||
// 创建读取流 | ||
let readable = fs.createReadStream(sourcesPath) | ||
// 创建写入流 | ||
let writable = fs.createWriteStream(attachPath) | ||
readable.on('data', (chunk) => writable.write(chunk)) | ||
readable.on('end', () => writable.end()) | ||
} | ||
}) | ||
function DeepClone(obj = {}) { | ||
const str = JSON.stringify(obj) | ||
return JSON.parse(str) | ||
} | ||
/** | ||
* 删除目录下的所有文件及目录,包括当前目录 | ||
* @param path 需要删除的路径文件夹 | ||
*/ | ||
function removeAll(_path) { | ||
if (!fs.existsSync(_path)) return | ||
const files = fs.readdirSync(_path) | ||
for (let item of files) { | ||
const file_path = resolve(`${_path}/${item}`) | ||
const stats = fs.statSync(file_path) | ||
if (stats.isDirectory()) removeAll(file_path) | ||
else fs.unlinkSync(file_path) //删除文件 | ||
} | ||
fs.rmdirSync(_path) // 删除文件夹 | ||
function SetVersion() { | ||
const pkgPath = resolvePath('package.json') | ||
const pkg = require(pkgPath) | ||
const awstatsVersion = pkg.dependencies.awstats || '' | ||
const version = awstatsVersion.replace(/\^|\~|\*/, '') | ||
pkg.awstats.version = version | ||
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2), { encoding: 'utf-8' }) | ||
} | ||
module.exports = { removeAll, fileCopy, resolvePath } | ||
module.exports = { resolvePath, DeepClone, SetVersion } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
9466
3
37
80
4
- Removedsimple-git@^2.45.1
- Removed@kwsites/file-exists@1.1.1(transitive)
- Removed@kwsites/promise-deferred@1.1.1(transitive)
- Removeddebug@4.4.0(transitive)
- Removedms@2.1.3(transitive)
- Removedsimple-git@2.48.0(transitive)