Skip to content

Commit db11f85

Browse files
committed
feat: Initial Release
1 parent 53cf9cb commit db11f85

File tree

6 files changed

+159
-105
lines changed

6 files changed

+159
-105
lines changed

.github/workflows/automation.yml

+13-14
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ name: CI
33
on:
44
push:
55
branches:
6-
- master
6+
- master
77
pull_request:
88
branches:
9-
- master
9+
- master
1010
create:
1111
branches:
12-
- master
12+
- master
1313

1414
jobs:
15-
updateKeyword:
15+
about:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Checkout
1919
uses: actions/checkout@v2
20-
20+
2121
- name: Jaid/action-sync-node-meta
2222
uses: jaid/[email protected]
2323
with:
2424
direction: overwrite-github # default is overwrite-file
2525
githubToken: ${{ secrets.GITHUB }}
26-
27-
ci:
26+
27+
release:
2828
runs-on: ubuntu-latest
2929
steps:
3030
- name: Checkout
@@ -41,27 +41,26 @@ jobs:
4141
@semantic-release/github
4242
env:
4343
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} # Auto Changog generator
45-
44+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} # Auto Changog generator
45+
4646
docs:
4747
runs-on: ubuntu-latest
4848
steps:
4949
- name: Checkout
5050
uses: actions/checkout@v2
51-
51+
5252
- name: update documentation
5353
uses: CoCreate-app/CoCreate-docs@master
54-
55-
54+
5655
cdn:
5756
runs-on: ubuntu-latest
5857
steps:
5958
- name: Checkout
6059
uses: actions/checkout@v2
61-
60+
6261
- name: upload cdn
6362
uses: CoCreate-app/CoCreate-s3@master
6463
with:
6564
aws-key-id: ${{ secrets.AWSACCESSKEYID }}
6665
aws-access-key: ${{ secrets.AWSSECERTACCESSKEY }}
67-
source: './dist/CoCreate-render.min.js'
66+
source: "./dist/CoCreate-render.min.js"

dist/CoCreate-render.js

+8-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/CoCreate-render.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+37-18
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,29 @@
22
"name": "@cocreate/render",
33
"version": "1.0.0",
44
"description": "A simple render component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5-
"keywords": ["render","cocreate","low-code-framework","no-code-framework","cocreatejs","cocreatejs-component","cocreate-framework","no-code","low-code","collaborative-framework","realtime","realtime-framework","collaboration","shared-editing","html5-framework","javascript-framework"],
6-
"publishConfig": {
7-
"access": "public"
8-
},
5+
"keywords": [
6+
"render",
7+
"cocreate",
8+
"low-code-framework",
9+
"no-code-framework",
10+
"cocreatejs",
11+
"cocreatejs-component",
12+
"cocreate-framework",
13+
"no-code",
14+
"low-code",
15+
"collaborative-framework",
16+
"realtime",
17+
"realtime-framework",
18+
"collaboration",
19+
"shared-editing",
20+
"html5-framework",
21+
"javascript-framework"
22+
],
23+
"publishConfig": { "access": "public" },
924
"scripts": {
10-
"start": "npx webpack --config webpack.config.js --watch",
25+
"start": "npx webpack --config webpack.config.js",
1126
"build": "NODE_ENV=production npx webpack --config webpack.config.js",
27+
"dev": "npx webpack --config webpack.config.js --watch",
1228
"docs": "node ./node_modules/@cocreate/docs/src/index.js"
1329
},
1430
"repository": {
@@ -17,23 +33,26 @@
1733
},
1834
"author": "CoCreate LLC",
1935
"license": "MIT",
20-
"bugs": {
21-
"url": "https://github.com/CoCreate-app/CoCreate-render/issues"
22-
},
36+
"bugs": { "url": "https://github.com/CoCreate-app/CoCreate-render/issues" },
2337
"homepage": "https://cocreate.app/docs/render",
38+
"funding": {
39+
"type": "GitHub Sponsors ❤",
40+
"url": "https://github.com/sponsors/CoCreate-app"
41+
},
42+
"main": "./src/index.js",
2443
"devDependencies": {
25-
"@babel/core": "^7.12.10",
26-
"@babel/preset-env": "^7.12.11",
27-
"babel-loader": "^8.2.2",
44+
"@babel/core": "^7.9.6",
45+
"@babel/preset-env": "^7.9.6",
46+
"babel-loader": "^8.1.0",
2847
"clean-webpack-plugin": "^3.0.0",
2948
"html-webpack-plugin": "^4.5.0",
3049
"uglifyjs-webpack-plugin": "^2.2.0",
31-
"webpack": "^5.14.0",
32-
"webpack-cli": "^4.3.1",
33-
"webpack-log": "^3.0.1"
50+
"webpack": "^5.24.4",
51+
"webpack-cli": "^4.5.0",
52+
"webpack-log": "^3.0.1",
53+
"file-loader": "^6.2.0",
54+
"style-loader": "^2.0.0",
55+
"terser-webpack-plugin": "^5.1.1"
3456
},
35-
36-
"dependencies": {
37-
"@cocreate/docs": "^1.0.3"
38-
}
57+
"dependencies": { "@cocreate/docs": "^1.0.3" }
3958
}

src/CoCreate-render.js src/index.js

+34-12
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ const CoCreateRender = {
4848
}
4949
},
5050

51+
__replaceValue: function(data, inputValue) {
52+
let isPass = false;
53+
let self = this;
54+
let resultValue = null;
55+
// let variables = inputValue.match(/{{\s*(\S+)\s*}}/g);
56+
let variables = inputValue.match(/{{([A-Za-z0-9_.,\- ]*)}}/g);
57+
if (variables) {
58+
variables.forEach((attr) => {
59+
let value = self.__getValue(data, attr)
60+
if (value && typeof(value) !== "object") {
61+
isPass = true;
62+
inputValue = inputValue.replace(attr, value);
63+
}
64+
})
65+
66+
if (isPass) {
67+
resultValue = inputValue;
68+
}
69+
}
70+
return resultValue;
71+
},
72+
5173
setArray: function(template, data) {
5274
const type = template.getAttribute('data-render_array') || "data";
5375
const render_key = template.getAttribute('data-render_key') || type;
@@ -85,19 +107,9 @@ const CoCreateRender = {
85107
let attr_name = attr.name.toLowerCase();
86108
let isPass = false;
87109
let attrValue = attr.value;
88-
let variables = attrValue.match(/{{\s*(\S+)\s*}}/g);
89-
if (!variables) {
90-
return;
91-
}
110+
attrValue = that.__replaceValue(data, attrValue);
92111

93-
variables.forEach((attr) => {
94-
let value = that.__getValue(data, attr)
95-
if (value && typeof(value) !== "object") {
96-
isPass = true;
97-
attrValue = attrValue.replace(attr, value);
98-
}
99-
})
100-
if (isPass) {
112+
if (attrValue) {
101113
if(attr_name == 'value'){
102114
let tag = e.tagName.toLowerCase();
103115
switch (tag) {
@@ -118,6 +130,16 @@ const CoCreateRender = {
118130
}
119131
});
120132

133+
if (e.children.length == 0 && e.textContent) {
134+
let textContent = e.textContent;
135+
textContent = that.__replaceValue(data, textContent);
136+
if (textContent) {
137+
e.textContent = textContent;
138+
}
139+
}
140+
141+
142+
121143
if(e.children.length > 0) {
122144
that.setValue(e.children, data)
123145

webpack.config.js

+66-30
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,85 @@
1-
const path = require('path');
2-
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
3-
let isProduction = process.env.NODE_ENV === 'production';
1+
const path = require("path")
2+
const TerserPlugin = require("terser-webpack-plugin")
3+
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
4+
let isProduction = process.env.NODE_ENV === "production"
5+
const { CleanWebpackPlugin } = require("clean-webpack-plugin")
46

57
module.exports = {
68
entry: {
7-
'CoCreate-render': './src/CoCreate-render.js'
9+
"CoCreate-render": "./src/index.js",
810
},
911
output: {
10-
path: path.resolve(__dirname, 'dist'),
11-
filename: isProduction ? '[name].min.js' : '[name].js',
12-
libraryTarget: 'umd',
13-
libraryExport: 'default',
14-
library: ['CoCreate', 'render'],
15-
globalObject: "this"
12+
path: path.resolve(__dirname, "dist"),
13+
filename: isProduction ? "[name].min.js" : "[name].js",
14+
libraryTarget: "umd",
15+
libraryExport: "default",
16+
library: ["CoCreate", "render"],
17+
globalObject: "this",
18+
// publicPath: 'https://server.cocreate.app/CoCreateJS/dist/'
1619
},
20+
21+
plugins: [
22+
new CleanWebpackPlugin(),
23+
new MiniCssExtractPlugin({
24+
filename: "[name].css",
25+
}),
26+
],
1727
// Default mode for Webpack is production.
1828
// Depending on mode Webpack will apply different things
1929
// on final bundle. For now we don't need production's JavaScript
2030
// minifying and other thing so let's set mode to development
21-
mode: isProduction ? 'production' : 'development',
31+
mode: isProduction ? "production" : "development",
2232
module: {
23-
rules: [{
24-
test: /\.js$/,
25-
exclude: /(node_modules)/,
26-
use: {
27-
loader: 'babel-loader',
28-
options: {
29-
presets: ['@babel/preset-env'],
30-
plugins: ["@babel/plugin-transform-runtime", "@babel/plugin-transform-regenerator"]
31-
32-
}
33-
}
34-
}, ]
33+
rules: [
34+
{
35+
test: /.js$/,
36+
exclude: /(node_modules)/,
37+
use: {
38+
loader: "babel-loader",
39+
options: {
40+
plugins: ["@babel/plugin-transform-modules-commonjs"],
41+
},
42+
},
43+
},
44+
{
45+
test: /.css$/i,
46+
use: [
47+
{ loader: "style-loader", options: { injectType: "linkTag" } },
48+
"file-loader",
49+
],
50+
},
51+
],
3552
},
3653

3754
// add source map
38-
...(isProduction ? {} : { devtool: 'eval-source-map' }),
55+
...(isProduction ? {} : { devtool: "eval-source-map" }),
3956

40-
// add uglifyJs
4157
optimization: {
42-
minimizer: [new UglifyJsPlugin({
43-
uglifyOptions: {
44-
// get options: https://github.com/mishoo/UglifyJS
45-
drop_console: isProduction
58+
minimize: true,
59+
minimizer: [
60+
new TerserPlugin({
61+
extractComments: true,
62+
// cache: true,
63+
parallel: true,
64+
// sourceMap: true, // Must be set to true if using source-maps in production
65+
terserOptions: {
66+
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
67+
// extractComments: 'all',
68+
compress: {
69+
drop_console: true,
70+
},
71+
},
72+
}),
73+
],
74+
splitChunks: {
75+
chunks: "all",
76+
minSize: 200,
77+
// maxSize: 99999,
78+
//minChunks: 1,
79+
80+
cacheGroups: {
81+
defaultVendors: false,
4682
},
47-
})],
83+
},
4884
},
4985
}

0 commit comments

Comments
 (0)