How to use the coffee-script.compile function in coffee-script

To help you get started, we’ve selected a few coffee-script examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SimonDegraeve / cjsxify / index.js View on Github external
function compile(file, data, callback) {
    var compiled;
    try {
        compiled = coffee.compile(cjsx(data), { // compile cjsx to coffee, then coffee to js
            sourceMap: true,
            generatedFile: file,
            inline: true,
            bare: true,
            literate: false
        });
    } catch (e) {
        var error = e;
        if (e.location) {
            error = new ParseError(e, data, file);
        }
        callback(error);
        return;
    }

    var map = convert.fromJSON(compiled.v3SourceMap);
github rlidwka / node-hotswap / hotswap.js View on Github external
function extension_js(type, module, filename)
{
	var is_hotswap_file = false;
	var content = get_file_contents(filename);
	delete fscache[filename];
	var iscompiled = false;
	
	fs.stat(filename, function(err, stats) {
		hotswap[filename] = stats.mtime;
	});

	if (type == 'coffee') {
		var compiled = require('coffee-script').compile(content, {
			filename: filename
		});
		module._compile(compiled, filename);
	} else {
		module._compile(content, filename);
	}

	var oldmodule = loaded_mods[filename];
	var newmodule = require.cache[filename];
	// require('repl').start() resets require.cache?
	if (typeof(newmodule) !== 'object') return;

	is_hotswap_file = !!newmodule.change_code;
	if (!is_hotswap_file) return;

	if (typeof(newmodule.exports) != 'object' && typeof(newmodule.exports) != 'function') {
github sequelize / umzug / test / fixtures / index.js View on Github external
this.customResolver = path => {
      const coffeescriptSrc = readFileSync(path, 'utf8');
      const javascriptSrc = coffeescript.compile(coffeescriptSrc);
      const Module = module.constructor;
      const m = new Module(path, module.parent);
      m.filename = path;
      m.paths = Module._nodeModulePaths(dirname(path));
      m._compile(javascriptSrc, path);
      return m.exports;
    };
github jgallen23 / gapserver / server.js View on Github external
fs.readFile(file, 'utf8', function(err, str) {
          var js = coffeeScript.compile(str);
          var jsFile = file.replace(".coffee", ".js");
          fs.writeFile(jsFile, js, function(err) {
            console.log("Created: "+jsFile);
            cb2();
          });
        });
      };
github 1602 / compound / lib / server / structure.js View on Github external
function requireFile(file) {
            switch (key) {
                case 'views':
                return path.normalize(file);
                case 'controllers':
                if (file.match(/_controller/)) {
                    var src = fs.readFileSync(file).toString();
                    return file.match(/\.coffee$/) ? cs.compile(src) : src;
                } else {
                    return require(file);
                }
                default:
                return require(file);
            }
        }
    };
github neftjs / neft / __old__ / lib / module-cache / index.js View on Github external
exports.compileFile = function (file, filename) {
    const extname = pathUtils.extname(filename);
    switch (extname) {
    case '.coffee':
        return CoffeeScript.compile(file);
    case '.litcoffee':
        return CoffeeScript.compile(file, {literate: true});
    case '.js':
        BABEL_OPTIONS.filename = filename;
        return babel.transform(file, BABEL_OPTIONS).code;
    case '.yaml':
    case '.yml': {
        const object = yaml.safeLoad(file, { filename: filename, json: true });
        return JSON.stringify(object);
    }
    case '.nml': {
        const bundle = require('src/nml-parser').bundle({ nml: file, path: filename }).bundle;
        return CoffeeScript.compile(bundle);
    }
    default:
        return file;
github Teal / TealUI / tools / node / node_modules2 / utilskit / parsers.js View on Github external
parseCoffeeScriptSync: function(content, options) {
		var coffee = require('coffee-script');
		return coffee.compile(content);
	},
github madskristensen / WebEssentials2013 / EditorExtensions / Resources / server / services / srv-coffeescript.js View on Github external
SourceFileName: params.sourceFileName,
                TargetFileName: params.targetFileName,
                MapFileName: params.mapFileName,
                Remarks: "CoffeeScript: Error reading input file.",
                Details: err,
                Errors: [{
                    Message: "CoffeeScript: " + err,
                    FileName: params.sourceFileName
                }]
            }));
            writer.end();
            return;
        }

        try {
            var compiled = coffeescript.compile(data, options);

            var map = JSON.parse(compiled.v3SourceMap);
            map.file = path.basename(params.targetFileName);
            delete map.sourceRoot;

            var js = compiled.js;
            if (params.sourceMapURL !== undefined)
                js += "\n//# sourceMappingURL=" + path.basename(params.targetFileName) + ".map\n";

            writer.write(JSON.stringify({
                Success: true,
                SourceFileName: params.sourceFileName,
                TargetFileName: params.targetFileName,
                MapFileName: params.mapFileName,
                Remarks: "Successful!",
                Content: js,
github aigis-styleguide / aigis / lib / plugin / src / transform / coffee.js View on Github external
var md = component.md.replace(reg_block, function(codeblock) {
      var code = codeblock.replace(reg_start, '').replace(reg_end, '');
      code = Coffee.compile(code, {bare: true});

      return codeblock + "\n\n";
    });
    component.md = md;
github livereload / livereload-plugins / Jade.lrplugin / node_modules / jade / jade.js View on Github external
coffeescript: function(str){
    var js = require('coffee-script').compile(str).replace(/\\/g, '\\\\').replace(/\n/g, '\\n');
    return '';
  }
};