olum-compiler 0.2.2 → 0.2.6

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
@@ -18,7 +18,7 @@ process.on("unhandledRejection", err => {
18
18
  const requiredNodeMajorVer = +require("../package.json").engines.node.replace(/\<|\>|\=/gi,"").split(".")[0];
19
19
  const currentNodeMajorVer = +process.version.replace(/v/gi, "").split(".")[0];
20
20
  if (currentNodeMajorVer < requiredNodeMajorVer) {
21
- console.error(`\nYour node version is "${currentNodeMajorVer}" which is not compatible with 'olum-compiler', Please upgrade to "${requiredNodeMajorVer}"\n`);
21
+ console.error(`\nYour node version is "${currentNodeMajorVer}" which is not compatible with 'olum-compiler', Please upgrade to "${requiredNodeMajorVer}" or higher\n`);
22
22
  process.exit(1);
23
23
  }
24
24
 
package/compiler.js CHANGED
@@ -365,12 +365,12 @@ class Compiler {
365
365
  if (isFullArr(modulesNames) && isFullArr(componentsNames)) { // there are components
366
366
  debugLib("components exist");
367
367
  const finalNames = [];
368
- modulesNames.forEach(moduleName => componentsNames.forEach(compName => (moduleName !== "" && moduleName === compName) ? finalNames.push(moduleName) : null));
368
+ modulesNames.forEach(moduleName => componentsNames.forEach(compName => (moduleName !== "" && moduleName === compName) ? finalNames.push("{"+moduleName+"}") : null));
369
369
  dataMethod = `
370
370
  olumCompData() {
371
371
  return {
372
372
  name: "${className}",
373
- components: { ${finalNames.join(", ")} },
373
+ components: [ ${finalNames.join(", ")} ],
374
374
  template: this.template(),
375
375
  style: this.style(),
376
376
  render: this.render.bind(this),
@@ -383,7 +383,7 @@ class Compiler {
383
383
  olumCompData() {
384
384
  return {
385
385
  name: "${className}",
386
- components: {},
386
+ components: [],
387
387
  template: this.template(),
388
388
  style: this.style(),
389
389
  render: this.render.bind(this),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "olum-compiler",
3
- "version": "0.2.2",
3
+ "version": "0.2.6",
4
4
  "description": "A module for compiling/bundling olumjs projects",
5
5
  "main": "bin/index.js",
6
6
  "bin": {
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "homepage": "https://github.com/olumjs/olum-compiler#readme",
24
24
  "engines": {
25
- "node": ">=10"
25
+ "node": ">=14"
26
26
  },
27
27
  "dependencies": {
28
28
  "cross-spawn": "^7.0.3",
@@ -56,7 +56,8 @@
56
56
  "webpack-cli": "^4.5.0",
57
57
  "webpack-pwa-manifest": "^4.3.0",
58
58
  "workbox-webpack-plugin": "^6.1.5",
59
- "olum-devtool": "latest"
59
+ "olum-devtool": "latest",
60
+ "string-replace-loader": "^3.0.3"
60
61
  },
61
62
  "browserslist": [
62
63
  "last 2 version",
package/webpack.config.js CHANGED
@@ -15,20 +15,49 @@ const WorkboxPlugin = require("workbox-webpack-plugin");
15
15
  const WebpackPwaManifest = require("webpack-pwa-manifest");
16
16
  const CopyPlugin = require("copy-webpack-plugin");
17
17
  const { title, favicon, template, hash, comments, polyfill, assetAsModule, serviceWorker, manifest } = require("../../package.json").olum;
18
+ const olumVer = require("olum/package.json").version;
19
+ const isObj = obj => !!(obj !== null && typeof obj === "object");
20
+ const isFullArr = arr => !!(isObj(arr) && Array.isArray(arr) && arr.length);
18
21
 
19
- module.exports = env => {
22
+ function getSelector() {
23
+ return new Promise((resolve, reject) => {
24
+ const commentsRegex = /(\/\*)([\s\S]*?)(\*\/)|(\/\/.*)/gi;
25
+ const olumRegex = /(\/*|\/\/)=?.*(new Olum)[\s\S]*?\.\$\((\'|\")(.*)(\'|\")\)[\s\S]*?(\.use\()/gi;
26
+ const file = path.resolve(__dirname, "./src/index.js");
27
+ if (fs.existsSync(file)) {
28
+ fs.readFile(file, "utf8", (err, data) => {
29
+ if (err) return reject(err);
30
+ data = data.replace(commentsRegex, ""); // clean code from inline/block comments
31
+ const instanceArr = data.match(olumRegex);
32
+ if (isFullArr(instanceArr)) {
33
+ const validOlumInstance = instanceArr.reverse().find(item => !item.trim().startsWith("/"));
34
+ validOlumInstance.replace(olumRegex, ($1, $2, $3, $4, $5, $6) => {
35
+ const selector = $5;
36
+ resolve(selector);
37
+ });
38
+ } else resolve();
39
+ });
40
+ }
41
+ });
42
+ }
43
+
44
+ const initConfig = (env, selector = "{{olumSelector}}") => {
20
45
  if (!fs.existsSync(path.resolve(__dirname, "./src/index.js")) || !fs.existsSync(path.resolve(__dirname, "./src/index.scss"))) {
21
46
  console.log("Make sure to have index.js & index.scss in src directory instead of app.js & app.scss");
22
47
  }
23
-
48
+
24
49
  const mode = !!env.dev ? "development" : "production";
25
50
  const globs = [path.resolve(__dirname, "./src/index.scss"), path.resolve(__dirname, "./src/index.js")];
26
51
  // add devtool if it exists
27
52
  const devtoolExists = fs.existsSync(path.resolve(__dirname, "../olum-devtool"));
28
- if (mode === "development" && devtoolExists) globs.push(path.resolve(__dirname, "../olum-devtool"));
53
+ const devtoolStyleExists = fs.existsSync(path.resolve(__dirname, "../olum-devtool/dist/olum-devtool.scss"));
54
+ if (mode === "development" && devtoolExists && devtoolStyleExists) {
55
+ globs.push(path.resolve(__dirname, "../olum-devtool"));
56
+ globs.push(path.resolve(__dirname, "../olum-devtool/dist/olum-devtool.scss"));
57
+ }
29
58
  const main = polyfill ? ["babel-polyfill", ...globs] : [...globs];
30
59
 
31
- const config = {
60
+ const configObj = {
32
61
  stats: "errors-warnings",
33
62
  mode,
34
63
  entry: { main },
@@ -44,7 +73,7 @@ module.exports = env => {
44
73
  if (contextRegex.test(resource.context) && resource.request.toLowerCase().endsWith(".html")) {
45
74
  resource.request = resource.request.substr(0, resource.request.length - 5) + ".js";
46
75
  }
47
- })
76
+ }),
48
77
  ],
49
78
  module: {
50
79
  rules: [
@@ -55,6 +84,22 @@ module.exports = env => {
55
84
  loader: "babel-loader",
56
85
  },
57
86
  },
87
+ {
88
+ test: /olum-devtool\.js$/,
89
+ loader: "string-replace-loader",
90
+ options: {
91
+ multiple: [
92
+ {
93
+ search: /\{\{olumSelector\}\}/g,
94
+ replace: selector,
95
+ },
96
+ {
97
+ search: /\{\{olumVer\}\}/g,
98
+ replace: olumVer,
99
+ },
100
+ ],
101
+ },
102
+ },
58
103
  {
59
104
  test: /\.(?:scss|sass|css)$/i,
60
105
  use: ["style-loader", "css-loader", "sass-loader"],
@@ -69,24 +114,39 @@ module.exports = env => {
69
114
  test: /\.(?:ico|gif|png|jpg|jpeg|svg|webp|tif|tiff|jfif|pjpeg|pjp|apng|avif|bmp|cur|m4awebm|mpg|mp2|mpeg|mpe|mpv|mp4|m4p|m4v|avi|wmv|mov|qt|flv|swf|avchd|wav|mp3|aac|ogg|woff|woff2|ttf|eot)$/i,
70
115
  type: "asset/resource",
71
116
  };
72
- config.module.rules.push(obj);
117
+ configObj.module.rules.push(obj);
73
118
  } else {
74
- config.plugins.push(new CopyPlugin({ patterns: [{ from: "./src/assets", to: path.resolve(__dirname, `build/assets`) }] }));
119
+ configObj.plugins.push(new CopyPlugin({ patterns: [{ from: "./src/assets", to: path.resolve(__dirname, `build/assets`) }] }));
75
120
  }
76
121
 
77
122
  if (mode === "development") {
78
123
  const clean = new CleanWebpackPlugin({ cleanAfterEveryBuildPatterns: [`./build/**/*`] });
79
- config.plugins.unshift(clean);
80
- config.devtool = "eval-source-map";
124
+ configObj.plugins.unshift(clean);
125
+ configObj.devtool = "eval-source-map";
81
126
  }
82
127
 
83
128
  if (mode === "production") {
84
- config.optimization = { minimize: true, minimizer: [new TerserPlugin({ extractComments: comments })] };
129
+ configObj.optimization = {
130
+ minimize: true,
131
+ minimizer: [new TerserPlugin({ extractComments: comments })],
132
+ };
85
133
  if (serviceWorker) {
86
- config.plugins.push(new WorkboxPlugin.GenerateSW({ clientsClaim: true, skipWaiting: true }));
87
- config.plugins.push(new WebpackPwaManifest(manifest));
134
+ configObj.plugins.push(new WorkboxPlugin.GenerateSW({ clientsClaim: true, skipWaiting: true }));
135
+ configObj.plugins.push(new WebpackPwaManifest(manifest));
88
136
  }
89
137
  }
90
138
 
91
- return config;
139
+ return configObj;
92
140
  };
141
+
142
+ const config = env => {
143
+ return getSelector()
144
+ .then(selector => selector)
145
+ .then(selector => initConfig(env, selector))
146
+ .catch(err => {
147
+ console.log(err);
148
+ initConfig(env);
149
+ });
150
+ };
151
+
152
+ module.exports = config;