Search in sources :

Example 1 with NODE_MODULES

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));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) DEFAULT_FRONTEND_DIR(com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR) DEFAULT_GENERATED_DIR(com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_GENERATED_DIR) StringUtils(org.apache.commons.lang3.StringUtils) FrontendDependencies(com.vaadin.flow.server.frontend.scanner.FrontendDependencies) Charset(java.nio.charset.Charset) ThemeDefinition(com.vaadin.flow.theme.ThemeDefinition) ExpectedException(org.junit.rules.ExpectedException) AbstractTheme(com.vaadin.flow.theme.AbstractTheme) Before(org.junit.Before) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) Files(java.nio.file.Files) NODE_MODULES(com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) TARGET(com.vaadin.flow.server.Constants.TARGET) Collectors(java.util.stream.Collectors) File(java.io.File) IMPORTS_NAME(com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_NAME) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Rule(org.junit.Rule) Paths(java.nio.file.Paths) FeatureFlags(com.vaadin.experimental.FeatureFlags) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) File(java.io.File) FrontendDependencies(com.vaadin.flow.server.frontend.scanner.FrontendDependencies) ThemeDefinition(com.vaadin.flow.theme.ThemeDefinition) Before(org.junit.Before)

Example 2 with NODE_MODULES

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());
}
Also used : DEFAULT_FRONTEND_DIR(com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR) Arrays(java.util.Arrays) DEFAULT_GENERATED_DIR(com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_GENERATED_DIR) ArrayList(java.util.ArrayList) Charset(java.nio.charset.Charset) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) FrontendDependenciesScanner(com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner) Logger(org.slf4j.Logger) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) Files(java.nio.file.Files) NODE_MODULES(com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES) OpenOption(java.nio.file.OpenOption) StandardOpenOption(java.nio.file.StandardOpenOption) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) TARGET(com.vaadin.flow.server.Constants.TARGET) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) IMPORTS_NAME(com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_NAME) Mockito(org.mockito.Mockito) List(java.util.List) Rule(org.junit.Rule) Paths(java.nio.file.Paths) Assert.assertFalse(org.junit.Assert.assertFalse) FeatureFlags(com.vaadin.experimental.FeatureFlags) FLOW_NPM_PACKAGE_NAME(com.vaadin.flow.server.frontend.FrontendUtils.FLOW_NPM_PACKAGE_NAME) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) Logger(org.slf4j.Logger) File(java.io.File) Before(org.junit.Before)

Example 3 with NODE_MODULES

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());
}
Also used : PACKAGE_JSON(com.vaadin.flow.server.Constants.PACKAGE_JSON) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) Json(elemental.json.Json) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) JsonUtil.stringify(elemental.json.impl.JsonUtil.stringify) FrontendDependencies(com.vaadin.flow.server.frontend.scanner.FrontendDependencies) JsonValue(elemental.json.JsonValue) PACKAGE_LOCK_JSON(com.vaadin.flow.server.Constants.PACKAGE_LOCK_JSON) Map(java.util.Map) Constants(com.vaadin.flow.server.Constants) URI(java.net.URI) Path(java.nio.file.Path) JsonException(elemental.json.JsonException) FrontendDependenciesScanner(com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner) Logger(org.slf4j.Logger) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) NODE_MODULES(com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Paths(java.nio.file.Paths) FeatureFlags(com.vaadin.experimental.FeatureFlags) JsonObject(elemental.json.JsonObject) FLOW_NPM_PACKAGE_NAME(com.vaadin.flow.server.frontend.FrontendUtils.FLOW_NPM_PACKAGE_NAME) Collections(java.util.Collections) COMPATIBILITY_RESOURCES_FRONTEND_DEFAULT(com.vaadin.flow.server.Constants.COMPATIBILITY_RESOURCES_FRONTEND_DEFAULT) InputStream(java.io.InputStream) RESOURCES_FRONTEND_DEFAULT(com.vaadin.flow.server.Constants.RESOURCES_FRONTEND_DEFAULT) URI(java.net.URI)

Aggregations

FeatureFlags (com.vaadin.experimental.FeatureFlags)3 NODE_MODULES (com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES)3 ClassFinder (com.vaadin.flow.server.frontend.scanner.ClassFinder)3 File (java.io.File)3 IOException (java.io.IOException)3 Paths (java.nio.file.Paths)3 List (java.util.List)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 FileUtils (org.apache.commons.io.FileUtils)3 TARGET (com.vaadin.flow.server.Constants.TARGET)2 DEFAULT_FRONTEND_DIR (com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR)2 DEFAULT_GENERATED_DIR (com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_GENERATED_DIR)2 FLOW_NPM_PACKAGE_NAME (com.vaadin.flow.server.frontend.FrontendUtils.FLOW_NPM_PACKAGE_NAME)2 IMPORTS_NAME (com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_NAME)2 FrontendDependencies (com.vaadin.flow.server.frontend.scanner.FrontendDependencies)2 FrontendDependenciesScanner (com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner)2 Charset (java.nio.charset.Charset)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Files (java.nio.file.Files)2