use of com.twinsoft.convertigo.beans.mobile.components.Contributor in project convertigo by convertigo.
the class Ionic3Builder 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());
}
}
}
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);
}
}
use of com.twinsoft.convertigo.beans.mobile.components.Contributor in project convertigo by convertigo.
the class Ionic3Builder method writeAppPluginsConfig.
private void writeAppPluginsConfig(ApplicationComponent app) throws EngineException {
try {
if (app != null) {
Map<String, String> cfg_plugins = new HashMap<>();
// Menus contributors
for (Contributor contributor : app.getContributors()) {
cfg_plugins.putAll(contributor.getConfigPlugins());
}
// 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) {
cfg_plugins.putAll(contributor.getConfigPlugins());
}
}
}
String mandatoryPlugins = "";
for (String plugin : cfg_plugins.keySet()) {
try {
JSONObject json = new JSONObject(cfg_plugins.get(plugin));
String version = json.getString("version");
mandatoryPlugins += "\t<plugin name=\"" + plugin + "\" spec=\"" + version + "\">" + System.lineSeparator();
if (json.has("variables")) {
JSONObject jsonVars = json.getJSONObject("variables");
@SuppressWarnings("unchecked") Iterator<String> it = jsonVars.keys();
while (it.hasNext()) {
String variable = it.next();
if (!variable.isEmpty()) {
String value = jsonVars.getString(variable);
mandatoryPlugins += "\t\t<variable name=\"" + variable + "\" value=\"" + value + "\" />" + System.lineSeparator();
}
}
}
mandatoryPlugins += "\t</plugin>" + System.lineSeparator();
} catch (Exception e) {
}
}
File appPlgConfig = new File(ionicWorkDir, "src/plugins.txt");
writeFile(appPlgConfig, mandatoryPlugins, "UTF-8");
if (initDone) {
Engine.logEngine.trace("(MobileBuilder) App plugins config file generated");
}
}
} catch (Exception e) {
throw new EngineException("Unable to write app plugins config file", e);
}
}
use of com.twinsoft.convertigo.beans.mobile.components.Contributor in project convertigo by convertigo.
the class Ionic3Builder method getPageModuleTsContent.
private String getPageModuleTsContent(PageComponent page) throws IOException {
// contributors
Map<String, File> comp_beans_dirs = new HashMap<>();
Map<String, String> module_ts_imports = new HashMap<>();
Set<String> module_ng_imports = new HashSet<String>();
Set<String> module_ng_providers = new HashSet<String>();
Set<String> module_ng_declarations = new HashSet<String>();
Set<String> module_ng_components = new HashSet<String>();
List<Contributor> contributors = page.getContributors();
for (Contributor contributor : contributors) {
comp_beans_dirs.putAll(contributor.getCompBeanDir());
module_ts_imports.putAll(contributor.getModuleTsImports());
module_ng_imports.addAll(contributor.getModuleNgImports());
module_ng_providers.addAll(contributor.getModuleNgProviders());
module_ng_declarations.addAll(contributor.getModuleNgDeclarations());
module_ng_components.addAll(contributor.getModuleNgComponents());
}
// fix for BrowserAnimationsModule until it will be handled in config
module_ts_imports.remove("BrowserAnimationsModule");
module_ng_imports.remove("BrowserAnimationsModule");
String c8o_ModuleTsImports = "";
Map<String, String> tpl_ts_imports = getTplPageModuleTsImports();
if (!module_ts_imports.isEmpty()) {
for (String comp : module_ts_imports.keySet()) {
if (!tpl_ts_imports.containsKey(comp)) {
String from = module_ts_imports.get(comp);
if (comp.indexOf(" as ") != -1) {
c8o_ModuleTsImports += "import " + comp + " from '" + from + "';" + System.lineSeparator();
} else {
from = (from.startsWith("../components/") ? "../" : "") + from;
c8o_ModuleTsImports += "import { " + comp + " } from '" + from + "';" + System.lineSeparator();
}
}
}
}
String c8o_ModuleNgImports = "";
String tpl_ng_imports = getTplPageModuleNgImports();
if (!module_ng_imports.isEmpty()) {
for (String module : module_ng_imports) {
if (!tpl_ng_imports.contains(module)) {
c8o_ModuleNgImports += "\t" + module + "," + System.lineSeparator();
}
}
if (!c8o_ModuleNgImports.isEmpty()) {
c8o_ModuleNgImports = System.lineSeparator() + c8o_ModuleNgImports;
}
}
String c8o_ModuleNgProviders = "";
String tpl_ng_providers = getTplPageModuleNgProviders();
if (!module_ng_providers.isEmpty()) {
for (String provider : module_ng_providers) {
if (!tpl_ng_providers.contains(provider)) {
c8o_ModuleNgProviders += "\t" + provider + "," + System.lineSeparator();
}
}
if (!c8o_ModuleNgProviders.isEmpty()) {
c8o_ModuleNgProviders = System.lineSeparator() + c8o_ModuleNgProviders;
}
}
String c8o_ModuleNgDeclarations = "";
String tpl_ng_declarations = getTplPageModuleNgDeclarations();
if (!module_ng_declarations.isEmpty()) {
for (String declaration : module_ng_declarations) {
if (!tpl_ng_declarations.contains(declaration)) {
c8o_ModuleNgDeclarations += "\t" + declaration + "," + System.lineSeparator();
}
}
if (!c8o_ModuleNgDeclarations.isEmpty()) {
c8o_ModuleNgDeclarations = System.lineSeparator() + c8o_ModuleNgDeclarations;
}
}
String c8o_ModuleNgComponents = "";
String tpl_ng_components = getTplPageModuleNgComponents();
if (!module_ng_components.isEmpty()) {
for (String component : module_ng_components) {
if (!tpl_ng_components.contains(component)) {
c8o_ModuleNgComponents += "\t" + component + "," + System.lineSeparator();
}
}
if (!c8o_ModuleNgComponents.isEmpty()) {
c8o_ModuleNgComponents = System.lineSeparator() + c8o_ModuleNgComponents;
}
}
String pageName = page.getName();
String c8o_PageName = pageName;
String c8o_PageModuleName = pageName + "Module";
String c8o_PageImport = "import { " + pageName + " } from \"./" + pageName.toLowerCase() + "\";" + System.lineSeparator();
File pageTplTs = new File(ionicTplDir, "src/page.module.tpl");
String tsContent = FileUtils.readFileToString(pageTplTs, "UTF-8");
tsContent = tsContent.replaceAll("/\\*\\=c8o_PageName\\*/", c8o_PageName);
tsContent = tsContent.replaceAll("/\\*\\=c8o_PageModuleName\\*/", c8o_PageModuleName);
tsContent = tsContent.replaceAll("/\\*\\=c8o_PageImport\\*/", c8o_PageImport);
tsContent = tsContent.replaceAll("/\\*\\=c8o_ModuleTsImports\\*/", c8o_ModuleTsImports);
tsContent = tsContent.replaceAll("/\\*Begin_c8o_NgModules\\*/", c8o_ModuleNgImports);
tsContent = tsContent.replaceAll("/\\*End_c8o_NgModules\\*/", "");
tsContent = tsContent.replaceAll("/\\*Begin_c8o_NgProviders\\*/", c8o_ModuleNgProviders);
tsContent = tsContent.replaceAll("/\\*End_c8o_NgProviders\\*/", "");
tsContent = tsContent.replaceAll("/\\*Begin_c8o_NgDeclarations\\*/", c8o_ModuleNgDeclarations);
tsContent = tsContent.replaceAll("/\\*End_c8o_NgDeclarations\\*/", "");
tsContent = tsContent.replaceAll("/\\*Begin_c8o_NgComponents\\*/", c8o_ModuleNgComponents);
tsContent = tsContent.replaceAll("/\\*End_c8o_NgComponents\\*/", "");
for (String compbean : comp_beans_dirs.keySet()) {
File srcDir = comp_beans_dirs.get(compbean);
File destDir = new File(ionicWorkDir, "src/components/" + compbean + "/");
Matcher m = Pattern.compile("file:(/.*?)!/(.*)").matcher(srcDir.getPath().replace('\\', '/'));
if (m.matches()) {
ZipUtils.expandZip(m.group(1), destDir.getAbsolutePath(), m.group(2));
} else {
for (File f : srcDir.listFiles()) {
String fContent = FileUtils.readFileToString(f, "UTF-8");
File destFile = new File(ionicWorkDir, "src/components/" + compbean + "/" + f.getName());
writeFile(destFile, fContent, "UTF-8");
}
}
}
return tsContent;
}
use of com.twinsoft.convertigo.beans.mobile.components.Contributor in project convertigo by convertigo.
the class Ionic3Builder method writeAppModuleTs.
private void writeAppModuleTs(ApplicationComponent app) throws EngineException {
try {
if (app != null) {
String c8o_PagesImport = "";
String c8o_PagesLinks = "";
String c8o_PagesDeclarations = "";
int i = 1;
Map<String, File> comp_beans_dirs = new HashMap<>();
Map<String, String> module_ts_imports = new HashMap<>();
Set<String> module_ng_imports = new HashSet<String>();
Set<String> module_ng_providers = new HashSet<String>();
Set<String> module_ng_declarations = new HashSet<String>();
Set<String> module_ng_components = new HashSet<String>();
// App contributors
for (Contributor contributor : app.getContributors()) {
comp_beans_dirs.putAll(contributor.getCompBeanDir());
module_ts_imports.putAll(contributor.getModuleTsImports());
module_ng_imports.addAll(contributor.getModuleNgImports());
module_ng_providers.addAll(contributor.getModuleNgProviders());
module_ng_declarations.addAll(contributor.getModuleNgDeclarations());
module_ng_components.addAll(contributor.getModuleNgComponents());
}
// Pages contributors
List<PageComponent> pages = getEnabledPages(app);
for (PageComponent page : pages) {
synchronized (page) {
String pageName = page.getName();
String pageSegment = page.getSegment();
boolean isLastPage = i == pages.size();
if (app.compareToTplVersion("7.7.0.2") < 0) {
c8o_PagesImport += "import { " + pageName + " } from \"../pages/" + pageName + "/" + pageName.toLowerCase() + "\";" + System.lineSeparator();
c8o_PagesLinks += " { component: " + pageName + ", name: \"" + pageName + "\", segment: \"" + pageSegment + "\" }" + (isLastPage ? "" : ",");
c8o_PagesDeclarations += " " + pageName + (isLastPage ? "" : ",");
List<Contributor> contributors = page.getContributors();
for (Contributor contributor : contributors) {
comp_beans_dirs.putAll(contributor.getCompBeanDir());
module_ts_imports.putAll(contributor.getModuleTsImports());
module_ng_imports.addAll(contributor.getModuleNgImports());
module_ng_providers.addAll(contributor.getModuleNgProviders());
module_ng_declarations.addAll(contributor.getModuleNgDeclarations());
module_ng_components.addAll(contributor.getModuleNgComponents());
}
} else {
List<Contributor> contributors = page.getContributors();
for (Contributor contributor : contributors) {
if (contributor.isNgModuleForApp()) {
comp_beans_dirs.putAll(contributor.getCompBeanDir());
module_ts_imports.putAll(contributor.getModuleTsImports());
module_ng_imports.addAll(contributor.getModuleNgImports());
module_ng_providers.addAll(contributor.getModuleNgProviders());
module_ng_declarations.addAll(contributor.getModuleNgDeclarations());
module_ng_components.addAll(contributor.getModuleNgComponents());
}
}
writePageModuleTs(page);
}
i++;
}
}
String c8o_ModuleTsImports = "";
Map<String, String> tpl_ts_imports = getTplAppModuleTsImports();
if (!module_ts_imports.isEmpty()) {
for (String comp : module_ts_imports.keySet()) {
if (!tpl_ts_imports.containsKey(comp)) {
if (comp.indexOf(" as ") != -1) {
c8o_ModuleTsImports += "import " + comp + " from '" + module_ts_imports.get(comp) + "';" + System.lineSeparator();
} else {
c8o_ModuleTsImports += "import { " + comp + " } from '" + module_ts_imports.get(comp) + "';" + System.lineSeparator();
}
}
}
}
String c8o_ModuleNgImports = "";
String tpl_ng_imports = getTplAppModuleNgImports();
if (!module_ng_imports.isEmpty()) {
for (String module : module_ng_imports) {
if (!tpl_ng_imports.contains(module)) {
c8o_ModuleNgImports += "\t" + module + "," + System.lineSeparator();
}
}
if (!c8o_ModuleNgImports.isEmpty()) {
c8o_ModuleNgImports = System.lineSeparator() + c8o_ModuleNgImports;
}
}
String c8o_ModuleNgProviders = "";
String tpl_ng_providers = getTplAppModuleNgProviders();
if (!module_ng_providers.isEmpty()) {
for (String provider : module_ng_providers) {
if (!tpl_ng_providers.contains(provider)) {
c8o_ModuleNgProviders += "\t" + provider + "," + System.lineSeparator();
}
}
if (!c8o_ModuleNgProviders.isEmpty()) {
c8o_ModuleNgProviders = System.lineSeparator() + c8o_ModuleNgProviders;
}
}
String c8o_ModuleNgDeclarations = "";
String tpl_ng_declarations = getTplAppModuleNgDeclarations();
if (!module_ng_declarations.isEmpty()) {
for (String declaration : module_ng_declarations) {
if (!tpl_ng_declarations.contains(declaration)) {
c8o_ModuleNgDeclarations += "\t" + declaration + "," + System.lineSeparator();
}
}
if (!c8o_ModuleNgDeclarations.isEmpty()) {
c8o_ModuleNgDeclarations = System.lineSeparator() + c8o_ModuleNgDeclarations;
}
}
String c8o_ModuleNgComponents = "";
String tpl_ng_components = getTplAppModuleNgComponents();
if (!module_ng_components.isEmpty()) {
for (String component : module_ng_components) {
if (!tpl_ng_components.contains(component)) {
c8o_ModuleNgComponents += "\t" + component + "," + System.lineSeparator();
}
}
if (!c8o_ModuleNgComponents.isEmpty()) {
c8o_ModuleNgComponents = System.lineSeparator() + c8o_ModuleNgComponents;
}
}
boolean c8o_RegisterWorker = isAppPwaAble() && isBuildProdMode();
File appModuleTpl = new File(ionicTplDir, "src/app/app.module.ts");
String mContent = FileUtils.readFileToString(appModuleTpl, "UTF-8");
mContent = mContent.replaceAll("/\\*\\=c8o_RegisterWorker\\*/", String.valueOf(c8o_RegisterWorker));
mContent = mContent.replaceAll("/\\*\\=c8o_ModuleTsImports\\*/", c8o_ModuleTsImports);
mContent = mContent.replaceAll("/\\*\\=c8o_PagesImport\\*/", c8o_PagesImport);
mContent = mContent.replaceAll("/\\*\\=c8o_PagesLinks\\*/", c8o_PagesLinks);
mContent = mContent.replaceAll("/\\*\\=c8o_PagesDeclarations\\*/", c8o_PagesDeclarations);
mContent = mContent.replaceAll("/\\*Begin_c8o_NgModules\\*/", c8o_ModuleNgImports);
mContent = mContent.replaceAll("/\\*End_c8o_NgModules\\*/", "");
mContent = mContent.replaceAll("/\\*Begin_c8o_NgProviders\\*/", c8o_ModuleNgProviders);
mContent = mContent.replaceAll("/\\*End_c8o_NgProviders\\*/", "");
mContent = mContent.replaceAll("/\\*Begin_c8o_NgDeclarations\\*/", c8o_ModuleNgDeclarations);
mContent = mContent.replaceAll("/\\*End_c8o_NgDeclarations\\*/", "");
mContent = mContent.replaceAll("/\\*Begin_c8o_NgComponents\\*/", c8o_ModuleNgComponents);
mContent = mContent.replaceAll("/\\*End_c8o_NgComponents\\*/", "");
File appModuleTsFile = new File(ionicWorkDir, "src/app/app.module.ts");
writeFile(appModuleTsFile, mContent, "UTF-8");
for (String compbean : comp_beans_dirs.keySet()) {
File srcDir = comp_beans_dirs.get(compbean);
for (File f : srcDir.listFiles()) {
String fContent = FileUtils.readFileToString(f, "UTF-8");
File destFile = new File(ionicWorkDir, "src/components/" + compbean + "/" + f.getName());
writeFile(destFile, fContent, "UTF-8");
}
}
if (initDone) {
Engine.logEngine.trace("(MobileBuilder) Ionic module ts file generated for 'app'");
}
}
} catch (Exception e) {
throw new EngineException("Unable to write ionic app module ts file", e);
}
}
use of com.twinsoft.convertigo.beans.mobile.components.Contributor in project convertigo by convertigo.
the class Ionic3Builder 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<>();
// Menus contributors
for (Contributor contributor : app.getContributors()) {
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) {
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)
c8o_ActionTsImports += "import { " + comp + " } from '" + action_ts_imports.get(comp) + "';" + 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/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(ionicWorkDir, "src/services/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);
}
}
Aggregations