shell.windows_Windows Shell中的cssmin.js

shell.windows

shell.windows

JavaScript can run virtually anywhere, including as a windows exe and the windows command line.

JavaScript几乎可以在任何地方运行,包括作为Windows exeWindows命令行

Say you have a JavaScript function foo()

假设您有一个JavaScript函数foo()

function foo(input) {
  var output = input;
  // .. unicorns
  return output;
}

In order to make this a windows shell script you add at the and a way to read standard input and then write to the standard output:

为了使它成为Windows Shell脚本,您在和添加了一种读取标准输入然后写入标准输出的方式:

(function () {
 
    var input  = WScript.StdIn.ReadAll(),
        output = foo(input);
 
    WScript.StdOut.Write(output);
 
}());

Then you run this script, say foo.js, like:

然后运行此脚本,说foo.js ,例如:

$ cscript foo.js < input.txt

And it prints the output to the console.

然后将输出打印到控制台。

If you want to read and print the code of foo.js itself you go:

如果您想阅读和打印foo.js本身的代码,请执行以下操作:

$ cscript foo.js < foo.js
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

function foo(input) {
  var output = input;
...

You can remove this "Microsoft (R) Windows..." stuff with //NoLogo parameter:

您可以使用//NoLogo参数删除此“ Microsoft(R)Windows ...”内容:

$ cscript //NoLogo foo.js < foo.js
function foo(input) {
  var output = input;
...

CSSMin.JS(CSSMin.JS)

Alrighty, going back to the title of the post.

好了,回到帖子的标题。

CSSMin.js is a port of YUICompressor's CSS minifier (source, hosted tool). Now adding a few lines at the end makes a windows shell script:

CSSMin.js是YUICompressorCSS缩小器( source托管工具)的端口。 现在,在最后添加几行,制作一个Windows Shell脚本:

(function () {
 
    var src = WScript.StdIn.ReadAll();
 
    if (!src) {
        // help!
        WScript.StdOut.WriteLine("cscript //NoLogo cssmin.js < in.css > out.css");
        return;
    }
 
    WScript.StdOut.Write(YAHOO.compressor.cssmin(src));
 
}());

Download it here.

在这里下载

Use it like:

像这样使用它:

$ cscript //NoLogo cssmin.js < in.css > out.css

Don't forget the //NoLogo or you'll end up with "Microsoft..." in your minified files

不要忘记// NoLogo,否则在缩小的文件中将出现“ Microsoft ...”

Random observation: "dude"[0] === "d" in most JS environments but is undefined in WSH (Windows Scripting Host). So "dude".substring(0, 1)

随机观察:在大多数JS环境中, "dude"[0] === "d" ,但在WSH(Windows脚本宿主)中undefined 。 因此, "dude".substring(0, 1)

Tell your friends about this post on Facebook and Twitter

FacebookTwitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/cssminjs-in-windows-shell/

shell.windows

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值