@total_onion/onion-library 3.1.0 → 3.2.1

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.
Files changed (42) hide show
  1. package/__spec__/copyBlockComponent.spec.js +4 -4
  2. package/__spec__/copyFile.spec.js +3 -3
  3. package/__spec__/copyFileKeeping.spec.js +3 -3
  4. package/__spec__/update-all-components.spec.js +2 -2
  5. package/__spec__/update-component.spec.js +4 -4
  6. package/assembleAssetList.js +3 -3
  7. package/checkBuildAssets.js +11 -12
  8. package/createDynamicBlockScss-v3.js +4 -4
  9. package/createJsAssets-v3.js +3 -3
  10. package/createJsAssets.js +4 -4
  11. package/createNewBlock.js +13 -13
  12. package/createNewChildBlock2.js +27 -29
  13. package/createPreviewScss.js +8 -8
  14. package/duplicateBlock.js +8 -8
  15. package/exportAllBlocks.js +10 -7
  16. package/exportBlock.js +5 -5
  17. package/exportChildBlock.js +5 -5
  18. package/exportCustomCachesToLibrary.js +18 -15
  19. package/exportEntrypointToLibrary.js +18 -15
  20. package/exportImagesToLibrary.js +14 -14
  21. package/exportSEOExtrasToLibrary.js +18 -15
  22. package/exportToLibrary.js +20 -17
  23. package/importBlock.js +7 -7
  24. package/importChildBlock.js +7 -7
  25. package/index.js +10 -0
  26. package/install-component.js +3 -3
  27. package/list-components.js +1 -1
  28. package/new-block-templates/template-acf-pattern.js +30 -0
  29. package/new-block-templates/template-block-json.js +1 -1
  30. package/new-block-templates/template-default.js +10 -7
  31. package/new-block-templates/template-js-blank.js +2 -2
  32. package/new-block-templates/template-scss-blank.js +2 -2
  33. package/onion-loader.js +22 -14
  34. package/onion-utils.mjs +18 -19
  35. package/package.json +21 -5
  36. package/public/block-cocktail-recipe-v3/cocktail-recipe-v3.js +2 -0
  37. package/public/block-modal-form-v3/modal-form-v3.js +8 -4
  38. package/public/block-video-content-v3/video-content-v3.js +1 -1
  39. package/removeBlock.js +4 -4
  40. package/update-all-components.js +11 -50
  41. package/update-component.js +6 -5
  42. package/update-template.js +6 -5
@@ -1,9 +1,9 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { promisify } = require('util');
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { promisify } from 'node:util';
4
4
 
5
5
  // Import the function to be tested
6
- const updateComponent = require('../update-component');
6
+ import updateComponent from '../update-component.js';
7
7
 
8
8
  // Promisify the fs functions used in the copyBlockComponent function
9
9
  const readdirPromisified = promisify(fs.readdir);
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const fs = require('fs');
4
- const path = require('path');
5
- const updateComponent = require('../update-component');
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import updateComponent from '../update-component.js';
6
6
 
7
7
 
8
8
  describe('copyFile function', () => {
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const fs = require('fs');
4
- // const path = require('path');
5
- const updateComponent = require('../update-component');
3
+ import fs from 'node:fs';
4
+ // import path from 'node:path';
5
+ import updateComponent from '../update-component.js';
6
6
 
7
7
  describe('copyFileKeeping', () => {
8
8
  const sourceFilePath = './__spec__/files/source.txt';
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const glob = require('glob');
3
+ import * as glob from 'glob';
4
4
  const fs = jest.mock('fs');
5
- const updateAllComponents = require('../update-all-components');
5
+ import updateAllComponents from '../update-all-components.js';
6
6
 
7
7
  describe('getComponentsList', () => {
8
8
  afterEach(() => {
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- // const glob = require('glob');
4
- const fs = require('fs');
3
+ // import * as glob from 'glob';
4
+ import fs from 'node:fs';
5
5
  // const fse = require("fs-extra");
6
6
 
7
- // const path = require('path');
8
- const updateComponent = require('../update-component');
7
+ // import path from 'node:path';
8
+ import updateComponent from '../update-component.js';
9
9
 
10
10
  jest.mock('fs');
11
11
 
@@ -1,6 +1,6 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const {globSync} = require('glob');
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import {globSync} from 'glob';
4
4
 
5
5
  const dynamicEntryPointsJs = globSync(`./components/block-*/*-v3.js`).map(
6
6
  (filePath) => {
@@ -1,18 +1,17 @@
1
- /* eslint-disable global-require */
2
- require('dotenv').config();
3
- const fs = require( 'fs' );
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import {fork} from 'node:child_process';
4
+
4
5
  const themePath = process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
5
6
 
6
7
  const paths = {
7
- createJsAssets:
8
- `${themePath}/assets/js/modules/jsAssets.js`,
9
- createPreviewScss:
10
- `${themePath}/assets/scss/modules/dynamicBlocksPreview.scss`,
8
+ createJsAssets: `${themePath}/assets/js/modules/jsAssets.js`,
9
+ createPreviewScss: `${themePath}/assets/scss/modules/dynamicBlocksPreview.scss`,
11
10
  };
12
11
 
13
- Object.keys( paths ).forEach( ( key ) => {
14
- if ( ! fs.existsSync( paths[ key ] ) ) {
15
- console.log( `creating missing assets with ${ key }` );
16
- require( 'child_process' ).fork( `./node_modules/@pernod-ricard-global-cms/jsbuildutils/${ key }.js` );
12
+ Object.keys(paths).forEach((key) => {
13
+ if (!fs.existsSync(paths[key])) {
14
+ console.log(`creating missing assets with ${key}`);
15
+ fork(`./node_modules/@pernod-ricard-global-cms/jsbuildutils/${key}.js`);
17
16
  }
18
- } );
17
+ });
@@ -1,7 +1,7 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const {globSync} = require('glob');
4
- const path = require('path');
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import {globSync} from 'glob';
4
+ import path from 'node:path';
5
5
 
6
6
  const scssModulePath = path.join('./public');
7
7
  const scssFilePath = path.join(scssModulePath, 'dynamicBlockScss-v3.scss');
@@ -1,6 +1,6 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const {globSync} = require('glob');
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import {globSync} from 'glob';
4
4
 
5
5
  const dynamicEntryPoints = globSync(`./components/block-*/*-v{3,4}.js`).map(
6
6
  (filePath) => {
package/createJsAssets.js CHANGED
@@ -1,7 +1,7 @@
1
- require('dotenv').config();
2
- const fs = require( 'fs' );
3
- const path = require( 'path' );
4
- const { globSync } = require( 'glob' );
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import {globSync} from 'glob';
5
5
  const themePath = process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
6
6
 
7
7
  const dynamicEntryPoints = globSync(`${themePath}/assets/js/blocks/*.js`)
package/createNewBlock.js CHANGED
@@ -1,10 +1,10 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const {globSync} = require('glob');
4
- const yargs = require('yargs');
5
- const {exec} = require('child_process');
6
- const acfTemplate = require('./new-block-templates/template-block-json');
7
- const defaultTemplates = require('./new-block-templates/template-default');
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import {globSync} from 'glob';
4
+ import yargs from 'yargs/yargs';
5
+ import {exec} from 'node:child_process';
6
+ import acfTemplate from './new-block-templates/template-block-json.js';
7
+ import defaultTemplates from './new-block-templates/template-default.js';
8
8
 
9
9
  const themePath =
10
10
  process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
@@ -65,12 +65,14 @@ const newBlockName = process.argv[2]?.toLowerCase();
65
65
  const blockType = process.argv[3];
66
66
 
67
67
  if (!newBlockName) {
68
- return console.log('Did you forget to give the new block a name?');
68
+ console.log('Did you forget to give the new block a name?');
69
+ process.exit(1);
69
70
  }
70
71
  if (dynamicEntryPoints.indexOf(newBlockName) !== -1) {
71
- return console.log(
72
+ console.log(
72
73
  `Alas! There is already a block called ${newBlockName} :( You'll have to try something else..`
73
74
  );
75
+ process.exit(1);
74
76
  }
75
77
 
76
78
  const templateData = `
@@ -81,10 +83,8 @@ const templateData = `
81
83
  </section>`;
82
84
 
83
85
  let jsData;
84
- if (swiper) {
85
- jsData = swiperTemplates.templatejs(newBlockName);
86
- } else if (vue) {
87
- jsData = vueTemplates.templatejs(newBlockName);
86
+ if (swiper || vue || image || content) {
87
+ jsData = defaultTemplates.defaultjs(newBlockName);
88
88
  } else {
89
89
  jsData = defaultTemplates.defaultjs(newBlockName);
90
90
  }
@@ -1,15 +1,17 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const {globSync} = require('glob');
4
- const {exec} = require('child_process');
5
- const acfTemplate = require('./new-block-templates/template-acf-pattern');
6
- const acfTemplateScss = require('@total_onion/onion-library/new-block-templates/template-scss-blank');
7
- const acfTemplateJs = require('@total_onion/onion-library/new-block-templates/template-js-blank');
8
- const yaml = require('js-yaml');
9
- const axios = require('axios');
10
-
11
- const themePath =
12
- process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import {globSync} from 'glob';
4
+ import {exec} from 'node:child_process';
5
+ import path from 'node:path';
6
+ import {fileURLToPath} from 'node:url';
7
+ import yaml from 'js-yaml';
8
+ import axios from 'axios';
9
+ import acfTemplate from './new-block-templates/template-acf-pattern.js';
10
+ import acfTemplateScss from './new-block-templates/template-scss-blank.js';
11
+ import acfTemplateJs from './new-block-templates/template-js-blank.js';
12
+
13
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
14
+ const themePath = process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
13
15
 
14
16
  const yamlData = yaml.load(fs.readFileSync('../../../../.lando.yml', 'utf8'));
15
17
  const siteName = yamlData.config.site;
@@ -17,11 +19,11 @@ const parentURL = process.env.DESIGN_MULTIDEV
17
19
  ? `${process.env.DESIGN_MULTIDEV}/wp-admin/admin-ajax.php`
18
20
  : `http://${siteName}.lndo.site/wp-admin/admin-ajax.php`;
19
21
 
20
- const srcPathJs = `${__dirname}/components`;
21
- const srcPathScss = `${__dirname}/components`;
22
+ const srcPathJs = path.join(__dirname, 'components');
23
+ const srcPathScss = path.join(__dirname, 'components');
22
24
 
23
25
  let projectName = 'Global Theme';
24
- const projectJson = JSON.parse(fs.readFileSync('./package.json'));
26
+ const projectJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
25
27
  if (projectJson) {
26
28
  projectName = projectJson.name;
27
29
  if (projectName.slice(0, 3) === 'the') {
@@ -40,8 +42,8 @@ if (projectJson) {
40
42
  }
41
43
 
42
44
  const dynamicEntryPoints = globSync(`${themePath}/assets/js/blocks/*.js`).map(
43
- (path) => {
44
- const assetKey = path
45
+ (filePath) => {
46
+ const assetKey = filePath
45
47
  .replace('assets/js/blocks/', '')
46
48
  .replace('.js', '');
47
49
  return assetKey;
@@ -51,10 +53,12 @@ const newBlockName = process.argv[2]?.toLowerCase();
51
53
  const patternID = process.argv[3];
52
54
 
53
55
  if (!newBlockName) {
54
- return console.log('Did you forget to give the new block a name?');
56
+ console.log('Did you forget to give the new block a name?');
57
+ process.exit(1);
55
58
  }
56
59
  if (!patternID) {
57
- return console.log('Did you forget to supply the pattern ID?');
60
+ console.log('Did you forget to supply the pattern ID?');
61
+ process.exit(1);
58
62
  }
59
63
 
60
64
  fs.writeFileSync(
@@ -64,16 +68,10 @@ fs.writeFileSync(
64
68
 
65
69
  const blockName = 'group-container-v3';
66
70
 
67
- const fullPath = `${srcPathJs}/block-${blockName}/${blockName}.js`;
71
+ const fullPath = path.join(srcPathJs, `block-${blockName}`, `${blockName}.js`);
68
72
 
69
- const jsdir = `Assets/js/blocks/`;
70
- // if (!fs.existsSync(jsdir)) {
71
- // fs.mkdirSync(jsdir, 0o744);
72
- // }
73
- const scssdir = `Assets/scss/blocks/`;
74
- // if (!fs.existsSync(scssdir)) {
75
- // fs.mkdirSync(scssdir, 0o744);
76
- // }
73
+ const jsdir = 'Assets/js/blocks/';
74
+ const scssdir = 'Assets/scss/blocks/';
77
75
 
78
76
  if (!fs.existsSync(`${jsdir}/${newBlockName}.js`)) {
79
77
  fs.writeFileSync(
@@ -91,7 +89,7 @@ if (!fs.existsSync(`${scssdir}/${newBlockName}.scss`)) {
91
89
  console.log(`👑👑\x1b[32m Successfully created the scss file! 👑👑`);
92
90
  }
93
91
 
94
- let data = new FormData();
92
+ const data = new FormData();
95
93
  data.append('action', 'get_pattern_block');
96
94
  data.append('postID', patternID);
97
95
 
@@ -1,9 +1,9 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const {globSync} = require('glob');
4
- const path = require('path');
5
- const themePath =
6
- process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import {globSync} from 'glob';
4
+ import path from 'node:path';
5
+
6
+ const themePath = process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
7
7
 
8
8
  // Create the directory path for the target file
9
9
  const scssModulePath = path.join(themePath, 'assets/scss/modules');
@@ -20,8 +20,8 @@ fs.writeFileSync(
20
20
 
21
21
  const dynamicEntryPoints = globSync(
22
22
  `${themePath}/assets/scss/blocks/*.scss`
23
- ).map((path) => {
24
- const assetPath = path.replace(
23
+ ).map((filePath) => {
24
+ const assetPath = filePath.replace(
25
25
  'assets/scss/blocks/',
26
26
  'Assets/scss/blocks/'
27
27
  );
package/duplicateBlock.js CHANGED
@@ -1,8 +1,8 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const path = require('path');
4
- const {globSync} = require('glob');
5
- const yargs = require('yargs');
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import {globSync} from 'glob';
5
+ import yargs from 'yargs/yargs';
6
6
  const templateOptions = yargs(process.argv.slice(2)).argv._;
7
7
  const themePath =
8
8
  process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
@@ -27,20 +27,20 @@ if (!blockName) {
27
27
  console.log(
28
28
  "\x1b[33m 🤔🤔 Hmmm...You dont't seem to have chosen a block to duplicate. 🤔🤔 \x1b[0m"
29
29
  );
30
- return;
30
+ process.exit(1);
31
31
  }
32
32
  if (!newName) {
33
33
  console.log(
34
34
  '\x1b[33m 🤓🤓 Nearly there! Unfortunately you forgot to choose a new name for your duplicate block. 🤓🤓 \x1b[0m'
35
35
  );
36
- return;
36
+ process.exit(1);
37
37
  }
38
38
 
39
39
  if (blockName === newName) {
40
40
  console.log(
41
41
  '\x1b[33m Oh no! 😱😱😱 Your new block name cannot be the same as the original block name! \x1b[0m'
42
42
  );
43
- return;
43
+ process.exit(1);
44
44
  }
45
45
 
46
46
  if (exisitingBlockNames.includes(blockName)) {
@@ -1,9 +1,12 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const {globSync} = require('glob');
4
- const yargs = require('yargs');
5
- const path = require('path');
6
- const compressing = require('compressing');
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import {globSync} from 'glob';
4
+ import yargs from 'yargs/yargs';
5
+ import path from 'node:path';
6
+ import {fileURLToPath} from 'node:url';
7
+ import compressing from 'compressing';
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
10
  const templateOptions = yargs(process.argv.slice(2)).argv._;
8
11
  const themePath =
9
12
  process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
@@ -24,7 +27,7 @@ try {
24
27
  blocks = JSON.parse(fs.readFileSync(component_list_file, 'utf8'));
25
28
  } catch (e) {
26
29
  console.error('Component list file error : ' + e);
27
- return;
30
+ process.exit(1);
28
31
  }
29
32
 
30
33
  const dynamicEntryPointsJs = globSync(`${themePath}/assets/js/blocks/*.js`).map(
package/exportBlock.js CHANGED
@@ -1,8 +1,8 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const {globSync} = require('glob');
4
- const yargs = require('yargs');
5
- const compressing = require('compressing');
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import {globSync} from 'glob';
4
+ import yargs from 'yargs/yargs';
5
+ import compressing from 'compressing';
6
6
  const templateOptions = yargs(process.argv.slice(2)).argv._;
7
7
  const themePath =
8
8
  process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
@@ -1,8 +1,8 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const {globSync} = require('glob');
4
- const yargs = require('yargs');
5
- const compressing = require('compressing');
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import {globSync} from 'glob';
4
+ import yargs from 'yargs/yargs';
5
+ import compressing from 'compressing';
6
6
  const templateOptions = yargs(process.argv.slice(2)).argv._;
7
7
  const themePath =
8
8
  process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
@@ -1,22 +1,25 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const path = require('path');
4
- const { globSync } = require('glob');
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import {fileURLToPath} from 'node:url';
5
+ import {globSync} from 'glob';
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
5
8
  const themePath = process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
6
9
  const srcPathCustomCaches = `${themePath}/inc/custom-caches`;
7
10
 
8
11
  const bColors = {
9
- HEADER: '\033[95m',
10
- OKBLUE: '\033[94m',
11
- OKGREEN: '\033[92m',
12
- WARNING: '\033[93m',
13
- FAIL: '\033[91m',
14
- ENDC: '\033[0m',
15
- BOLD: '\033[1m',
16
- UNDERLINE: '\033[4m',
17
- ORANGE: '\033[93m',
18
- MAGENTA: '\033[95m',
19
- CYAN: '\033[96m'
12
+ HEADER: '\u001b[95m',
13
+ OKBLUE: '\u001b[94m',
14
+ OKGREEN: '\u001b[92m',
15
+ WARNING: '\u001b[93m',
16
+ FAIL: '\u001b[91m',
17
+ ENDC: '\u001b[0m',
18
+ BOLD: '\u001b[1m',
19
+ UNDERLINE: '\u001b[4m',
20
+ ORANGE: '\u001b[93m',
21
+ MAGENTA: '\u001b[95m',
22
+ CYAN: '\u001b[96m'
20
23
  };
21
24
 
22
25
  const icons = {
@@ -1,7 +1,10 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const yargs = require('yargs');
4
- const path = require('path');
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import yargs from 'yargs/yargs';
4
+ import path from 'node:path';
5
+ import {fileURLToPath} from 'node:url';
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
5
8
  // entry points
6
9
  const args = yargs(process.argv.slice(2)).argv;
7
10
  const componentOptions = args._;
@@ -15,17 +18,17 @@ const destPathEntryPoints = path.join(
15
18
  );
16
19
 
17
20
  const bColors = {
18
- HEADER: '\033[95m',
19
- OKBLUE: '\033[94m',
20
- OKGREEN: '\033[92m',
21
- WARNING: '\033[93m',
22
- FAIL: '\033[91m',
23
- ENDC: '\033[0m',
24
- BOLD: '\033[1m',
25
- UNDERLINE: '\033[4m',
26
- ORANGE: '\033[93m',
27
- MAGENTA: '\033[95m',
28
- CYAN: '\033[96m'
21
+ HEADER: '\u001b[95m',
22
+ OKBLUE: '\u001b[94m',
23
+ OKGREEN: '\u001b[92m',
24
+ WARNING: '\u001b[93m',
25
+ FAIL: '\u001b[91m',
26
+ ENDC: '\u001b[0m',
27
+ BOLD: '\u001b[1m',
28
+ UNDERLINE: '\u001b[4m',
29
+ ORANGE: '\u001b[93m',
30
+ MAGENTA: '\u001b[95m',
31
+ CYAN: '\u001b[96m'
29
32
  };
30
33
 
31
34
  const icons = {
@@ -1,6 +1,6 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const path = require('path');
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
4
 
5
5
  const themePath = process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
6
6
 
@@ -8,17 +8,17 @@ const srcPathImages = path.join(themePath, 'assets/images/icon/library-images');
8
8
  const destPath = '../../../../../onion-library/components/fields-library-images';
9
9
 
10
10
  const bColors = {
11
- HEADER: '\033[95m',
12
- OKBLUE: '\033[94m',
13
- OKGREEN: '\033[92m',
14
- WARNING: '\033[93m',
15
- FAIL: '\033[91m',
16
- ENDC: '\033[0m',
17
- BOLD: '\033[1m',
18
- UNDERLINE: '\033[4m',
19
- ORANGE: '\033[93m',
20
- MAGENTA: '\033[95m',
21
- CYAN: '\033[96m'
11
+ HEADER: '\u001b[95m',
12
+ OKBLUE: '\u001b[94m',
13
+ OKGREEN: '\u001b[92m',
14
+ WARNING: '\u001b[93m',
15
+ FAIL: '\u001b[91m',
16
+ ENDC: '\u001b[0m',
17
+ BOLD: '\u001b[1m',
18
+ UNDERLINE: '\u001b[4m',
19
+ ORANGE: '\u001b[93m',
20
+ MAGENTA: '\u001b[95m',
21
+ CYAN: '\u001b[96m'
22
22
  };
23
23
 
24
24
  const icons = {
@@ -1,22 +1,25 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const path = require('path');
4
- const { globSync } = require('glob');
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import {fileURLToPath} from 'node:url';
5
+ import {globSync} from 'glob';
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
5
8
  const themePath = process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
6
9
  const srcPathSeoExtras = `${themePath}/inc/seo-extras`;
7
10
 
8
11
  const bColors = {
9
- HEADER: '\033[95m',
10
- OKBLUE: '\033[94m',
11
- OKGREEN: '\033[92m',
12
- WARNING: '\033[93m',
13
- FAIL: '\033[91m',
14
- ENDC: '\033[0m',
15
- BOLD: '\033[1m',
16
- UNDERLINE: '\033[4m',
17
- ORANGE: '\033[93m',
18
- MAGENTA: '\033[95m',
19
- CYAN: '\033[96m'
12
+ HEADER: '\u001b[95m',
13
+ OKBLUE: '\u001b[94m',
14
+ OKGREEN: '\u001b[92m',
15
+ WARNING: '\u001b[93m',
16
+ FAIL: '\u001b[91m',
17
+ ENDC: '\u001b[0m',
18
+ BOLD: '\u001b[1m',
19
+ UNDERLINE: '\u001b[4m',
20
+ ORANGE: '\u001b[93m',
21
+ MAGENTA: '\u001b[95m',
22
+ CYAN: '\u001b[96m'
20
23
  };
21
24
 
22
25
  const icons = {
@@ -1,9 +1,12 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const fse = require('fs-extra');
4
- const {globSync} = require('glob');
5
- const yargs = require('yargs');
6
- const path = require('path');
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import fse from 'fs-extra';
4
+ import {globSync} from 'glob';
5
+ import yargs from 'yargs/yargs';
6
+ import path from 'node:path';
7
+ import {fileURLToPath} from 'node:url';
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
10
  const templateOptions = yargs(process.argv.slice(2)).argv._;
8
11
  const themePath =
9
12
  process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
@@ -43,17 +46,17 @@ const destPath = path.join(
43
46
  );
44
47
 
45
48
  const bColors = {
46
- HEADER: '\033[95m',
47
- OKBLUE: '\033[94m',
48
- OKGREEN: '\033[92m',
49
- WARNING: '\033[93m',
50
- FAIL: '\033[91m',
51
- ENDC: '\033[0m',
52
- BOLD: '\033[1m',
53
- UNDERLINE: '\033[4m',
54
- ORANGE: '\033[93m',
55
- MAGENTA: '\033[95m',
56
- CYAN: '\033[96m'
49
+ HEADER: '\u001b[95m',
50
+ OKBLUE: '\u001b[94m',
51
+ OKGREEN: '\u001b[92m',
52
+ WARNING: '\u001b[93m',
53
+ FAIL: '\u001b[91m',
54
+ ENDC: '\u001b[0m',
55
+ BOLD: '\u001b[1m',
56
+ UNDERLINE: '\u001b[4m',
57
+ ORANGE: '\u001b[93m',
58
+ MAGENTA: '\u001b[95m',
59
+ CYAN: '\u001b[96m'
57
60
  };
58
61
 
59
62
  const icons = {
package/importBlock.js CHANGED
@@ -1,8 +1,8 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const {globSync} = require('glob');
4
- const yargs = require('yargs');
5
- const compressing = require('compressing');
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import {globSync} from 'glob';
4
+ import yargs from 'yargs/yargs';
5
+ import compressing from 'compressing';
6
6
  const templateOptions = yargs(process.argv.slice(2)).argv._;
7
7
  const blockName = templateOptions[0];
8
8
  const exportedFolder = '../../../../exported-blocks';
@@ -77,11 +77,11 @@ const decompressDone = () => {
77
77
  if (!existingBlocks.includes(blockName)) {
78
78
  if (!blockName) {
79
79
  console.log('Aborting because of bad name!');
80
- return;
80
+ process.exit(1);
81
81
  }
82
82
  if (!fs.existsSync(`${exportedFolder}/${blockName}.zip`)) {
83
83
  console.log('Aborting as could not find the zip file');
84
- return;
84
+ process.exit(1);
85
85
  }
86
86
  compressing.zip
87
87
  .uncompress(`${exportedFolder}/${blockName}.zip`, `${exportedFolder}/`)
@@ -1,8 +1,8 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const {globSync} = require('glob');
4
- const yargs = require('yargs');
5
- const compressing = require('compressing');
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import {globSync} from 'glob';
4
+ import yargs from 'yargs/yargs';
5
+ import compressing from 'compressing';
6
6
  const templateOptions = yargs(process.argv.slice(2)).argv._;
7
7
  const blockName = templateOptions[0];
8
8
  const exportedFolder = '../../../../exported-blocks';
@@ -64,11 +64,11 @@ const decompressDone = () => {
64
64
 
65
65
  if (!blockName) {
66
66
  console.log('Aborting because of bad name!');
67
- return;
67
+ process.exit(1);
68
68
  }
69
69
  if (!fs.existsSync(`${exportedFolder}/${blockName}.zip`)) {
70
70
  console.log('Aborting as could not find the zip file');
71
- return;
71
+ process.exit(1);
72
72
  }
73
73
  compressing.zip
74
74
  .uncompress(`${exportedFolder}/${blockName}.zip`, `${exportedFolder}/`)
package/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import VideoController from './onion-videocontroller/onion-videocontroller.js';
2
+ import ModalController from './onion-modalcontroller/onion-modalcontroller.js';
3
+ export * from './onion-utils.mjs';
4
+ export * from './entry-animation-observer.js';
5
+
6
+ export default VideoController;
7
+ export { VideoController, ModalController };
8
+ export { default as modalController } from './onion-modalcontroller/onion-modalcontroller.js';
9
+ export { default as videoController } from './onion-videocontroller/onion-videocontroller.js';
10
+ export { default as onionLoader } from './onion-loader.js';
@@ -1,6 +1,6 @@
1
- const fs = require('fs');
2
- const glob = require('glob');
3
- const yargs = require('yargs');
1
+ import fs from 'node:fs';
2
+ import * as glob from 'glob';
3
+ import yargs from 'yargs/yargs';
4
4
 
5
5
  let projectName = 'Global Theme';
6
6
  const libraryPath = './node_modules/@total_onion/onion-library';
@@ -1,4 +1,4 @@
1
- const glob = require('glob');
1
+ import * as glob from 'glob';
2
2
  const libraryPath =
3
3
  './node_modules/@total_onion/onion-library'
4
4
 
@@ -0,0 +1,30 @@
1
+ export default function templateAcfPattern(newBlockName, projectName) {
2
+ const blockTitle =
3
+ newBlockName.charAt(0).toUpperCase() +
4
+ newBlockName.slice(1).replaceAll('-', ' ');
5
+ const namespace = projectName.toLowerCase().replaceAll(' ', '-');
6
+
7
+ return `<?php
8
+ /**
9
+ * ${blockTitle}
10
+ */
11
+ add_action('acf/init', function () {
12
+ if (function_exists('acf_register_block_type')) {
13
+ acf_register_block_type([
14
+ 'name' => '${newBlockName}',
15
+ 'title' => '${blockTitle}',
16
+ 'description' => '${blockTitle}',
17
+ 'render_template' => get_template_directory() . '/views/blocks/${newBlockName}.twig',
18
+ 'category' => 'project-blocks',
19
+ 'icon' => 'editor-code',
20
+ 'supports' => [
21
+ 'align' => false,
22
+ 'anchor' => true,
23
+ ],
24
+ 'enqueue_style' => get_template_directory_uri() . '/assets/scss/blocks/${newBlockName}.css',
25
+ 'enqueue_script' => get_template_directory_uri() . '/assets/js/blocks/${newBlockName}.js',
26
+ ]);
27
+ }
28
+ });
29
+ `;
30
+ }
@@ -1,4 +1,4 @@
1
- module.exports = function (newBlockName, projectName) {
1
+ export default function (newBlockName, projectName) {
2
2
  const blockTitle =
3
3
  newBlockName.charAt(0).toUpperCase() +
4
4
  newBlockName.slice(1).replaceAll('-', ' ');
@@ -1,6 +1,5 @@
1
- module.exports = {
2
- defaultjs: function (newBlockName) {
3
- return `export default function ${newBlockName.replaceAll(
1
+ const defaultjs = function (newBlockName) {
2
+ return `export default function ${newBlockName.replaceAll(
4
3
  '-',
5
4
  ''
6
5
  )}Js ( options = {} ) {
@@ -10,12 +9,16 @@ module.exports = {
10
9
  console.error( error );
11
10
  }
12
11
  }`;
13
- },
14
- defaultscss: function (newBlockName) {
15
- return `// @use 'NodeModules/@total_onion/onion-library/components/fields-core-mixins-v3/core-mixins-v3';
12
+ };
13
+
14
+ const defaultscss = function (newBlockName) {
15
+ return `// @use 'NodeModules/@total_onion/onion-library/components/fields-core-mixins-v3/core-mixins-v3';
16
16
  // @use 'NodeModules/@total_onion/onion-library/components/fields-core-functions-v3/core-functions-v3';
17
17
  // @use 'NodeModules/@total_onion/onion-library/breakpoints';
18
18
  .${newBlockName} {
19
19
  }`;
20
- }
21
20
  };
21
+
22
+ export default { defaultjs, defaultscss };
23
+ export { defaultjs, defaultscss };
24
+
@@ -1,4 +1,4 @@
1
- module.exports = function (newBlockName, projectName) {
1
+ export default function templateJsBlank(newBlockName) {
2
2
  return `export default function ${newBlockName.replaceAll(
3
3
  '-',
4
4
  ''
@@ -9,4 +9,4 @@ module.exports = function (newBlockName, projectName) {
9
9
  console.error(error);
10
10
  }
11
11
  }`;
12
- };
12
+ }
@@ -1,6 +1,6 @@
1
- module.exports = function (newBlockName, projectName) {
1
+ export default function templateScssBlank(newBlockName) {
2
2
  return `// @use 'NodeModules/@total_onion/onion-library/components/fields-core-mixins-v3/core-mixins-v3';
3
3
  // @use 'NodeModules/@total_onion/onion-library/components/fields-core-functions-v3/core-functions-v3';
4
4
  // @use 'NodeModules/@total_onion/onion-library/breakpoints';
5
5
  .${newBlockName} {}`;
6
- };
6
+ }
package/onion-loader.js CHANGED
@@ -52,27 +52,35 @@ function lazyloaderInit() {
52
52
  options.debugLogMessages && console.log('Lazy Loader initialized!');
53
53
  options.lazyBlocksToSearchFor = [];
54
54
  assetArray.forEach((asset) => {
55
- if (
56
- options.filePrefix === 'nodemodules' &&
57
- asset.assetKey.includes('-v3')
58
- ) {
55
+ // if (
56
+ // asset.assetKey.includes('-v3') &&
57
+ // !asset.assetKey.includes('sub-block')
58
+ // ) {
59
+ // options.assetMap[asset.assetKey] = {
60
+ // js: () =>
61
+ // import(
62
+ // `Assets/blocks/${asset.assetKey}/${asset.assetKey}${options.fileSuffixJs}`
63
+ // ),
64
+ // // import(
65
+ // // `NodeModules/@total_onion/onion-library/components/block-${asset.assetKey}/${asset.assetKey}${options.fileSuffixJs}`
66
+ // // ),
67
+ // css: options.ignoreCss === true
68
+ // };
69
+ // }
70
+ if (asset.assetKey.includes('-v3')) {
59
71
  options.assetMap[asset.assetKey] = {
60
72
  js: () =>
61
73
  import(
62
- `NodeModules/@total_onion/onion-library/components/block-${asset.assetKey}/${asset.assetKey}${options.fileSuffixJs}`
74
+ `Assets/sub-blocks/${asset.assetKey}/${asset.assetKey}${options.fileSuffixJs}`
63
75
  ),
64
- css: options.ignoreCss === true
76
+ css: options.ignoreCss === false
65
77
  };
66
- } else {
67
78
  }
68
- if (
69
- options.filePrefix === 'nodemodules' &&
70
- !asset.assetKey.includes('-v3')
71
- ) {
79
+ if (!asset.assetKey.includes('-v3')) {
72
80
  options.assetMap[asset.assetKey] = {
73
81
  js: () =>
74
82
  import(
75
- `Assets/js/blocks/${asset.assetKey}${options.fileSuffixJs}`
83
+ `Assets/blocks/${asset.assetKey}/${asset.assetKey}${options.fileSuffixJs}`
76
84
  ),
77
85
  css: options.ignoreCss === false
78
86
  };
@@ -236,7 +244,7 @@ export function loadCss(assetKey) {
236
244
  assetKey.includes('-v3')
237
245
  ) {
238
246
  import(
239
- /* webpackChunkName: "[request]" */ `NodeModules/@total_onion/onion-library/components/block-${assetKey}/${assetKey}${options.fileSuffixCss}`
247
+ /* webpackChunkName: "[request]" */ `Assets/sub-blocks/${assetKey}/${assetKey}${options.fileSuffixCss}`
240
248
  ).then(() => resolve(true));
241
249
  } else if (
242
250
  options.css === true &&
@@ -244,7 +252,7 @@ export function loadCss(assetKey) {
244
252
  !assetKey.includes('-v3')
245
253
  ) {
246
254
  import(
247
- /* webpackChunkName: "[request]" */ `Assets/scss/blocks/${assetKey}${options.fileSuffixCss}`
255
+ /* webpackChunkName: "[request]" */ `Assets/blocks/${assetKey}/${assetKey}${options.fileSuffixCss}`
248
256
  ).then(() => resolve(true));
249
257
  } else {
250
258
  return resolve(true);
package/onion-utils.mjs CHANGED
@@ -88,24 +88,24 @@ export function inCriticalCssConfig(assetKey) {
88
88
  return true;
89
89
  }
90
90
 
91
- /**
92
- * Dynamically loads the css for the block if it has not already been included in critical css or the css property is set to false.
93
- * @param {string} assetKey The assetkey string of the block.
94
- * @param {object} options The options object which will at the very least contain the css property set to true.
95
- * @returns {promise}
96
- */
97
- export function loadCss(assetKey, options = { css: true }) {
98
- const promise = new Promise((resolve) => {
99
- if (options.css === true && !inCriticalCssConfig(assetKey)) {
100
- import(
101
- /* webpackChunkName: "[request]" */ `Assets/scss/blocks/${assetKey}.scss`
102
- ).then(() => resolve(true));
103
- } else {
104
- return resolve(true);
105
- }
106
- });
107
- return promise;
108
- }
91
+ // /**
92
+ // * Dynamically loads the css for the block if it has not already been included in critical css or the css property is set to false.
93
+ // * @param {string} assetKey The assetkey string of the block.
94
+ // * @param {object} options The options object which will at the very least contain the css property set to true.
95
+ // * @returns {promise}
96
+ // */
97
+ // export function loadCss(assetKey, options = { css: true }) {
98
+ // const promise = new Promise((resolve) => {
99
+ // if (options.css === true && !inCriticalCssConfig(assetKey)) {
100
+ // import(
101
+ // /* webpackChunkName: "[request]" */ `Assets/scss/blocks/${assetKey}.scss`
102
+ // ).then(() => resolve(true));
103
+ // } else {
104
+ // return resolve(true);
105
+ // }
106
+ // });
107
+ // return promise;
108
+ // }
109
109
 
110
110
  /**
111
111
  * Checks for browser, device and OS and then adds the relevant classes to the html tag.
@@ -680,7 +680,6 @@ const api = {
680
680
  isEmailValid,
681
681
  isInViewport,
682
682
  isTablet,
683
- loadCss,
684
683
  mobileCheck,
685
684
  resizeDebouncer,
686
685
  supportsWebp,
package/package.json CHANGED
@@ -1,8 +1,23 @@
1
1
  {
2
2
  "name": "@total_onion/onion-library",
3
- "version": "3.1.0",
3
+ "version": "3.2.1",
4
4
  "description": "Component library",
5
- "main": "index.js",
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "module": "./index.js",
8
+ "exports": {
9
+ ".": "./index.js",
10
+ "./onion-utils": "./onion-utils.mjs",
11
+ "./onion-utils.mjs": "./onion-utils.mjs",
12
+ "./onion-loader": "./onion-loader.js",
13
+ "./onion-loader.js": "./onion-loader.js",
14
+ "./entry-animation-observer": "./entry-animation-observer.js",
15
+ "./entry-animation-observer.js": "./entry-animation-observer.js",
16
+ "./onion-videocontroller": "./onion-videocontroller/onion-videocontroller.js",
17
+ "./onion-videocontroller.js": "./onion-videocontroller/onion-videocontroller.js",
18
+ "./onion-modalcontroller": "./onion-modalcontroller/onion-modalcontroller.js",
19
+ "./onion-modalcontroller.js": "./onion-modalcontroller/onion-modalcontroller.js"
20
+ },
6
21
  "scripts": {
7
22
  "build": "node build-library.js",
8
23
  "test": ""
@@ -18,8 +33,7 @@
18
33
  },
19
34
  "homepage": "https://github.com/TotalOnion/onion-library#readme",
20
35
  "dependencies": {
21
- "lottie-web": "^5.13.0",
22
- "swiper": "^14.1.0"
36
+ "@vimeo/player": "^2.26.0"
23
37
  },
24
38
  "devDependencies": {
25
39
  "autoprefixer": "^10.4.27",
@@ -36,6 +50,8 @@
36
50
  "postcss-preset-env": "^11.2.0",
37
51
  "prettier": "^2.6.2",
38
52
  "url-loader": "^4.1.1",
39
- "yargs": "^17.4.1"
53
+ "yargs": "^17.4.1",
54
+ "lottie-web": "^5.13.0",
55
+ "swiper": "^14.1.0"
40
56
  }
41
57
  }
@@ -33,6 +33,8 @@ export default function cocktailrecipev3Js(options = {}) {
33
33
  return (Math.round(num * 100) / 100).toFixed(2).replace(/\.?0+$/, "");
34
34
  if (unit === "ml")
35
35
  return (Math.round(num * 10) / 10).toString().replace(/\.0$/, "");
36
+ if (unit === "cl")
37
+ return (Math.round(num * 100) / 100).toString().replace(/\.0$/, "");
36
38
  return (Math.round(num * 100) / 100).toString().replace(/\.?0+$/, "");
37
39
  };
38
40
  const convert = (value, fromUnit, toUnit) => {
@@ -5,7 +5,9 @@ export default function modalformv3Js(options = {}) {
5
5
  ".cdb_form_field input, .cdb_form_field select, .cdb_form_gdpr_information input, .cdb_form_privacypolicy_information input"
6
6
  );
7
7
  inputs.forEach((input) => {
8
- const wrapper = input.closest(".cdb_form_field, .cdb_form_gdpr_information, .cdb_form_privacypolicy_information");
8
+ const wrapper = input.closest(
9
+ ".cdb_form_field, .cdb_form_gdpr_information, .cdb_form_privacypolicy_information"
10
+ );
9
11
  if (!wrapper) return;
10
12
  wrapper.classList.remove("invalid");
11
13
  if (!input.hasAttribute("required")) return;
@@ -31,9 +33,11 @@ export default function modalformv3Js(options = {}) {
31
33
  });
32
34
  };
33
35
  const { block } = options;
34
- const submit = block.querySelector(
35
- ".cdb-submit"
36
- );
36
+ const submit = block.querySelector(".cdb-submit");
37
+ if (!submit) {
38
+ console.error("could not find submit button");
39
+ return;
40
+ }
37
41
  submit.classList.add("cmpl-cta-style-11", "cmpl-cta-animation-style-1");
38
42
  submit.addEventListener("click", (e) => {
39
43
  validateFormFields(block);
@@ -1,4 +1,4 @@
1
- import videocontroller from "@total_onion/onion-videocontroller/onion-videocontroller.js";
1
+ import videocontroller from "../../onion-videocontroller/onion-videocontroller.js";
2
2
  export default function videocontentv3Js(options = {}) {
3
3
  try {
4
4
  const { block } = options;
package/removeBlock.js CHANGED
@@ -1,7 +1,7 @@
1
- require('dotenv').config();
2
- const fs = require('fs');
3
- const readline = require('readline');
4
- const {globSync} = require('glob');
1
+ import 'dotenv/config';
2
+ import fs from 'node:fs';
3
+ import readline from 'node:readline';
4
+ import {globSync} from 'glob';
5
5
  const themePath =
6
6
  process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
7
7
 
@@ -1,16 +1,16 @@
1
- const getComponentsList = () => {
2
- const path = require('path');
3
- const glob = require('glob');
4
- const fs = require('fs');
5
- const libraryPath = './node_modules/@total_onion/onion-library';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import {exec} from 'node:child_process';
4
+ import {pathToFileURL} from 'node:url';
5
+ import * as glob from 'glob';
6
6
 
7
- let finalList = [];
7
+ const libraryPath = './node_modules/@total_onion/onion-library';
8
8
 
9
- // printMemoryUsage('Before checking components list');
9
+ const getComponentsList = () => {
10
+ let finalList = [];
10
11
 
11
12
  if (fs.existsSync('./project-components-list.json')) {
12
13
  const componentsList = glob.sync(`${libraryPath}/components/*`);
13
-
14
14
  const listJson = fs.readFileSync('./project-components-list.json');
15
15
  const componentsListObject = JSON.parse(listJson);
16
16
 
@@ -27,28 +27,19 @@ const getComponentsList = () => {
27
27
  finalList.push(component);
28
28
  }
29
29
  });
30
-
31
- // Free up memory
32
30
  } else {
33
31
  finalList = glob
34
32
  .sync(`${libraryPath}/components/*`)
35
- .map((componentPath) => {
36
- return path.basename(componentPath);
37
- });
33
+ .map((componentPath) => path.basename(componentPath));
38
34
  }
39
35
 
40
- // printMemoryUsage('After checking components list');
41
-
42
36
  return finalList;
43
37
  };
44
38
 
45
39
  const updateAllComponents = () => {
46
- const {exec} = require('child_process');
47
40
  const componentsList = getComponentsList();
48
41
  console.log('updating all Onions');
49
42
 
50
- // printMemoryUsage('Before updating components');
51
-
52
43
  if (
53
44
  componentsList.includes('admin-core-generic') ||
54
45
  componentsList.includes('admin-core-critical')
@@ -60,7 +51,6 @@ const updateAllComponents = () => {
60
51
  process.exit();
61
52
  }
62
53
 
63
- // Limit the number of parallel updates
64
54
  const maxConcurrentUpdates = 2;
65
55
  let currentIndex = 0;
66
56
 
@@ -85,13 +75,11 @@ const updateAllComponents = () => {
85
75
  console.log(`stdout: ${stdout}`);
86
76
  }
87
77
 
88
- // Recursively update the next component
89
78
  updateNextComponent();
90
79
  }
91
80
  );
92
81
  };
93
82
 
94
- // Start the initial batch of updates
95
83
  for (
96
84
  let i = 0;
97
85
  i < Math.min(maxConcurrentUpdates, componentsList.length);
@@ -99,37 +87,10 @@ const updateAllComponents = () => {
99
87
  ) {
100
88
  updateNextComponent();
101
89
  }
102
-
103
- // printMemoryUsage('After updating components');
104
90
  };
105
91
 
106
- const printMemoryUsage = (label) => {
107
- console.log(console.time(label));
108
- const memoryUsage = process.memoryUsage();
109
- console.log(`\nMemory Usage - ${label}`);
110
- console.log(`RSS: ${Math.round(memoryUsage.rss / 1024 / 1024)} MB`);
111
- console.log(
112
- `Heap Total: ${Math.round(memoryUsage.heapTotal / 1024 / 1024)} MB`
113
- );
114
- console.log(
115
- `Heap Used: ${Math.round(memoryUsage.heapUsed / 1024 / 1024)} MB`
116
- );
117
- console.log(
118
- `External: ${Math.round(memoryUsage.external / 1024 / 1024)} MB`
119
- );
120
- console.log(
121
- `Array Buffers: ${Math.round(
122
- memoryUsage.arrayBuffers / 1024 / 1024
123
- )} MB\n`
124
- );
125
- };
126
-
127
- module.exports = {
128
- getComponentsList,
129
- updateAllComponents
130
- };
92
+ export {getComponentsList, updateAllComponents};
131
93
 
132
- // It calls the function only if executed through the command line
133
- if (require.main === module) {
94
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
134
95
  updateAllComponents();
135
96
  }
@@ -1,7 +1,9 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import {pathToFileURL} from 'node:url';
4
+
1
5
  const themePath =
2
6
  process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
3
- const fs = require('fs');
4
- const path = require('path');
5
7
  const libraryPath = './node_modules/@total_onion/onion-library';
6
8
 
7
9
  // Get extension of filename
@@ -516,7 +518,7 @@ const updateComponent = () => {
516
518
  );
517
519
  };
518
520
 
519
- module.exports = {
521
+ export {
520
522
  getExtension,
521
523
  getFileType,
522
524
  checkFolder,
@@ -531,7 +533,6 @@ module.exports = {
531
533
  updateComponent
532
534
  };
533
535
 
534
- // It calls the function only if executed through the command line
535
- if (require.main === module) {
536
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
536
537
  updateComponent();
537
538
  }
@@ -1,7 +1,9 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import {pathToFileURL} from 'node:url';
4
+
1
5
  const themePath =
2
6
  process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
3
- const fs = require('fs');
4
- const path = require('path');
5
7
  const libraryPath = './node_modules/@total_onion/onion-library';
6
8
 
7
9
  // Get extension of filename
@@ -516,7 +518,7 @@ const updateComponent = () => {
516
518
  );
517
519
  };
518
520
 
519
- module.exports = {
521
+ export {
520
522
  getExtension,
521
523
  getFileType,
522
524
  checkFolder,
@@ -531,7 +533,6 @@ module.exports = {
531
533
  updateComponent
532
534
  };
533
535
 
534
- // It calls the function only if executed through the command line
535
- if (require.main === module) {
536
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
536
537
  updateComponent();
537
538
  }