use of org.eclipse.ceylon.compiler.js.util.JsOutput in project ceylon by eclipse.
the class Stitcher method main.
public static void main(String[] args) throws IOException {
if (args.length < 2) {
System.err.println("This program requires 2 arguments to run:");
System.err.println("1. The path to the master file (the one with the list of files to compile)");
System.err.println("2. The path of the resulting JS file");
System.exit(1);
return;
}
// Force coloring of output if not already set
String useColors = System.getProperty(Constants.PROP_CEYLON_TERM_COLORS, "yes");
System.setProperty(Constants.PROP_CEYLON_TERM_COLORS, useColors);
int exitCode = 0;
tmpDir = Files.createTempDirectory("ceylon-jsstitcher-");
try {
File infile = new File(args[0]);
if (infile.exists() && infile.isFile() && infile.canRead()) {
File outfile = new File(args[1]);
if (!outfile.getParentFile().exists()) {
FileUtil.mkdirs(outfile);
}
exitCode = encodeModel(outfile);
if (exitCode == 0) {
final int p0 = args[1].indexOf(".language-");
final String version = args[1].substring(p0 + 10, args[1].length() - 3);
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(outfile), "UTF-8")) {
final JsOutput jsout = new JsOutput(mod, true) {
@Override
public Writer getWriter() throws IOException {
return writer;
}
};
// CommonJS wrapper
JsCompiler.beginWrapper(writer);
JsCompiler.requireWrapper(writer, mod);
// Model
jsout.out("var _CTM$;function $CCMM$(){if (_CTM$===undefined)_CTM$=require('", "ceylon/language/", version, "/ceylon.language-", version, "-model", "').$CCMM$;return _CTM$;}\nex$.$CCMM$=$CCMM$;");
// Compile all the listed files
exitCode = stitch(infile, jsout);
// Unshared declarations
if (names != null) {
jsout.publishUnsharedDeclarations(names);
}
// Close the commonJS wrapper
JsCompiler.endWrapper(writer);
} finally {
ShaSigner.sign(outfile, new JsJULLogger(), true);
}
}
} else {
System.err.println("Input file is invalid: " + infile);
exitCode = 2;
}
} finally {
FileUtil.deleteQuietly(tmpDir.toFile());
}
if (exitCode != 0) {
System.exit(exitCode);
}
}
Aggregations