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

tpm

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tpm - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

tasks/tui2build.js

2

main.js

@@ -14,2 +14,4 @@

cleanup : true,
tui2build : true,
tui2min : true,
};

@@ -16,0 +18,0 @@

2

package.json
{
"name": "tpm",
"version": "1.0.5",
"version": "1.0.6",
"description": "Static Package Manager",

@@ -5,0 +5,0 @@ "author": "Longhao Luo <lhluo@tudou.com>",

var Path = require('path');
var Fs = require('fs');
var Iconv = require('iconv-lite');
var _ = require('underscore');
var Ozma = require('ozma-tudou').Ozma;
var Less = require('less');
var ChildProcess = require('child_process');

@@ -49,2 +51,103 @@ var Util = require(__dirname + '/../util');

// 取得文件SVN版本号
function getSvnVersion(pathList, callback) {
var pathCount = pathList.length;
var result = {};
for (var i = 0, len = pathList.length; i < len; i++) {
var path = pathList[i];
if (result[path]) {
continue;
}
if (!Fs.existsSync(path)) {
Util.error('File not found: ' + path);
continue;
}
var cmd = (process.platform === 'win32' ? 'set' : 'export') + ' LANG=en_US && svn info "' + path.replace(/\\/g, '\\\\') + '"';
var cp = ChildProcess.exec(cmd);
cp.stdout.on('data', function(stdout) {
var data = Iconv.fromEncoding(stdout, 'gbk');
var match;
if ((match = /^Path:\s*(.+)$/im.exec(data))) {
var key = match[1];
}
if ((match = /^Last Changed Rev:\s*(\d+)$/im.exec(data))) {
var value = match[1];
}
if (key && value) {
key = key.substr(0, 1).toLowerCase() + key.substr(1);
result[key] = value;
}
});
cp.stderr.on('data', function(stderr){
Util.error('[SVN] ' + stderr);
});
cp.on('exit', function() {
pathCount--;
if (pathCount === 0) {
callback(result);
}
});
}
}
// 图片版本化
function renameAssets(cssPath, content, callback) {
var dirPath = Path.dirname(cssPath);
function url2path(url) {
var path = null;
if (url.charAt(0) == '.') {
path = Path.resolve(dirPath + '/' + url);
} else if (url.charAt(0) == '/') {
path = Path.resolve(config.root + '/../' + url);
}
return path;
}
function addVersion(path, version) {
return path.replace(/^(.+)(\.\w+)$/, '$1_' + version + '$2');
}
var match;
var regExp = /url\("((?:\\"|[^"])+)"\)/g;
var newContent = content.replace(/\/\*[\S\s]*?\*\//g, '');
var pathList = [];
while((match = regExp.exec(newContent))) {
var url = match[1];
var path = url2path(url);
if (path) {
pathList.push(path);
}
}
getSvnVersion(pathList, function(data) {
content = content.replace(/\/\*[\S\s]*?\*\/|(url\(")((?:\\"|[^"])+)("\))/g, function(full, prefix, url, suffix) {
if (prefix) {
var path = url2path(url);
if (data[path]) {
var version = data[path];
var buildPath = addVersion(getBuildPath(path), version);
var distPath = addVersion(getDistPath(path), version);
Util.copyFile(path, buildPath);
Util.copyFile(path, distPath);
return prefix + addVersion(url, version) + suffix;
}
}
return full;
});
callback(content);
});
}
// 构建一个JS文件

@@ -110,6 +213,9 @@ function buildJs(path) {

}
Util.writeFileSync(buildPath, Util.banner + tree.toCSS());
Util.minCss(buildPath, distPath);
Util.setSvnKeywords(buildPath);
Util.setSvnKeywords(distPath);
content = tree.toCSS();
renameAssets(path, content, function(content) {
Util.writeFileSync(buildPath, Util.banner + content);
Util.minCss(buildPath, distPath);
Util.setSvnKeywords(buildPath);
Util.setSvnKeywords(distPath);
});
});

@@ -116,0 +222,0 @@ }

@@ -46,6 +46,6 @@

if (!Fs.existsSync(srcPath)) {
if (!Fs.existsSync(srcPath) && !Fs.existsSync(srcPath.replace(/_\d+(\.\w+)$/, '$1'))) {
Rimraf.sync(path);
Util.info('File "' + path + '" deleted.' + Util.linefeed);
return;
continue;
}

@@ -52,0 +52,0 @@

@@ -31,3 +31,3 @@

var cmd = 'svn info "' + path.replace(/\\/g, '\\\\') + '"';
var cmd = (process.platform === 'win32' ? 'set' : 'export') + ' LANG=en_US && svn info "' + path.replace(/\\/g, '\\\\') + '"';

@@ -43,3 +43,3 @@ var cp = ChildProcess.exec(cmd);

}
if ((match = /(?:Revision|版本):\s*(\d+)/i.exec(data))) {
if ((match = /^Last Changed Rev:\s*(\d+)$/im.exec(data))) {
line += ' ' + match[1];

@@ -46,0 +46,0 @@ }

var Path = require('path');
var Fs = require('fs');
var _ = require('underscore');
var Ozma = require('ozma-tudou').Ozma;
var Less = require('less');

@@ -8,0 +5,0 @@ var Util = require(__dirname + '/../util');

@@ -117,6 +117,8 @@

function minJs(fromPath, toPath) {
function minJs(fromPath, toPath, charset) {
charset = charset || 'utf-8';
console.log('Compress file: ' + fromPath);
var content = readFileSync(fromPath, 'utf-8');
var content = readFileSync(fromPath, charset);

@@ -133,6 +135,8 @@ var ast = uglifyParser.parse(content); // parse code and get the initial AST

function minCss(fromPath, toPath) {
function minCss(fromPath, toPath, charset) {
charset = charset || 'utf-8';
console.log('Compress file: ' + fromPath);
var content = readFileSync(fromPath, 'utf-8');
var content = readFileSync(fromPath, charset);

@@ -146,3 +150,5 @@ var minContent = CleanCss.process(content);

function concatFile(fromPaths, toPath) {
function concatFile(fromPaths, toPath, charset) {
charset = charset || 'utf-8';
console.log('Concat files:');

@@ -155,3 +161,3 @@

contentList.push(readFileSync(path, 'utf-8'));
contentList.push(readFileSync(path, charset));
});

@@ -158,0 +164,0 @@

Sorry, the diff of this file is not supported yet

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