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

legov

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

legov - npm Package Compare versions

Comparing version
1.2.0
to
1.2.1
asset/gitignore

Sorry, the diff of this file is not supported yet

+9
{
"name": "@legov",
"version": "0.0.0",
"private": true,
"dependencies": {
"legov-bundler": "^1.0.0",
"legov-server": "^1.0.0"
}
}
#!/usr/bin/env node
var program = require('commander');
var path = require('path');
var chalk = require('chalk');
var fs = require('hexo-fs');
var yml = require('js-yaml');
var app_info = require('../package.json');
var add = require('../lib/add');
//读取配置文件
var _readConfig = function () {
var local_yml = path.join(__dirname, 'legov.yml');
var config = {};
return Promise.resolve()
.then(function () {
//判断bin/legov.yml是否存在
return fs.exists(local_yml);
})
.then(function (exist) {
//如果存在就读取;否则给一个默认值(yml格式)
return exist? fs.readFile(local_yml): '\
local:\n\
yml:\n\
path:\n\
seed:\n\
prefix: legov-seed-\
leaf:\n\
prefix: legov-leaf-\
site:\n';
})
.then(function (data) {
//将yml转为json
config = yml.safeLoad(data);
//本机是否已经初始化?
//如果已经初始化,被初始化的目录是否还存在?
return config.local.path? fs.exists(config.local.path): false;
})
.then(function (exist) {
//目录不存在直接置为空值
if (!exist) {
config.local.path = ''
}
//直接指定配置文件所在地址
config.local.yml = local_yml
return config;
})
.catch(console.log)
}
//基本信息
program
.version(app_info.version)
.usage(chalk.magenta('[lv|lego]') + ' [options] <cmd>\n\n ' + app_info.description);
//$ lv init
program
.command('init')
.description('初始化前端工程。')
.action(function () {
console.log('\n 开始初始化:' + chalk.green(process.cwd())) + '\n';
_readConfig().then(function (config) {
if (config.local.path) {
return console.log('\n 操作无法执行!@legov已存在:' + chalk.green(config.local.path) + '\n');
} else {
require('../lib/init')(config);
}
}).catch(console.log);
})
.on('--help', function() {
console.log(' Examples: \n');
console.log(' $ mkdir <工程目录>\n');
console.log(' $ cd <工程目录>\n');
console.log(' $ %s %s\n', chalk.magenta('lv'), chalk.cyan('init'));
});
//$ lv get [key]
program
.command('get [key]')
.description('获取 LegoV 环境变量。')
.action(function(key){
_readConfig().then(function (config) {
require('../lib/get')(config, key);
}).catch(console.log);
})
.on('--help', function () {
console.log(' Examples: \n');
console.log(' $ %s %s all \n', chalk.magenta('lv'), chalk.cyan('get'));
console.log(' $ %s %s local/path \n', chalk.magenta('lv'), chalk.cyan('get'));
});
//$ lv set <key> <val>
program
.command('set <key> <val>')
.description('配置 LegoV 环境变量。')
.action(function(key, val){
_readConfig().then(function (config) {
require('../lib/set')(config, key, val);
}).catch(console.log);
})
.on('--help', function() {
console.log(' Examples: \n');
console.log(' $ %s %s seed/prefix "@tencent/wxpay-seed-" #内网前缀,引号是必须的\n', chalk.magenta('lv'), chalk.cyan('set'));
console.log(' $ %s %s seed/prefix "legov-seed-" #默认值\n', chalk.magenta('lv'), chalk.cyan('set'));
});
//$ lv generator <seed>
program
.command('generate <seed>')
.alias('g')
.description('播种站点(请确定种子已经就位)。')
.action(function (seed) {
_readConfig().then(function (config) {
if ('' == config.local.path){
console.log('\n 尚未初始化工程,请执行以下命令查看帮助:\n');
console.log(' $ %s %s -h\n', chalk.magenta('lv'), chalk.cyan('init'));
} else {
console.log('\n [%s]开始播种站点~~\n', chalk.green(seed));
require('../lib/generate')(config, seed);
}
}).catch(console.log);
})
.on('--help', function() {
console.log(' Examples: \n');
console.log(' $ cd "<工程目录>/@legov"\n');
console.log(' $ tnpm i @tencent/wxpay-seed-codeigniter\n');
console.log(' $ cd .. #返回<工程目录>\n');
console.log(' $ mkdir <站点目录> #建立<站点目录>(或者从 Svn or Git 拉取)\n');
console.log(' $ cd <站点目录>\n');
console.log(' $ %s %s seed/prefix "@tencent/wxpay-seed-" #引号是必须的\n', chalk.magenta('lv'), chalk.cyan('set'));
console.log(' $ %s %s codeigniter\n', chalk.magenta('lv'), chalk.cyan('g'));
console.log(' $ %s %s #不加参数,进行补种\n', chalk.magenta('lv'), chalk.cyan('g'));
});
//$ lv start
program
.command('start')
.alias('s')
.description('启动站点。')
.action(function () {
_readConfig().then(function (config) {
if ('' == config.local.path){
console.log('\n 尚未初始化工程,请执行以下命令查看帮助:\n');
console.log(' $ %s %s -h\n', chalk.magenta('lv'), chalk.cyan('init'));
} else {
console.log('\n 启动站点~~');
require('../lib/start')(config);
}
}).catch(console.log);
})
.on('--help', function() {
console.log(' Examples: \n');
console.log(' $ cd wxpay.oa.com-boss\n');
console.log(' $ %s %s\n', chalk.magenta('lv'), chalk.cyan('s'));
});
//$ lv proxy
program
.command('proxy')
.alias('x')
.description('启动代理服务器。')
.action(function(){
_readConfig().then(function (config) {
if ('' == config.local.path){
console.log('\n 尚未初始化工程,请执行以下命令查看帮助:\n');
console.log(' $ %s %s -h\n', chalk.magenta('lv'), chalk.cyan('init'));
} else {
console.log('\n 启动反向代理服务器~~');
require('../lib/proxy')(config);
}
}).catch(console.log);
})
.on('--help', function() {
console.log(' Examples: \n');
console.log(' $ cd wxpay.oa.com-boss\n');
console.log(' $ %s %s\n', chalk.magenta('lv'), chalk.cyan('p'));
});
//$ lv add <leaf> <name>
program
.command('add <leaf> <project>')
.description('增加项目(请确定叶子已经就位)。')
.action(function(leaf, project){
_readConfig().then(function (config) {
if ('' == config.local.path){
console.log('\n 尚未初始化工程,请执行以下命令查看帮助:\n');
console.log(' $ %s %s -h\n', chalk.magenta('lv'), chalk.cyan('init'));
} else {
console.log('\n [%s %s]开始增加项目~~\n', chalk.green(leaf), chalk.yellow(project));
require('../lib/add')(config, leaf, project);
}
}).catch(console.log);
})
.on('--help', function() {
console.log(' Examples: \n');
console.log(' $ cd "<工程目录>/@legov"\n');
console.log(' $ tnpm i @tencent/wxpay-leaf-flame\n');
console.log(' $ cd ../<站点目录>\n');
console.log(' $ %s %s flame -n project\n', chalk.magenta('lv'), chalk.cyan('add'));
});
//$ lv bundle
program
.command('bundle')
.alias('b')
.description('打包服务。')
.action(function(){
_readConfig().then(function (config) {
if ('' == config.local.path){
console.log('\n 尚未初始化工程,请执行以下命令查看帮助:\n');
console.log(' $ %s %s -h\n', chalk.magenta('lv'), chalk.cyan('init'));
} else {
console.log('\n 开始打包~~');
require('../lib/bundle')(config);
}
}).catch(console.log);
})
.on('--help', function() {
console.log(' Examples: \n');
console.log(' $ cd wxpay.oa.com-boss/views/home\n');
console.log(' $ %s %s\n', chalk.magenta('lv'), chalk.cyan('b'));
});
//$ lv publish
program
.command('publish')
.alias('p')
.description('发布项目。')
.action(function(){
_readConfig().then(function (config) {
if ('' == config.local.path){
console.log('\n 尚未初始化工程,请执行以下命令查看帮助:\n');
console.log(' $ %s %s -h\n', chalk.magenta('lv'), chalk.cyan('init'));
} else {
console.log('\n 开始打包~~');
require('../lib/publish')(config);
}
}).catch(console.log);
})
.on('--help', function() {
console.log(' Examples: \n');
console.log(' $ cd wxpay.oa.com-boss/material/\n');
console.log(' $ %s %s\n', chalk.magenta('lv'), chalk.cyan('p'));
});
program.parse(process.argv);
local:
yml: "F:\\Node\\node_modules\\legov\\bin\\legov.yml"
path: "E:\\Web\\@legov"
seed:
prefix: '@tencent/wxpay-seed-'
site:
wxpay.oa.com:
boss:
port: 64901
root: htdocs
view: views
leaf:
prefix: '@tencent/wxpay-leaf-'
'use strict';
var path = require('path');
var chalk = require('chalk');
var fs = require('hexo-fs');
var yml = require('js-yaml');
module.exports = function(config, leaf, project) {
var leaf_path = path.join(config.local.path, 'node_modules', config.leaf.prefix + leaf);
return fs.exists(leaf_path)
.then(function (exist) {
if (exist) {
var cwd = process.cwd();
//拷贝种子站点中的资源到当前目录
return fs.listDir(leaf_path).map(function (item) {
var src = path.join(leaf_path, item);
var dest = path.join(cwd, project, item.replace('home', project));
return fs.exists(dest).then(function (exist) {
if(!exist){
return fs.copyFile(src, dest).then(function() {
console.log(' ' + chalk.magenta(dest));
});
} else {
return console.log('\n ' + chalk.red('文件已经存在:' + dest));
}
});
});
} else {
console.log('\n [%s]没有找到种子。请确定种子已经就位。', chalk.red(leaf));
console.log('\n [%s]查找目录为:%s', chalk.red(leaf), chalk.red(leaf_path));
console.log('\n 如需帮助,请执行:\n');
console.log(' $ %s %s -h', chalk.magenta('lv'), chalk.cyan('g'));
}
})
.then(function () {
console.log('\n 项目初始化完成!');
});
};
'use strict';
var path = require('path');
var chalk = require('chalk');
var fs = require('hexo-fs');
module.exports = function (config) {
var bundler = path.join(config.local.path, 'node_modules', 'legov-bundler');
return fs.exists(bundler).then(function (exist) {
if (exist) {
require(bundler)(config);
} else {
console.log('[%s]当前目录下没有找到legov-bundler。', chalk.red(server));
}
})
}
'use strict';
var path = require('path');
var chalk = require('chalk');
var fs = require('hexo-fs');
var yml = require('js-yaml');
module.exports = function(config, seed) {
var seed_path = path.join(config.local.path, 'node_modules', config.seed.prefix + seed);
return fs.exists(seed_path)
.then(function (exist) {
if (exist) {
var asset = path.join(seed_path, 'asset');
//拷贝种子站点中的资源到当前目录
return fs.listDir(asset).map(function (item) {
var src = path.join(asset, item);
var dest = path.join(process.cwd(), item);
return fs.exists(dest).then(function (exist) {
if(!exist){
return fs.copyFile(src, dest).then(function() {
console.log(' ' + chalk.magenta(dest));
});
} else {
return console.log('\n ' + chalk.red('文件已经存在:' + dest));
}
});
});
} else {
console.log('\n [%s]没有找到种子。请确定种子已经就位。', chalk.red(seed));
console.log('\n [%s]查找目录为:%s', chalk.red(seed), chalk.red(seed_path));
console.log('\n 如需帮助,请执行:\n');
console.log(' $ %s %s -h', chalk.magenta('lv'), chalk.cyan('g'));
}
})
.then(function () {
console.log('\n 站点初始化完成!');
});
};
'use strict';
var chalk = require('chalk');
module.exports = function(config, key) {
if (!key || 'all' == key){
console.log('\n 所有环境变量如下:\n');
console.dir(config);
return console.log('\n');
} else {
var look = config;
key = key.split('/');
for (var i = 0, len = key.length; i < len; i++){
look = look[key[i]];
if(typeof(look) == "undefined"){
return console.log('\n [%s]未定义此变量。\n', chalk.red(key.join('/')));
}
}
console.log('\n [%s]:\n', chalk.green(key.join('/')));
console.dir(look);
return console.log('\n');
}
}
'use strict';
var path = require('path');
var chalk = require('chalk');
var fs = require('hexo-fs');
var yml = require('js-yaml');
module.exports = function (config) {
var local = path.join(process.cwd(), '@legov');
var local_yml = config.local.yml;
//写入@legov安装路径
config.local.path = local;
fs.writeFile(local_yml, yml.safeDump(config));
console.log('\n 拷贝文件到:' + chalk.green(local) + '\n');
var asset = path.join(local_yml, '../../asset');
return fs.listDir(asset).map(function(item) {
var src = path.join(asset, item);
//npm会自动把gitignore转为npmignore,这里要做兼容处理
var dest = item === 'gitignore' ? '.' + item : item;
dest = path.join(local, dest);
return fs.copyFile(src, dest)
.then(function() {
console.log(' ' + chalk.magenta(dest));
});
})
.then(function (data) {
console.log('\n 初始化完成!请执行以下操作:\n');
console.log(' $ cd @legov');
console.log(' $ npm install');
})
.catch(console.dir)
};
'use strict';
var path = require('path');
var chalk = require('chalk');
var fs = require('hexo-fs');
module.exports = function (config) {
var server = path.join(config.local.path, 'node_modules', 'legov-server');
return fs.exists(server).then(function (exist) {
if (exist) {
require(server).proxy(config);
} else {
console.log('[%s]当前目录下没有反向代理服务器。', chalk.red(server));
}
})
}
'use strict';
var path = require('path');
var chalk = require('chalk');
var fs = require('hexo-fs');
var yml = require('js-yaml');
module.exports = function(config, key, val) {
key = key.split('/');
var len = key.length;
if (len < 2) {
return console.log('\n [%s]仅能配置最终子项。\n', key);
}
_setConfig(config, key, val);
return fs.writeFile(config.local.yml, yml.safeDump(config))
}
var _setConfig = function (config, key ,val) {
if(typeof(config[key[0]]) == "undefined"){
return console.log('\n [%s]未定义此变量。\n', chalk.red(key.join('/')));
}
if (key.length > 1){
_setConfig(config[key[0]], key.slice(1), val);
} else {
if (typeof(config[key[0]]) != "string") {
return console.log('\n [%s]仅能配置最终子项。\n', key);
}
config[key[0]] = val;
}
}
'use strict';
var path = require('path');
var chalk = require('chalk');
var fs = require('hexo-fs');
module.exports = function (config) {
var server = path.join(config.local.path, 'node_modules', 'legov-server');
return fs.exists(server).then(function (exist) {
if (exist) {
require(server).start(config);
} else {
console.log('[%s]当前目录下没有找到站点服务器。', chalk.red(server));
}
})
}
+10
-3
{
"name": "legov",
"version": "1.2.0",
"version": "1.2.1",
"description": "基于项目的多站点前端集成解决方案。",
"main": "package.json",
"bin": {
"lv": "bin/legov.js",
"lego": "bin/legov.js",
"legov": "bin/legov.js"
},
"scripts": {

@@ -16,5 +21,7 @@ "test": "echo \"Error: no test specified\" && exit 1"

"dependencies": {
"legov-bundler": "^1.0.0",
"legov-server": "^1.0.0"
"chalk": "^1.1.1",
"commander": "^2.9.0",
"hexo-fs": "^0.1.5",
"js-yaml": "^3.4.6"
}
}

@@ -5,11 +5,22 @@ # LegoV

# Version
### 1.2.0
* 新增legov-bundler
* 调整依赖关系
## 1.2.1:
* 调整bundle监听方式
* proxy现在可以自动监听文件改变了
* 调整了asset内的文件
### 1.1.0
* cmd:generater|start|proxy|
## 1.2.0
### Commands:
* bundle|b 文件打包
* add 增加叶子
### 1.0.0
* cmd:init
* 初始架构
## 1.1.0
### Commands:
* init 初始化前端工程。
* get [key] 获取 LegoV 环境变量。
* set <key> <val> 配置 LegoV 环境变量。
* generator|g <seed> 播种站点(请确定种子已经就位)。
* start|s 启动站点。
* proxy|p 启动代理服务器。
## 1.0.0
项目初始化。