@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) throws Exception { String path = filename.startsWith("/") ? filename.substring(1) : filename; return engine(V8Engine.class) .execute("r.js", source, options(), path); }
public V8Object hash() { return hash(v8); }
public String execute(final String path, final Object... args) throws Exception { V8Function fn = register(v8, (V8Function) load(path)); V8Array arguments = array(Arrays.asList(args)); Object value = null; try { value = register(v8, fn.call(v8, arguments)); if (value instanceof String) { return value.toString(); } List<AssetProblem> problems = problems(value); if (problems.size() > 0) { throw new AssetException(id, problems); } return ((V8Object) value).getString("output"); } finally { releaseNow(value); releaseNow(arguments); releaseNow(fn); } }
V8 v8 = engine.v8; V8Object j2v8 = engine.hash(); j2v8.add("createFilter", engine.function((receiver, args) -> { List<PathMatcher> includes = filter(args, 0).stream() .map(it -> FileSystems.getDefault().getPathMatcher("glob:" + it)) return engine.function((self, arguments) -> { Path path = Paths.get(arguments.get(0).toString()); if (includes.stream().filter(it -> it.matches(path)).findFirst().isPresent()) { log.debug("{}", options); return engine.execute("rollup.js", source, options, filename);
private V8Engine v8(String id, String scope) { return cache.computeIfAbsent(Thread.currentThread().getName() + ":" + id, name -> { V8 v8 = V8.createV8Runtime(scope); MemoryManager mem = new MemoryManager(v8); console(v8, id); assets(getClass(), v8); b64(v8); return new V8Engine(v8, mem, id); }); }
V8 v8 = engine.v8; V8Object j2v8 = engine.hash(); j2v8.add("createFilter", engine.function((receiver, args) -> { List<PathMatcher> includes = filter(args, 0).stream() .map(it -> FileSystems.getDefault().getPathMatcher("glob:" + it)) return engine.function((self, arguments) -> { Path path = Paths.get(arguments.get(0).toString()); if (includes.stream().filter(it -> it.matches(path)).findFirst().isPresent()) { log.debug("{}", options); return engine.execute("rollup.js", source, options, filename);
@SuppressWarnings("unchecked") @Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) throws Exception { Map<String, Object> options = new LinkedHashMap<>(options()); Map<String, Object> predef = (Map<String, Object>) options.remove("predef"); options.remove("excludes"); return engine(V8Engine.class, "global") .execute("jshint.js", source, options(), predef, filename); }
@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) throws Exception { return engine(V8Engine.class) .execute("uglify.js", source, options(), filename); }
@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) throws Exception { return engine(V8Engine.class) .execute("auto-prefixer.js", source, options(), filename); }
@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) throws Exception { return engine(V8Engine.class) .execute("csslint.js", source, options(), filename); }
@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) throws Exception { return engine(V8Engine.class) .execute("less.js", source, options(), filename); }
@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) throws Exception { return engine(V8Engine.class) .execute("babel.js", source, options(), filename); }
@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) throws Exception { return engine(V8Engine.class) .execute("ng-annotate.js", source, options(), filename); }
@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) throws Exception { return engine(V8Engine.class) .execute("clean-css.js", source, options(), filename); }
@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) throws Exception { return engine(V8Engine.class, "global") .execute("jscs.js", source, options(), filename); }