use of org.eclipse.ceylon.compiler.js.util.JsJULLogger in project ceylon by eclipse.
the class Stitcher method encodeModel.
private static int encodeModel(final File moduleFile) throws IOException {
final String name = moduleFile.getName();
final File file = new File(moduleFile.getParentFile(), name.substring(0, name.length() - 3) + ArtifactContext.JS_MODEL);
System.out.println("Generating language module compile-time model in JSON...");
TypeCheckerBuilder tcb = new TypeCheckerBuilder().usageWarnings(false);
tcb.addSrcDirectory(clSrcDir);
TypeChecker tc = tcb.getTypeChecker();
tc.process(true);
MetamodelVisitor mmg = null;
final ErrorCollectingVisitor errVisitor = new ErrorCollectingVisitor(tc);
for (PhasedUnit pu : tc.getPhasedUnits().getPhasedUnits()) {
pu.getCompilationUnit().visit(errVisitor);
if (errVisitor.getErrorCount() > 0) {
errVisitor.printErrors(false, false);
System.out.println("errors in the language module " + pu.getCompilationUnit().getLocation());
return 1;
}
if (mmg == null) {
mmg = new MetamodelVisitor(pu.getPackage().getModule());
}
pu.getCompilationUnit().visit(mmg);
}
mod = tc.getPhasedUnits().getPhasedUnits().get(0).getPackage().getModule();
try (FileWriter writer = new FileWriter(file)) {
JsCompiler.beginWrapper(writer);
writer.write("ex$.$CCMM$=");
ModelEncoder.encodeModel(mmg.getModel(), writer);
writer.write(";\n");
final JsOutput jsout = new JsOutput(mod, true) {
@Override
public Writer getWriter() throws IOException {
return writer;
}
};
jsout.outputFile(new File(LANGMOD_JS_SRC, "MODEL.js"));
JsCompiler.endWrapper(writer);
} finally {
ShaSigner.sign(file, new JsJULLogger(), true);
}
final File npmFile = new File(moduleFile.getParentFile(), ArtifactContext.NPM_DESCRIPTOR);
try (FileWriter writer = new FileWriter(npmFile)) {
String npmdesc = new NpmDescriptorGenerator(mod, true, false).generateDescriptor();
writer.write(npmdesc);
}
return 0;
}
use of org.eclipse.ceylon.compiler.js.util.JsJULLogger 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