Search in sources :

Example 6 with Contributor

use of com.twinsoft.convertigo.beans.ngx.components.Contributor in project convertigo by convertigo.

the class NgxBuilder method writeAppBuildSettings.

private void writeAppBuildSettings(ApplicationComponent app) throws EngineException {
    try {
        if (app != null) {
            Set<String> build_assets = new HashSet<String>();
            Set<String> build_scripts = new HashSet<String>();
            Set<String> build_styles = new HashSet<String>();
            // Menus contributors
            for (Contributor contributor : app.getContributors()) {
                build_assets.addAll(contributor.getBuildAssets());
                build_scripts.addAll(contributor.getBuildScripts());
                build_styles.addAll(contributor.getBuildStyles());
            }
            // Pages contributors
            List<PageComponent> pages = forceEnable ? app.getPageComponentList() : getEnabledPages(app);
            for (PageComponent page : pages) {
                synchronized (page) {
                    List<Contributor> contributors = page.getContributors();
                    for (Contributor contributor : contributors) {
                        build_assets.addAll(contributor.getBuildAssets());
                        build_scripts.addAll(contributor.getBuildScripts());
                        build_styles.addAll(contributor.getBuildStyles());
                    }
                }
            }
            boolean hasSettings = !build_assets.isEmpty() || !build_scripts.isEmpty() || !build_styles.isEmpty();
            if (hasSettings) {
                File tplAngularJson = new File(ionicTplDir, "angular.json");
                if (tplAngularJson.exists()) {
                    String content = FileUtils.readFileToString(tplAngularJson, "UTF-8");
                    JSONObject jsonObject = new JSONObject(content);
                    JSONObject jsonOptions = jsonObject.getJSONObject("projects").getJSONObject("app").getJSONObject("architect").getJSONObject("build").getJSONObject("options");
                    JSONArray jsonArray = null;
                    try {
                        // Assets
                        jsonArray = jsonOptions.getJSONArray("assets");
                        for (String asset : build_assets) {
                            if (jsonArrayContains(jsonArray, asset)) {
                                continue;
                            }
                            try {
                                JSONObject jsonAsset = new JSONObject(asset);
                                jsonArray.put(jsonAsset);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        // Scripts
                        jsonArray = jsonOptions.getJSONArray("scripts");
                        for (String script : build_scripts) {
                            if (jsonArrayContains(jsonArray, script)) {
                                continue;
                            }
                            try {
                                jsonArray.put(script);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        // Styles
                        jsonArray = jsonOptions.getJSONArray("styles");
                        for (String style : build_styles) {
                            if (jsonArrayContains(jsonArray, style)) {
                                continue;
                            }
                            try {
                                jsonArray.put(style);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    setNeedPkgUpdate(true);
                    File angularJson = new File(ionicWorkDir, "angular.json");
                    String aContent = jsonObject.toString(1);
                    writeFile(angularJson, aContent, "UTF-8");
                }
            }
            if (initDone) {
                Engine.logEngine.trace("(MobileBuilder) App angular json file generated");
            }
        }
    } catch (Exception e) {
        throw new EngineException("Unable to write angular json file", e);
    }
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) EngineException(com.twinsoft.convertigo.engine.EngineException) Contributor(com.twinsoft.convertigo.beans.ngx.components.Contributor) IPageComponent(com.twinsoft.convertigo.beans.core.IPageComponent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException) JSONObject(org.codehaus.jettison.json.JSONObject) File(java.io.File) HashSet(java.util.HashSet)

Example 7 with Contributor

use of com.twinsoft.convertigo.beans.ngx.components.Contributor in project convertigo by convertigo.

the class NgxBuilder method writeAppServiceTs.

private void writeAppServiceTs(ApplicationComponent app) throws EngineException {
    try {
        if (app != null) {
            Map<String, String> action_ts_imports = new HashMap<>();
            Map<String, String> action_ts_functions = new HashMap<>();
            // App contributors
            for (Contributor contributor : app.getContributors()) {
                contributor.forContainer(app, () -> {
                    action_ts_imports.putAll(contributor.getActionTsImports());
                    action_ts_functions.putAll(contributor.getActionTsFunctions());
                });
            }
            // Shared components
            for (UISharedComponent comp : app.getSharedComponentList()) {
                if (comp.isRegular()) {
                    List<Contributor> contributors = comp.getContributors();
                    for (Contributor contributor : contributors) {
                        contributor.forContainer(app, () -> {
                            action_ts_imports.putAll(contributor.getActionTsImports());
                            action_ts_functions.putAll(contributor.getActionTsFunctions());
                        });
                    }
                }
            }
            // Pages contributors
            List<PageComponent> pages = forceEnable ? app.getPageComponentList() : getEnabledPages(app);
            for (PageComponent page : pages) {
                synchronized (page) {
                    List<Contributor> contributors = page.getContributors();
                    for (Contributor contributor : contributors) {
                        contributor.forContainer(app, () -> {
                            action_ts_imports.putAll(contributor.getActionTsImports());
                            action_ts_functions.putAll(contributor.getActionTsFunctions());
                        });
                    }
                }
            }
            String c8o_ActionTsImports = "";
            for (String comp : action_ts_imports.keySet()) {
                if (!getTplServiceActionTsImports().containsKey(comp)) {
                    if (comp.indexOf(" as ") == -1) {
                        String comPath = action_ts_imports.get(comp).replace("./pages", "../pages");
                        c8o_ActionTsImports += "import { " + comp + " } from '" + comPath + "';" + System.lineSeparator();
                    } else {
                        c8o_ActionTsImports += "import " + comp + " from '" + action_ts_imports.get(comp) + "';" + System.lineSeparator();
                    }
                }
            }
            String c8o_ActionTsFunctions = System.lineSeparator();
            for (String function : action_ts_functions.values()) {
                c8o_ActionTsFunctions += function + System.lineSeparator();
            }
            File appServiceTpl = new File(ionicTplDir, "src/app/services/actionbeans.service.ts");
            String mContent = FileUtils.readFileToString(appServiceTpl, "UTF-8");
            mContent = mContent.replaceAll("/\\*\\=c8o_ActionTsImports\\*/", Matcher.quoteReplacement(c8o_ActionTsImports));
            mContent = mContent.replaceAll("/\\*\\=c8o_ActionTsFunctions\\*/", Matcher.quoteReplacement(c8o_ActionTsFunctions));
            File appServiceTsFile = new File(servicesDir, "actionbeans.service.ts");
            writeFile(appServiceTsFile, mContent, "UTF-8");
            if (initDone) {
                Engine.logEngine.trace("(MobileBuilder) Ionic service ts file generated for 'app'");
            }
        }
    } catch (Exception e) {
        throw new EngineException("Unable to write ionic app service ts file", e);
    }
}
Also used : HashMap(java.util.HashMap) EngineException(com.twinsoft.convertigo.engine.EngineException) Contributor(com.twinsoft.convertigo.beans.ngx.components.Contributor) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) File(java.io.File) IPageComponent(com.twinsoft.convertigo.beans.core.IPageComponent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 8 with Contributor

use of com.twinsoft.convertigo.beans.ngx.components.Contributor in project convertigo by convertigo.

the class NgxBuilder method writeAppPackageJson.

private void writeAppPackageJson(ApplicationComponent app) throws EngineException {
    try {
        if (app != null) {
            Map<String, String> pkg_dependencies = new HashMap<>();
            // Menus contributors
            for (Contributor contributor : app.getContributors()) {
                pkg_dependencies.putAll(contributor.getPackageDependencies());
            }
            // Pages contributors
            List<PageComponent> pages = forceEnable ? app.getPageComponentList() : getEnabledPages(app);
            for (PageComponent page : pages) {
                synchronized (page) {
                    List<Contributor> contributors = page.getContributors();
                    for (Contributor contributor : contributors) {
                        pkg_dependencies.putAll(contributor.getPackageDependencies());
                    }
                }
            }
            // Shared components contributors
            for (UISharedComponent comp : app.getSharedComponentList()) {
                if (comp.isRegular()) {
                    List<Contributor> contributors = comp.getContributors();
                    for (Contributor contributor : contributors) {
                        pkg_dependencies.putAll(contributor.getPackageDependencies());
                    }
                }
            }
            File appPkgJsonTpl = new File(ionicTplDir, "package.json");
            String mContent = FileUtils.readFileToString(appPkgJsonTpl, "UTF-8");
            mContent = mContent.replaceAll("\\.\\./DisplayObjects", "../../DisplayObjects");
            mContent = mContent.replaceAll("\\{\\{c8o_project\\}\\}", app.getProject().getName());
            JSONObject jsonPackage = new JSONObject(mContent);
            JSONObject jsonDependencies = jsonPackage.getJSONObject("dependencies");
            for (String pkg : pkg_dependencies.keySet()) {
                jsonDependencies.put(pkg, pkg_dependencies.get(pkg));
                if (!existPackage(pkg)) {
                    setNeedPkgUpdate(true);
                }
            }
            boolean addNode = !jsonDependencies.has("@types/node");
            if (addNode) {
                try {
                    String version = new JSONObject(FileUtils.readFileToString(new File(ionicTplDir, "version.json"), "utf-8")).getString("version");
                    addNode = version.matches("7\\.[0-7]\\..*");
                } catch (Exception e) {
                }
                if (addNode) {
                    jsonDependencies.put("@types/node", "12.0.10");
                }
            }
            File appPkgJson = new File(ionicWorkDir, "package.json");
            writeFile(appPkgJson, jsonPackage.toString(2), "UTF-8");
            if (initDone) {
                Engine.logEngine.trace("(MobileBuilder) Ionic package json file generated");
            }
        }
    } catch (Exception e) {
        throw new EngineException("Unable to write ionic package json file", e);
    }
}
Also used : HashMap(java.util.HashMap) EngineException(com.twinsoft.convertigo.engine.EngineException) Contributor(com.twinsoft.convertigo.beans.ngx.components.Contributor) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) IPageComponent(com.twinsoft.convertigo.beans.core.IPageComponent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException) JSONObject(org.codehaus.jettison.json.JSONObject) File(java.io.File)

Aggregations

Contributor (com.twinsoft.convertigo.beans.ngx.components.Contributor)8 File (java.io.File)8 EngineException (com.twinsoft.convertigo.engine.EngineException)7 IOException (java.io.IOException)7 HashMap (java.util.HashMap)6 IPageComponent (com.twinsoft.convertigo.beans.core.IPageComponent)5 PageComponent (com.twinsoft.convertigo.beans.ngx.components.PageComponent)5 HashSet (java.util.HashSet)4 JSONObject (org.codehaus.jettison.json.JSONObject)3 UISharedComponent (com.twinsoft.convertigo.beans.ngx.components.UISharedComponent)2 Matcher (java.util.regex.Matcher)2 JSONArray (org.codehaus.jettison.json.JSONArray)1