use of com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES in project flow by vaadin.
the class UpdateThemedImportsTest method setup.
@Before
public void setup() throws Exception {
File tmpRoot = temporaryFolder.getRoot();
frontendDirectory = new File(tmpRoot, DEFAULT_FRONTEND_DIR);
nodeModulesPath = new File(tmpRoot, NODE_MODULES);
generatedPath = new File(tmpRoot, Paths.get(TARGET, DEFAULT_GENERATED_DIR).toString());
importsFile = new File(generatedPath, IMPORTS_NAME);
Assert.assertTrue(nodeModulesPath.mkdirs());
createImport("./src/subfolder/sub-template.js", "");
createImport("./src/client-side-template.js", "import 'xx' from './subfolder/sub-template.js';" + "import '@vaadin/vaadin-button/src/vaadin-button.js'");
createImport("./src/client-side-no-themed-template.js", "");
createImport("./src/main-template.js", "import 'xx' from './client-side-template.js';" + "import \"./client-side-no-themed-template.js\";" + "import './src/wrong-themed-template.js';" + "import '@vaadin/vaadin-button/src/vaadin-button.js'");
// create themed modules
createImport("./theme/myTheme/subfolder/sub-template.js", "");
createImport("./theme/myTheme/client-side-template.js", "");
createImport("./theme/myTheme/main-template.js", "");
// wrong-themed-template.js should not be resolved inside node_modules.
// It should be searched only inside frontend directory
createImport("theme/myTheme/wrong-themed-template.js", "");
// create css files to avoid exception when files not found during the
// test
createImport("./foo.css", "");
createImport("@vaadin/vaadin-mixed-component/bar.css", "");
// make external component's module and its themed version
createImport("@vaadin/vaadin-button/src/vaadin-button.js", "");
createImport("@vaadin/vaadin-button/theme/myTheme/vaadin-button.js", "");
ClassFinder finder = getClassFinder();
FrontendDependencies deps = new FrontendDependencies(finder) {
@Override
public List<String> getModules() {
return Stream.of("./src/main-template.js").collect(Collectors.toList());
}
@Override
public Set<String> getScripts() {
return Collections.emptySet();
}
@Override
public AbstractTheme getTheme() {
return new MyTheme();
}
@Override
public ThemeDefinition getThemeDefinition() {
return new ThemeDefinition(MyTheme.class, "", "");
}
};
updater = new TaskUpdateImports(finder, deps, cf -> null, tmpRoot, generatedPath, frontendDirectory, null, null, false, TARGET, true, false, Mockito.mock(FeatureFlags.class));
}
use of com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES in project flow by vaadin.
the class AbstractNodeUpdateImportsTest method setup.
@Before
public void setup() throws Exception {
File tmpRoot = temporaryFolder.getRoot();
logger = new MockLogger();
frontendDirectory = new File(tmpRoot, DEFAULT_FRONTEND_DIR);
nodeModulesPath = new File(tmpRoot, NODE_MODULES);
generatedPath = new File(tmpRoot, Paths.get(TARGET, DEFAULT_GENERATED_DIR).toString());
importsFile = new File(generatedPath, IMPORTS_NAME);
ClassFinder classFinder = getClassFinder();
updater = new TaskUpdateImports(classFinder, getScanner(classFinder), finder -> null, tmpRoot, generatedPath, frontendDirectory, null, null, false, TARGET, true, false, Mockito.mock(FeatureFlags.class)) {
@Override
Logger log() {
return logger;
}
};
assertTrue(nodeModulesPath.mkdirs());
createExpectedImports(frontendDirectory, nodeModulesPath);
assertTrue(new File(nodeModulesPath, FLOW_NPM_PACKAGE_NAME + "ExampleConnector.js").exists());
}
use of com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES in project flow by vaadin.
the class NodeUpdater method getGeneratedModules.
static Set<String> getGeneratedModules(File directory, Set<String> excludes) {
if (!directory.exists()) {
return Collections.emptySet();
}
final Function<String, String> unixPath = str -> str.replace("\\", "/");
final URI baseDir = directory.toURI();
return FileUtils.listFiles(directory, new String[] { "js" }, true).stream().filter(file -> {
String path = unixPath.apply(file.getPath());
if (path.contains("/node_modules/")) {
return false;
}
return excludes.stream().noneMatch(postfix -> path.endsWith(unixPath.apply(postfix)));
}).map(file -> GENERATED_PREFIX + unixPath.apply(baseDir.relativize(file.toURI()).getPath())).collect(Collectors.toSet());
}
Aggregations