Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alpaca-sm

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alpaca-sm - npm Package Compare versions

Comparing version 1.1.11 to 2.0.0

lib/file.js

25

debug.js

@@ -1,23 +0,6 @@

/*var alp = require('./index.js');
var _ = alp._;
alp.config.merge({
base: process.cwd(),
word: 'require',
optimizer:true,
readcss:false
});
console.time('');
require('/Users/gml/github/testJS/alp-conf.js');
var result = alp.parse({
src: '/Users/gml/github/testJS/d.js'
});
var alp = require('./index.js');
for (var i in result) {
console.dir(alp.processor({
src: '/Users/gml/github/testJS/index.html'
}));
_.write(_.path.resolve(alp.config.get('base'), 'output3', i), result[i].content, 'utf-8');
}
console.timeEnd('');*/
var test = require('./test.js');
console.dir(test);
var alp = module.exports = {};
if (!global.alp) {
Object.defineProperty(global, 'alp', {
enumerable: true,
writable: false,
value: alp
});
Object.defineProperty(global, 'alp', {
enumerable: true,
writable: false,
value: alp
});
}
alp._ = require('./lib/unit.js');
alp.log = require('./lib/log.js');
alp.jsParse = require('./lib/jsParse.js');
alp._ = require('./lib/util.js');
alp.txtParse = require('./lib/txtParse.js');
alp.storage = alp.storage || {};
alp.config = require('./lib/config.js');
alp.config = alp.conf || require('./lib/config.js');
alp.parse = require('./lib/parse.js');
alp.File = require('./lib/file.js');
alp.processor = require('./lib/processor.js');
var CONFIG = {
ns: "alp",
exclude: [],//排除一些已存在的使用require关键字的文件,比如用webpack或browerify打包的文件。
txtType: [],//扩展已有的文本类型['txt','js']
cssMap:['scss','sass','less','styl'],
excludeType:[],
isJswrapperInHtml:true,
main: { //命令行时,指定的入口文件
include: [],
exclude: []
},
optimizer: true, //是否压缩文件
base: process.cwd(), //指定项目的根路径
useBaseInJsFile:false, //js文件中的出现require()的路径是否是基于base的(主要是对于FIS)
word: 'require',
readcss: true, //出现在js中的css是否读取内容。
readcssInHtml:false,//出现在html中的script标签中的css是否可读
settings: {
optimizer: {
css: {
processImport: false,
keepSpecialComments: '*' //只对‘/*!我是注市有效*/’
},
js: {
fromString: true
}
}
}
}
// 生成闭包的命名空间
ns: 'ns',
// 项目的根目录
root: process.cwd(),
// 排除一些已存在的使用require关键字的文件,比如用webpack或browerify打包的文件。
exclude: [],
// 排除一些文本类型
excludeTxtType: [],
// 扩展已有的文本类型['txt','js']
txtType: [],
// 分析的文件是否是被压缩过的文件
isOptimizer: false,
// js文件中的出现require()的路径是否是基于root的(主要用于应对使用构建工具生成的文件,路径会被编译为基于项目root的相对路径,如fis)
fileBasedRoot: false,
// 分析依赖时所识别的关键字
word: 'require',
// 是否对html中的js代码添加闭包代码, 如果代码中的require参与运算的话,就忽略该值,为代码加上闭包。
wrapJsInHtml: false,
readable: {
// 使用requrie('../xx.css')时,是否是读取css的内容
css: false,
// 在HTML文件的script标签使用require('../xx.css')是,是否读取css的内容
cssInHTML: false
},
tmpl: {
js: '<script type="text/javascript" src="{0}"></script>',
css: '<link rel="stylesheet" type="text/css" href="{0}">'
}
};
function merge(source, target) {
if (typeof source === 'object' && typeof target === 'object') {
for (var key in target) {
if (target.hasOwnProperty(key)) {
source[key] = merge(source[key], target[key]);
}
}
} else {
source = target;
}
return source;
if (typeof source === 'object' && typeof target === 'object') {
for (var key in target) {
if (target.hasOwnProperty(key)) {
source[key] = merge(source[key], target[key]);
}
}
} else {
source = target;
}
return source;
}
function Config(config) {
this.config = merge(config, CONFIG);
if(Config.instance instanceof Config) {
return Config.instance;
}
this.config = merge(config, CONFIG);
Config.instance = this;
}
Config.prototype = {
set: function(key, value) {
if (typeof value !== 'undefined') {
set: function(key, value) {
if (typeof value !== 'undefined') {
key = String(key || '').trim();
if (key) {
var paths = key.split('.'),
last = paths.pop(),
data = this.config || {};
paths.forEach(function(key) {
var type = typeof data[key];
if (type === 'object') {
data = data[key];
} else if (type === 'undefined') {
data = data[key] = {};
} else {
alp.log.error('forbidden to set property[' + key + '] of [' + type + '] data');
}
});
data[last] = value;
}
}
},
get: function(keyPath) {
var keys = keyPath.split('.'),
key,
config = this.config;
for (var i = 0, len = keys.length; i < len; i++) {
key = keys[i];
if (i == len - 1) {
return config[key];
} else if (key in config) {
config = config[key];
} else {
return;
}
}
},
merge: function(config) {
this.config = merge(this.config, config);
}
key = String(key || '').trim();
if (key) {
var paths = key.split('.'),
last = paths.pop(),
data = this.config || {};
paths.forEach(function (key) {
var type = typeof data[key];
if (type === 'object') {
data = data[key];
} else if (type === 'undefined') {
data = data[key] = {};
} else {
alp.log.error('forbidden to set property[' + key + '] of [' + type + '] data');
}
});
data[last] = value;
}
}
},
get: function(keyPath) {
var keys = keyPath.split('.'),
key,
config = this.config;
for (var i = 0, len = keys.length; i < len; i++) {
key = keys[i];
if (i == len - 1) {
return config[key];
} else if (key in config) {
config = config[key];
} else {
return;
}
}
},
merge: function(config) {
this.config = merge(this.config, config);
}
}

@@ -91,0 +108,0 @@

@@ -6,6 +6,6 @@ var colors = require('colors');

function log(type, msg) {
if (type) {
type = '\n[' + type.toLocaleUpperCase() + '] ';
}
process.stdout.write(type + msg + '\n');
if (type) {
type = '\n[' + type.toLocaleUpperCase() + '] ';
}
process.stdout.write(type + msg + ' this is in "alpaca" module'.red + '\n');
}

@@ -15,20 +15,20 @@

ep.error = function(err) {
if (!(err instanceof Error)) {
err = new Error(err.message || err);
}
if (!(err instanceof Error)) {
err = new Error(err.message || err);
}
log('error', err.message.red);
process.exit(1);
log('error', err.message.red);
process.exit(1);
}
ep.warning = function(msg) {
log('waring', msg.yellow);
log('waring', msg.yellow);
}
ep.info = function(msg) {
log('', msg.green);
log('', msg.green);
}
ep.debug = function(msg){
log('debug',msg.blue);
log('debug',msg.blue);
}
{
"name": "alpaca-sm",
"version": "1.1.11",
"version": "2.0.0",
"description": "分析Html文件依赖的js文件和css文件",
"main": "index.js",
"scripts": {
"test": "supervisor --debug-brk ./debug.js",
"start": "supervisor bin/alp"
"test": "supervisor --debug-brk ./debug.js"
},
"bin": {
"alp": "bin/alp"
},
"repository": {

@@ -21,6 +17,3 @@ "type": "git",

],
"author": {
"name": "guomilo",
"email": "guomilo@gmail.com"
},
"author": "guomilo <guomilo@gmail.com>",
"engines": {

@@ -34,3 +27,2 @@ "node": ">0.10.0"

"dependencies": {
"clean-css": "^3.4.6",
"colors": "^1.1.2",

@@ -41,6 +33,27 @@ "commander": "*",

"estraverse": "4.1.0",
"iconv-lite": "^0.4.13",
"tap": "^2.1.1",
"uglify-js": "^2.5.0"
}
"iconv-lite": "^0.4.13"
},
"_shasum": "a14cfd4a4e3e5c58ced1507aa033b99d53ca678f",
"_from": "alpaca-sm@^1.1.0",
"_npmVersion": "3.3.9",
"_nodeVersion": "0.12.7",
"_npmUser": {
"name": "guomilo",
"email": "guomilo@gmail.com"
},
"dist": {
"shasum": "a14cfd4a4e3e5c58ced1507aa033b99d53ca678f",
"size": 12627,
"noattachment": false,
"tarball": "http://registry.npm.taobao.org/alpaca-sm/download/alpaca-sm-1.1.9.tgz"
},
"maintainers": [
"guomilo <guomilo@gmail.com>"
],
"directories": {},
"publish_time": 1449141934910,
"_cnpm_publish_time": 1449141934910,
"_resolved": "http://registry.npm.taobao.org/alpaca-sm/download/alpaca-sm-1.1.9.tgz",
"devDependencies": {},
"license": "MIT"
}
# alpaca-sm
针对sm公司业务定制的用于模块化解析的工具。
因公司前端业务框架的原因,前端开发不能使用市面上的模块化类库,如seajs,requireJs,modJs等。
>针对sm公司业务定制的用于模块化解析的工具。
>因公司前端业务框架的原因,前端开发不能使用市面上的模块化类库,如seajs,requireJs,modJs等。
此工具是在编译阶段,将采用commonJS规范的模块化代码,转译成闭包形式的代码。

@@ -11,59 +9,82 @@

### 安装
### example
a-object.js
```js
module.exports = {
sayName: function(name) {
console.log(name);;;
var tt = '6';
}
}
```bash
npm install alpaca-sm -g
```
b-function.js
```js
var aobj = require('./a-object.js');
module.exports = function(word) {
aobj.sayName(word + 'test');
}
### API说明
```
#### 命令行
####config
+ 解释:管理配置项
+ 用法:
```js
alp.config.get('ns');
alp.config.get('readable.css');
alp.config.set('ns');
```
```
alp release -d ./output
####processor
+ 解释:分析文件的依赖项
+ 参数:
src: 文件的绝对路径,重要的事说三遍,绝对路径!绝对路径!绝对路径!
contentProcessor: 文件内容处理器,返回处理过后的文件内容。
+ 用法:
```js
alp.processor({
src: file.realpath,
contentProcessor: function (file) {
var retObj;
```
retObj = ret.src['/' + file.subpath];
if (retObj) {
return retObj.rawContent || retObj.getContent();
} else {
return file.getContent();
}
}
});
#### output
```
a-object.js
### 配置说明
```
window.sm = window.sm || {};
(function (sm) {
sm.a_object_js = {
sayName: function (name) {
console.log(name);;
var tt = '6';
}
};
}(sm));
```
b-function.js
```js
window.sm = window.sm || {};
(function (sm, a_object_js) {
var aobj = a_object_js;
sm.b_function_js = function (word) {
aobj.sayName(word + 'test');
};
}(sm, sm.a_object_js));
```
### config说明
####ns
解释:生成闭包后,所使用的命名空间
类型: string
默认值:'ns'
####root
解释:项目的根目录
类型:string
默认值:当前目录
说明:注意配置项fileBasedRoot对他的影响
####fileBasedRoot
解释:js文件中使用require的路径是否是基于root的。
类型:boolean
默认值:false
说明:主要用于应对使用构建工具生成的文件,路径会被编译为基于项目root的相对路径,如fis
####exclude
解释:排除一些已存在的使用require关键字的文件,比如用webpack或browerify打包的文件。
类型:array | string | RegExp
默认值:[]
####isOptimizer
解释:分析的文件是否是被压缩过的文件
类型:boolean
默认值:false
说明:压缩过的文件和没压缩过的文件,代码结构不同,不能使用同一种处理方法。
####wrapJsInHtml
解释:是否对html中的js代码添加闭包代码
类型:boolean
默认值:false
说明:如果代码中的require参与运算的话,就忽略该值,为代码加上闭包。
####readable.css
解释:在js中出现requrie('../xx.css')时,是否读取css文件的内容
类型:boolean
默认值:false
####readable.cssInHtml
解释:在HTML文件的script标签使用require('../xx.css')是,是否读取css的内容
类型:boolean
默认值:false
####tmpl
解释:css和js的引入模板

@@ -74,18 +95,1 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc