🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

deploy-finlean

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deploy-finlean - npm Package Compare versions

Comparing version
1.0.6
to
1.0.7
+58
-143
bin/deploy-init.js

@@ -7,59 +7,55 @@ #!/usr/bin/env node

* 修复说明:
* 1. 支持双模块系统:同时兼容CommonJS和ES模块
* 2. 自动检测环境:根据运行环境自动选择合适的模块系统
* 3. 解决初始 化 失败问题:确保在不同项目环境中都能正确执行
* 1. 使用CommonJS模块语法:确保在所有环境中都能正常执行
* 2. 移除ES模块语法:避免在CommonJS环境中出现语法错误
* 3. 保持功能不变:确保初始化功能正常工作
*
* 原因:不同项目可能使用不同的模块系统,
* 有些项目使用CommonJS (require/module.exports),
* 有些项目使用ES模块 (import/export)。
* 原因:ES模块的import语法在CommonJS环境中会导致"Unexpected identifier"错误
*/
// 检查是否支持ES模块(通过检测require是否存在)
if (typeof require !== 'undefined') {
// 使用CommonJS模块
const fs = require('fs');
const path = require('path');
// 解析命令行参数
const argv = process.argv.slice(2);
let webDir = '/home/webapps/'; // 默认值
for (let i = 0; i < argv.length; i++) {
if (argv[i] === '--webDir' || argv[i] === '-w') {
if (argv[i + 1]) {
const dirName = argv[i + 1];
// 如果用户只传入了文件夹名,自动拼接路径
if (!dirName.startsWith('/')) {
webDir = `/home/webapps/${dirName}`;
} else {
webDir = dirName;
}
i++;
// 使用CommonJS模块语法
const fs = require('fs');
const path = require('path');
// 解析命令行参数
const argv = process.argv.slice(2);
let webDir = '/home/webapps/'; // 默认值
for (let i = 0; i < argv.length; i++) {
if (argv[i] === '--webDir' || argv[i] === '-w') {
if (argv[i + 1]) {
const dirName = argv[i + 1];
// 如果用户只传入了文件夹名,自动拼接路径
if (!dirName.startsWith('/')) {
webDir = `/home/webapps/${dirName}`;
} else {
webDir = dirName;
}
i++;
}
}
// 检查当前目录是否存在 package.json 文件
const packageJsonPath = path.join(process.cwd(), 'package.json');
if (!fs.existsSync(packageJsonPath)) {
console.error('Error: package.json not found in current directory');
process.exit(1);
}
// 读取 package.json 文件
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
// 添加部署脚本
if (!packageJson.scripts) {
packageJson.scripts = {};
}
packageJson.scripts.deploy = 'node ./node_modules/deploy-finlean/index.js';
// 写入更新后的 package.json 文件
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
console.log('Added deploy script to package.json');
// 生成 deploy.config.js 文件
const deployConfigContent = `/*
}
// 检查当前目录是否存在 package.json 文件
const packageJsonPath = path.join(process.cwd(), 'package.json');
if (!fs.existsSync(packageJsonPath)) {
console.error('Error: package.json not found in current directory');
process.exit(1);
}
// 读取 package.json 文件
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
// 添加部署脚本
if (!packageJson.scripts) {
packageJson.scripts = {};
}
packageJson.scripts.deploy = 'node ./node_modules/deploy-finlean/index.js';
// 写入更新后的 package.json 文件
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
console.log('Added deploy script to package.json');
// 生成 deploy.config.js 文件
const deployConfigContent = `/*
* Deployment configuration file

@@ -87,93 +83,12 @@ * Generated by deploy-finlean

}`;
const deployConfigPath = path.join(process.cwd(), 'deploy.config.js');
fs.writeFileSync(deployConfigPath, deployConfigContent);
console.log('Generated deploy.config.js file');
console.log('\nPlease update deploy.config.js with your server information');
console.log('You can also specify the web directory during initialization:');
console.log(' npx deploy-init --webDir /path/to/web/directory (完整路径)');
console.log(' or');
console.log(' npx deploy-init -w directory-name (自动拼接 /home/webapps/directory-name)');
console.log('\nThen run "npm run deploy" to deploy your project');
} else {
// 使用ES模块
import fs from 'fs';
import path from 'path';
// 解析命令行参数
const argv = process.argv.slice(2);
let webDir = '/home/webapps/'; // 默认值
for (let i = 0; i < argv.length; i++) {
if (argv[i] === '--webDir' || argv[i] === '-w') {
if (argv[i + 1]) {
const dirName = argv[i + 1];
// 如果用户只传入了文件夹名,自动拼接路径
if (!dirName.startsWith('/')) {
webDir = `/home/webapps/${dirName}`;
} else {
webDir = dirName;
}
i++;
}
}
}
// 检查当前目录是否存在 package.json 文件
const packageJsonPath = path.join(process.cwd(), 'package.json');
if (!fs.existsSync(packageJsonPath)) {
console.error('Error: package.json not found in current directory');
process.exit(1);
}
// 读取 package.json 文件
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
// 添加部署脚本
if (!packageJson.scripts) {
packageJson.scripts = {};
}
packageJson.scripts.deploy = 'node ./node_modules/deploy-finlean/index.js';
// 写入更新后的 package.json 文件
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
console.log('Added deploy script to package.json');
// 生成 deploy.config.js 文件
const deployConfigContent = `/*
* Deployment configuration file
* Generated by deploy-finlean
*/
export default {
// 服务器配置
server: {
host: '39.106.58.84',
port: 22,
username: 'root',
password: '' // 或者使用私钥
},
// 本地配置
local: {
buildDir: 'dist', // 构建输出目录
zipPath: 'dist.zip', // 压缩文件路径
buildCommand: 'npm run build:prod' // 打包命令
},
// 服务器配置
remote: {
webDir: '${webDir}' // 服务器 web 目录
}
}`;
const deployConfigPath = path.join(process.cwd(), 'deploy.config.js');
fs.writeFileSync(deployConfigPath, deployConfigContent);
console.log('Generated deploy.config.js file');
console.log('\nPlease update deploy.config.js with your server information');
console.log('You can also specify the web directory during initialization:');
console.log(' npx deploy-init --webDir /path/to/web/directory (完整路径)');
console.log(' or');
console.log(' npx deploy-init -w directory-name (自动拼接 /home/webapps/directory-name)');
console.log('\nThen run "npm run deploy" to deploy your project');
}
const deployConfigPath = path.join(process.cwd(), 'deploy.config.js');
fs.writeFileSync(deployConfigPath, deployConfigContent);
console.log('Generated deploy.config.js file');
console.log('\nPlease update deploy.config.js with your server information');
console.log('You can also specify the web directory during initialization:');
console.log(' npx deploy-init --webDir /path/to/web/directory (完整路径)');
console.log(' or');
console.log(' npx deploy-init -w directory-name (自动拼接 /home/webapps/directory-name)');
console.log('\nThen run "npm run deploy" to deploy your project');
{
"name": "deploy-finlean",
"version": "1.0.6",
"version": "1.0.7",
"description": "Deployment package for projects",

@@ -5,0 +5,0 @@ "main": "index.js",