olum-compiler 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/index.js CHANGED
@@ -3,6 +3,9 @@ const path = require("path");
3
3
  const spawn = require("../lib/cross-spawn");
4
4
  const script = process.argv[2];
5
5
 
6
+ if (script == "dev") process.env.NODE_ENV = "development";
7
+ else if (script == "build") process.env.NODE_ENV = "production";
8
+
6
9
  if (typeof script !== undefined && ["dev", "build"].includes(script)) {
7
10
  const result = spawn.sync("node", [path.resolve(__dirname, script + ".js")], { stdio: "inherit" });
8
11
 
package/lib/helpers.js CHANGED
@@ -713,6 +713,17 @@ const routerParamsParser = `<script>
713
713
  }
714
714
  </script>`;
715
715
 
716
+ const libsMap = {
717
+ development: {
718
+ olum: "/node_modules/olum/dist/olum.js",
719
+ router: "/node_modules/olum-router/dist/router.js"
720
+ },
721
+ production: {
722
+ olum: "olum",
723
+ router: "olum-router"
724
+ }
725
+ }
726
+
716
727
  module.exports.isNum = isNum;
717
728
  module.exports.id = id;
718
729
  module.exports.isUpper = isUpper;
@@ -739,3 +750,4 @@ module.exports.generateRouteManifest = generateRouteManifest;
739
750
  module.exports.generateImports = generateImports;
740
751
  module.exports.generateRoutes = generateRoutes;
741
752
  module.exports.routerParamsParser = routerParamsParser;
753
+ module.exports.libsMap = libsMap;
package/lib/jsParser.js CHANGED
@@ -22,6 +22,7 @@ function jsParser(str) {
22
22
 
23
23
  content = content.replace(/(<script.*>)/, "");
24
24
  content = content.replace(/(<\/script>)$/, "");
25
+ content = content.replace(/onMount\(/, "var mounted = onMount("); // handle onMount hook if imported -- wrape it to another name (mounted) to continue the old flow
25
26
  // content = content.replace(exportDefault, "").trim();
26
27
  // return "__isInitial__: true,\n__render__(obj, prop) { olum.lifeCycle.render(obj, prop); },\n" + content;
27
28
  content = content.replace(/const state/g, "var state"); // todo make this solid
package/lib/parser.js CHANGED
@@ -5,7 +5,7 @@ const jsParser = require("./jsParser");
5
5
  const getImports = require("./getImports");
6
6
  const toJs = require("./toJs");
7
7
  const path = require("path");
8
- const { isFullArr, id, createScopeHandler, getGlobalMethods, getGlobalProps, minifyJS } = require("./helpers");
8
+ const { isFullArr, id, createScopeHandler, getGlobalMethods, getGlobalProps, minifyJS, libsMap } = require("./helpers");
9
9
  const createSourceMap = require("./sourcemap");
10
10
 
11
11
  const parser = (str, counter, filePath) => {
@@ -27,6 +27,14 @@ const parser = (str, counter, filePath) => {
27
27
  if (imports) {
28
28
  const importRegex = /(import)(\s+)?(?!from)/g;
29
29
  imports.forEach((item) => {
30
+ // resolve imported libs: olum, olum-router
31
+ if (/from\s+(['"])olum\1/.test(item.statement)) {
32
+ item.statement = item.statement.replace(new RegExp(item.regex, ""), `from "${libsMap[process.env.NODE_ENV].olum}"`)
33
+ }
34
+ if (/from\s+(['"])olum-router\1/.test(item.statement)) {
35
+ item.statement = item.statement.replace(new RegExp(item.regex, ""), `from "${libsMap[process.env.NODE_ENV].olum}"`)
36
+ }
37
+
30
38
  if (item.type && item.type == "noFrom") js = js.replace(new RegExp(item.regex, "gm"), "");
31
39
  if (!item.type) js = js.replace(new RegExp(item.regex, "g"), "*/");
32
40
  });
@@ -54,8 +62,8 @@ const parser = (str, counter, filePath) => {
54
62
  let hasMounted = false;
55
63
  let hasUnMounted = false;
56
64
 
57
- const methodsTobeExcluded = ["mounted", "unMounted"];
58
- const propsTobeExcluded = ["watcher"];
65
+ const methodsTobeExcluded = ["mounted", "unMounted", "onMount"];
66
+ const propsTobeExcluded = ["watcher", "mounted"];
59
67
 
60
68
  globalProps = getGlobalProps(js);
61
69
  globalMethods = getGlobalMethods(js);
@@ -158,8 +166,8 @@ const parser = (str, counter, filePath) => {
158
166
  incomingPropsProxy: props,
159
167
  ${isDev ? `stateProps: ${hasState ? "state" : "null"},` : ""}
160
168
  hooks: {
161
- mounted: ${hasMounted ? "mounted" : "null"},
162
- unMounted: ${hasUnMounted ? "unMounted" : "null"},
169
+ mounted: typeof mounted !== "undefined" ? mounted : null,
170
+ unMounted: null,
163
171
  isMounted: false,
164
172
  isUnMounted: false,
165
173
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "olum-compiler",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "A module for compiling/bundling olumjs projects",
5
5
  "main": "bin/index.js",
6
6
  "bin": {