@agung_dhewe/webapps 1.2.3 → 1.2.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agung_dhewe/webapps",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "library javascript (nodejs+express) untuk pengembangan applikasi web",
5
5
  "type": "module",
6
6
  "main": "./src/webapps.js",
@@ -23,9 +23,6 @@ export async function createTable(context, options) {
23
23
  return
24
24
  }
25
25
 
26
- console.log(context.entities)
27
-
28
-
29
26
 
30
27
  // start geneate program code
31
28
  let sections = []
@@ -0,0 +1,90 @@
1
+ /************************************************************************
2
+ * minimize script using rollup
3
+ *
4
+ * you need to install rollup & terser to use this tools
5
+ *
6
+ * usage:
7
+ * npx rollup -c ./public/modules/<%=moduleName%>/__rollup.<%=moduleName%>.js
8
+ *
9
+ * This module is generated by fgta5 generator
10
+ ************************************************************************/
11
+
12
+
13
+ import terser from '@rollup/plugin-terser';
14
+ import { writeFileSync } from 'fs';
15
+ import { readFile, unlink, access } from 'fs/promises';
16
+ import { join } from 'path';
17
+ import { constants } from 'fs';
18
+
19
+ const currentdate = (new Date()).toISOString().split('T')[0]
20
+ const banner = `<%=moduleName%>
21
+ *
22
+ * build at ${currentdate}
23
+ `
24
+
25
+ const filename = `version.txt`;
26
+ const filepath = join('public/modules/<%=moduleName%>', filename);
27
+
28
+ /* Hapus versi sebelumnya */
29
+ if (await isExists(filepath)) {
30
+ const previousVersionNumber = await readFile(filepath, 'utf8');
31
+ const previousFile = `public/modules/<%=moduleName%>/<%=moduleName%>-${previousVersionNumber}.min.mjs`
32
+ await unlink(previousFile);
33
+ }
34
+
35
+ /* Create New Version */
36
+ const newVersionNumber = getTimestampYYMMDDHHII()
37
+
38
+
39
+ // Simpan ke file
40
+ writeFileSync(filepath, newVersionNumber, 'utf8')
41
+
42
+
43
+ export default {
44
+ input: "public/modules/<%=moduleName%>/<%=moduleName%>.mjs", // File utama yang menjadi entry point
45
+ output: {
46
+ file: `public/modules/<%=moduleName%>/<%=moduleName%>-${newVersionNumber}.min.mjs`, // Lokasi output file hasil bundle
47
+ format: "esm", // Format modul ECMAScript
48
+ banner: `/*! ${banner}*/`,
49
+ // manualChunks: (id) => {
50
+ // console.log('Chunking:', id);
51
+ // if (id.includes('module.mjs') || id.includes('-ext.mjs') || id.includes('public/libs/webmodule')) return null;
52
+ // }
53
+ },
54
+ external: (id) => {
55
+ return id.includes('module.mjs') || id === '$fgta5' || id.includes('public/libs/webmodule');
56
+ },
57
+
58
+ preserveEntrySignatures: 'strict',
59
+
60
+ plugins: [
61
+ terser({
62
+ compress: {
63
+ pure_funcs: ['console.log', 'console.warn'] // hanya log dan warn dihilangkan, sedangkan error tidak
64
+ // drop_console: true // hapus console
65
+ }
66
+ })
67
+ ]
68
+ }
69
+
70
+
71
+ function getTimestampYYMMDDHHII() {
72
+ const now = new Date();
73
+ const yy = String(now.getFullYear()).slice(-2);
74
+ const mm = String(now.getMonth() + 1).padStart(2, '0');
75
+ const dd = String(now.getDate()).padStart(2, '0');
76
+ const hh = String(now.getHours()).padStart(2, '0');
77
+ const ii = String(now.getMinutes()).padStart(2, '0');
78
+ return `${yy}${mm}${dd}${hh}${ii}`;
79
+ };
80
+
81
+
82
+ async function isExists(filepath) {
83
+ try {
84
+ await access(filepath, constants.F_OK);
85
+ return true
86
+ } catch {
87
+ return false
88
+ }
89
+
90
+ }
@@ -11,61 +11,108 @@
11
11
 
12
12
 
13
13
  import terser from '@rollup/plugin-terser';
14
+ import postcss from 'rollup-plugin-postcss';
15
+ import cssnano from 'cssnano';
16
+ import atImport from 'postcss-import';
17
+ import del from 'rollup-plugin-delete';
18
+
14
19
  import { writeFileSync } from 'fs';
15
20
  import { readFile, unlink, access } from 'fs/promises';
16
21
  import { join } from 'path';
17
22
  import { constants } from 'fs';
18
23
 
24
+
25
+ const moduleName = '<%=moduleName%>'
26
+ const moduleDirPath = `public/modules/${moduleName}`
27
+ const filename = `version.txt`;
28
+ const filepath = join(moduleDirPath, filename);
29
+
19
30
  const currentdate = (new Date()).toISOString().split('T')[0]
20
- const banner = `<%=moduleName%>
31
+ const banner = `${moduleName}
21
32
  *
22
33
  * build at ${currentdate}
23
34
  `
24
35
 
25
- const filename = `version.txt`;
26
- const filepath = join('public/modules/<%=moduleName%>', filename);
36
+
27
37
 
28
38
  /* Hapus versi sebelumnya */
29
39
  if (await isExists(filepath)) {
30
40
  const previousVersionNumber = await readFile(filepath, 'utf8');
31
- const previousFile = `public/modules/<%=moduleName%>/<%=moduleName%>-${previousVersionNumber}.min.mjs`
32
- await unlink(previousFile);
41
+ const previousMjsFile = join(moduleDirPath, `${moduleName}-${previousVersionNumber}.min.mjs`)
42
+ const previousCssFile = join(moduleDirPath, `${moduleName}-${previousVersionNumber}.min.css`)
43
+
44
+ await Promise.all([
45
+ remove(previousMjsFile),
46
+ remove(previousCssFile)
47
+ ])
33
48
  }
34
49
 
50
+ const cssFiles = await getCssFiles()
51
+
52
+
35
53
  /* Create New Version */
36
54
  const newVersionNumber = getTimestampYYMMDDHHII()
37
55
 
38
56
 
57
+
39
58
  // Simpan ke file
40
59
  writeFileSync(filepath, newVersionNumber, 'utf8')
41
60
 
42
61
 
43
- export default {
44
- input: "public/modules/<%=moduleName%>/<%=moduleName%>.mjs", // File utama yang menjadi entry point
45
- output: {
46
- file: `public/modules/<%=moduleName%>/<%=moduleName%>-${newVersionNumber}.min.mjs`, // Lokasi output file hasil bundle
47
- format: "esm", // Format modul ECMAScript
48
- banner: `/*! ${banner}*/`,
49
- // manualChunks: (id) => {
50
- // console.log('Chunking:', id);
51
- // if (id.includes('module.mjs') || id.includes('-ext.mjs') || id.includes('public/libs/webmodule')) return null;
52
- // }
53
- },
54
- external: (id) => {
55
- return id.includes('module.mjs') || id === '$fgta5' || id.includes('public/libs/webmodule');
62
+ export default [
63
+ {
64
+ input: join(moduleDirPath, `${moduleName}.mjs`), // File utama yang menjadi entry point
65
+ output: {
66
+ file: join(moduleDirPath, `${moduleName}-${newVersionNumber}.min.mjs`), // Lokasi output file hasil bundle
67
+ format: "esm", // Format modul ECMAScript
68
+ banner: `/*! ${banner}*/`,
69
+ },
70
+ external: (id) => {
71
+ return id.includes('module.mjs') || id === '$fgta5' || id.includes('public/libs/webmodule');
72
+ },
73
+
74
+ preserveEntrySignatures: 'strict',
75
+
76
+ plugins: [
77
+ terser({
78
+ compress: {
79
+ pure_funcs: ['console.log', 'console.warn'] // hanya log dan warn dihilangkan, sedangkan error tidak
80
+ // drop_console: true // hapus console
81
+ }
82
+ })
83
+ ]
56
84
  },
57
-
58
- preserveEntrySignatures: 'strict',
59
-
60
- plugins: [
61
- terser({
62
- compress: {
63
- pure_funcs: ['console.log', 'console.warn'] // hanya log dan warn dihilangkan, sedangkan error tidak
64
- // drop_console: true // hapus console
65
- }
66
- })
67
- ]
68
- }
85
+
86
+ {
87
+ input: cssFiles,
88
+ output: {
89
+ dir: moduleDirPath
90
+ },
91
+ plugins: [
92
+
93
+ // Konfigurasi PostCSS untuk CSS
94
+ postcss({
95
+ extract: `${moduleName}-${newVersionNumber}.min.css`, // Nama file output CSS
96
+ minimize: true, // Aktifkan minifikasi
97
+ plugins: [
98
+ atImport(), // 1. Gabungkan semua @import menjadi satu file
99
+ cssnano() // Plugin untuk optimasi CSS
100
+ ]
101
+ }),
102
+ del({
103
+ targets: [
104
+ join(moduleDirPath, `${moduleName}.js`),
105
+ join(moduleDirPath, `${moduleName}.layout.js`),
106
+ ],
107
+ hook: 'closeBundle' // Jalankan setelah semua proses selesai
108
+ })
109
+ ]
110
+ }
111
+
112
+ ]
113
+
114
+
115
+
69
116
 
70
117
 
71
118
  function getTimestampYYMMDDHHII() {
@@ -79,6 +126,30 @@ function getTimestampYYMMDDHHII() {
79
126
  };
80
127
 
81
128
 
129
+ async function remove(filepath) {
130
+ if (await isExists(filepath)) {
131
+ await unlink(filepath)
132
+ }
133
+ }
134
+
135
+
136
+ async function getCssFiles() {
137
+ const cssFiles = []
138
+ const cssMainFile = join(moduleDirPath, `${moduleName}.css`)
139
+ const cssLayoutFile = join(moduleDirPath, `${moduleName}.layout.css`)
140
+
141
+ if (await isExists(cssMainFile)) {
142
+ cssFiles.push(cssMainFile)
143
+ }
144
+
145
+ if (await isExists(cssLayoutFile)) {
146
+ cssFiles.push(cssLayoutFile)
147
+ }
148
+
149
+ return cssFiles;
150
+ }
151
+
152
+
82
153
  async function isExists(filepath) {
83
154
  try {
84
155
  await access(filepath, constants.F_OK);
@@ -33,22 +33,30 @@ export async function modulePage(req, res) {
33
33
 
34
34
 
35
35
  // const mjsFileName = appDebugMode ? `${moduleName}.mjs` : `${moduleName}.min.mjs`
36
+ let useCssBundle
37
+ let cssBundleFileName
36
38
  let mjsFileName
37
39
  if (appDebugMode) {
38
40
  // Default Debug
39
41
  if (req.query.mode == 'release') {
40
42
  const version = await getCurrentVersion(path.join(__rootDir, 'public', 'modules', moduleName, 'version.txt'))
41
43
  mjsFileName = `${moduleName}-${version}.min.mjs`
44
+ cssBundleFileName = `${moduleName}-${version}.min.css`
45
+ useCssBundle = true
42
46
  } else {
43
47
  mjsFileName = `${moduleName}.mjs`
48
+ useCssBundle = false
44
49
  }
45
50
  } else {
46
51
  // Default Production
47
52
  if (req.query.mode == 'debug') {
48
53
  mjsFileName = `${moduleName}.mjs`
54
+ useCssBundle = false
49
55
  } else {
50
56
  const version = await getCurrentVersion(path.join(__rootDir, 'public', 'modules', moduleName, 'version.txt'))
51
57
  mjsFileName = `${moduleName}-${version}.min.mjs`
58
+ cssBundleFileName = `${moduleName}-${version}.min.css`
59
+ useCssBundle = true
52
60
  }
53
61
  }
54
62
  const mjsPath = path.join(__rootDir, 'public', 'modules', moduleName, mjsFileName);
@@ -113,7 +121,9 @@ export async function modulePage(req, res) {
113
121
  additionalHeaderExists,
114
122
  cssApplicationPath,
115
123
  cssApplicationExists,
116
- setting: req.app.locals.appConfig
124
+ setting: req.app.locals.appConfig,
125
+ useCssBundle,
126
+ cssBundleFileName,
117
127
  }
118
128
  }
119
129
 
@@ -30,15 +30,17 @@
30
30
  <% } %>
31
31
 
32
32
 
33
- <% if (cssExists) { %>
34
- <link rel="stylesheet" href="public/modules/<%= `${moduleName}/${moduleName}.css` %>" />
35
- <% } %>
36
-
37
- <% if (cssLayoutExists) { %>
38
- <link rel="stylesheet" href="public/modules/<%= `${moduleName}/${moduleName}.layout.css` %>" />
39
- <% } %>
33
+ <% if (useCssBundle) { %>
34
+ <link rel="stylesheet" href="public/modules/<%= `${moduleName}/${cssBundleFileName}` %>" />
35
+ <% } else { %>
36
+ <% if (cssExists) { %>
37
+ <link rel="stylesheet" href="public/modules/<%= `${moduleName}/${moduleName}.css` %>" />
38
+ <% } %>
40
39
 
41
-
40
+ <% if (cssLayoutExists) { %>
41
+ <link rel="stylesheet" href="public/modules/<%= `${moduleName}/${moduleName}.layout.css` %>" />
42
+ <% } %>
43
+ <% } %>
42
44
 
43
45
  <style>
44
46
  #loadingindicator {