Giter Site home page Giter Site logo

Comments (2)

duncansmart avatar duncansmart commented on July 27, 2024

Thanks Jared - it's easier that you think! See
https://github.com/blog/844-forking-with-the-edit-button

On 4 April 2012 16:00, jaredfholgate <
[email protected]

wrote:

Hi

The following revision to the .wsf file removes read-only flags from css
files to stop the script bombing out. This is particularly relevant for
those of us using TFS. This is my first time in GitHub, so I apologise for
not submitting the code properly, but I have no idea how to.

It checks for the existence of a file before checking and removing its
read-only flag in the convert method.

Regards

Jared

<script language="jscript"> // Stub out globals var window = this; var location = window.location = { port: 0, href: '' }; var fso = new ActiveXObject("Scripting.FileSystemObject"); var input = null; var util = { readText: function (filename) { //WScript.StdErr.WriteLine("readText: " + filename); var file = fso.OpenTextFile(filename); // Don't error on empty files var text = file.AtEndOfStream ? '' : file.ReadAll(); // Strip off any UTF-8 BOM var utf8bom = String.fromCharCode(0xEF, 0xBB, 0xBF); if (text.substr(0, utf8bom.length) == utf8bom) { text = text.substr(utf8bom.length); } file.Close(); return text; } }; // XMLHttpRequest that just gets local files. Used when processing "@import" function XMLHttpRequest(){} XMLHttpRequest.prototype = { open: function (method, url, async) { this.url = url; }, send: function () { // get the file path relative to the input less file/directory var currDir = fso.folderExists(input) ? input : fso.getParentFolderName(input); var filename = fso.BuildPath(currDir, this.url); //WScript.StdErr.WriteLine("XHR.send " + filename); // Little hack so *.less will resolve to *.less.css also. Helps with Visual Studio // ensuring that file BuildAction is set to Content and you get rudimentary syntax highlighting with no set up. if (filename.match(/.less$/i) && !fso.FileExists(filename)) { filename = filename.replace(/.less$/i, '.less.css'); } try { this.status = 200; this.responseText = util.readText(filename); } catch (e) { this.status = 404; this.responseText = e.description; } }, setRequestHeader: function () {}, getResponseHeader: function () {} }; // Fake document var document = { _dummyElement: { childNodes: [], appendChild: function(){}, style: {} }, getElementsByTagName: function(){ return []; }, getElementById: function(){ return this._dummyElement; }, createElement: function(){ return this._dummyElement; }, createTextNode: function(){ return this._dummyElement; } }; </script> <script language="jscript" src="less-1.3.0.js" /> <script language="jscript"> // Parse args var args = {}; for (var i = 0; i < WScript.Arguments.Length; i++) { var arg = WScript.Arguments.Item(i); // Handle "-switch" and "--switch" var match = arg.match(/^--?([a-z][0-9a-z-]*)$/i); if (match) { i = match[1]; arg = true; } args[i] = arg; } input = args[0]; var output = args[1]; if (fso.folderExists(input)) { input = fso.getAbsolutePathName(input); var files = getFiles(input, /\.less$/i); for (var i = 0; i < files.length; i++) { var file = files[i]; convert(file.path, output + '\\' + file.name.replace( /\.less$/i, '.css')); } } else { if (fso.folderexists(output)) { output = fso.getAbsolutePathName(output) + '\\' + fso.getfile(input).name.replace(/\.less$/i, '.css'); } convert(input, output); } // Returns array of {name:'foo.bar', path:'c:\baz\foo.bar'} for given directory and pattern function getFiles(dir, regex) { var e = new Enumerator(fso.getFolder(dir).files); var files = [] for (; !e.atEnd(); e.moveNext()) { if (regex.test(e.item().path)) { files.push({ name: e.item().name, path: e.item().path }); } } return files; } function convert(input, output) { if (!input) { WScript.StdErr.WriteLine("lessc.wsf: no input files"); WScript.StdErr.WriteLine("Usage:"); WScript.StdErr.WriteLine(" Single file: cscript //nologo lessc.wsf input.less [output.css] [-compress]"); WScript.StdErr.WriteLine(" Directory: cscript //nologo lessc.wsf inputdir outputdir [-compress]"); WScript.Quit(1); } var data; if (input == '-') { var chunks = []; while (!WScript.StdIn.AtEndOfStream) chunks.push(WScript.StdIn.ReadAll()); data = chunks.join(''); } else { data = util.readText(input); } var parser = new less.Parser({ filename: input }); try { parser.parse(data, function (err, tree) { if (err) { WScript.StdErr.WriteLine("ERR: "); for (var i in err) { if (err[i]) { WScript.StdErr.WriteLine(" " + i + ': ' + err[i]); } } WScript.Quit(2); } else { var css = tree.toCSS({ compress: args.compress }); if (output) { if(fso.FileExists(output)) { var checkfile = fso.GetFile(output); if(checkfile.Attributes & 1) { checkfile.Attributes = checkfile.Attributes ^ 1 } } var outputfile = fso.CreateTextFile(output,true); outputfile.Write(css); outputfile.Close(); } else { WScript.StdOut.Write(css); } } }); } catch (e) { WScript.StdErr.WriteLine("ERROR:"); for (var i in e) { if (e[i]) { WScript.StdErr.WriteLine(" " + i + ': ' + e[i]); } } WScript.Quit(3); } // Sometimes less will return errors inside the fake HTML element if (document._dummyElement.innerHTML && document._dummyElement.innerHTML.match(/Syntax Error/i)) { var s = document._dummyElement.innerHTML; s = s.replace(/<[^>]+(\/?)>/g, function (m) { return m.indexOf('/') > 0 && m !== '' ? "\n" : '' }); s = s.replace(/\n+/g, '\n'); WScript.StdErr.WriteLine("ERR: "); WScript.StdErr.WriteLine(s); WScript.Quit(2); } } </script>

Reply to this email directly or view it on GitHub:
#15

from less.js-windows.

jaredfholgate avatar jaredfholgate commented on July 27, 2024

Thanks, I have added a pull request now.

from less.js-windows.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.