@total_onion/onion-library 1.1.44 → 1.1.45

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.
@@ -0,0 +1,163 @@
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 yaml = require('js-yaml');
7
+ const axios = require('axios');
8
+
9
+ const themePath =
10
+ process.env.THEME_PATH || 'web/wp-content/themes/global-theme';
11
+
12
+ const yamlData = yaml.load(fs.readFileSync('../../../../.lando.yml', 'utf8'));
13
+ const siteName = yamlData.config.site;
14
+ const parentURL = process.env.DESIGN_MULTIDEV
15
+ ? `${process.env.DESIGN_MULTIDEV}/wp-admin/admin-ajax.php`
16
+ : `http://${siteName}.lndo.site/wp-admin/admin-ajax.php`;
17
+
18
+ const srcPathJs = `${__dirname}/components`;
19
+ const srcPathScss = `${__dirname}/components`;
20
+
21
+ let projectName = 'Global Theme';
22
+ const projectJson = JSON.parse(fs.readFileSync('./package.json'));
23
+ if (projectJson) {
24
+ projectName = projectJson.name;
25
+ if (projectName.slice(0, 3) === 'the') {
26
+ const prefix =
27
+ projectName.slice(0, 3).charAt(0).toUpperCase() +
28
+ projectName.slice(0, 3).slice(1);
29
+ projectName = `${prefix} ${
30
+ projectName.slice(3).charAt(0).toUpperCase() +
31
+ projectName.slice(3).slice(1)
32
+ }`;
33
+ } else {
34
+ projectName = `${
35
+ projectName.charAt(0).toUpperCase() + projectName.slice(1)
36
+ }`;
37
+ }
38
+ }
39
+
40
+ const dynamicEntryPoints = globSync(`${themePath}/assets/js/blocks/*.js`).map(
41
+ (path) => {
42
+ const assetKey = path
43
+ .replace('assets/js/blocks/', '')
44
+ .replace('.js', '');
45
+ return assetKey;
46
+ }
47
+ );
48
+ const newBlockName = process.argv[2]?.toLowerCase();
49
+ const patternID = process.argv[3];
50
+
51
+ if (!newBlockName) {
52
+ return console.log('Did you forget to give the new block a name?');
53
+ }
54
+ if (!patternID) {
55
+ return console.log('Did you forget to supply the pattern ID?');
56
+ }
57
+ // if (dynamicEntryPoints.indexOf(newBlockName) !== -1) {
58
+ // return console.log(
59
+ // `Alas! There is already a block called ${newBlockName} :( You'll have to try something else..`
60
+ // );
61
+ // }
62
+
63
+ fs.writeFileSync(
64
+ `${themePath}/inc/acf-blocks/${newBlockName}.php`,
65
+ acfTemplate(newBlockName, projectName)
66
+ );
67
+
68
+ const blockName = 'group-container-v3';
69
+
70
+ console.log(`${srcPathJs}/block-${blockName}/${blockName}.js`);
71
+ console.log('__dirname:', __dirname);
72
+ console.log('process.cwd():', process.cwd());
73
+
74
+ const fullPath = `${srcPathJs}/block-${blockName}/${blockName}.js`;
75
+
76
+ const jsdir = `Assets/js/blocks/`;
77
+ // if (!fs.existsSync(jsdir)) {
78
+ // fs.mkdirSync(jsdir, 0o744);
79
+ // }
80
+ const scssdir = `Assets/scss/blocks/`;
81
+ // if (!fs.existsSync(scssdir)) {
82
+ // fs.mkdirSync(scssdir, 0o744);
83
+ // }
84
+
85
+ if (fs.existsSync(`${srcPathJs}/block-${blockName}/${blockName}.js`)) {
86
+ console.log('found it');
87
+
88
+ fs.readFile(
89
+ `${srcPathJs}/block-${blockName}/${blockName}.js`,
90
+ 'utf-8',
91
+ (err, contents) => {
92
+ if (err) throw err;
93
+ const regEx = RegExp(
94
+ String.raw`(${blockName.replaceAll(/( |-)/g, '')})`,
95
+ 'gi'
96
+ );
97
+
98
+ const replaced = contents
99
+ .replaceAll(
100
+ regEx,
101
+ `${newBlockName.toLowerCase().replaceAll(/( |-)/g, '')}`
102
+ )
103
+ .replaceAll(`blocks/${blockName}`, `blocks/${newBlockName}`);
104
+ fs.writeFile(
105
+ `${jsdir}/${newBlockName}.js`,
106
+ replaced,
107
+ 'utf-8',
108
+ function (err) {
109
+ if (err) throw err;
110
+ console.log(
111
+ `👑👑\x1b[32m Successfully duplicated the js file! 👑👑`
112
+ );
113
+ }
114
+ );
115
+ }
116
+ );
117
+ }
118
+ if (fs.existsSync(`${srcPathJs}/block-${blockName}/${blockName}.scss`)) {
119
+ fs.readFile(
120
+ `${srcPathJs}/block-${blockName}/${blockName}.scss`,
121
+ 'utf-8',
122
+ (err, contents) => {
123
+ if (err) throw err;
124
+ const replaced = contents.replaceAll(
125
+ `${blockName}`,
126
+ `${newBlockName}`
127
+ );
128
+ fs.writeFile(
129
+ `${scssdir}/${newBlockName}.scss`,
130
+ replaced,
131
+ 'utf-8',
132
+ function (err) {
133
+ if (err) throw err;
134
+ console.log(
135
+ `👑👑\x1b[32m Successfully duplicated the scss file! 👑👑`
136
+ );
137
+ }
138
+ );
139
+ }
140
+ );
141
+ }
142
+
143
+ let data = new FormData();
144
+ data.append('action', 'get_pattern_block');
145
+ data.append('postID', patternID);
146
+
147
+ const headers = {
148
+ headers: {
149
+ 'user-agent':
150
+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36'
151
+ }
152
+ };
153
+
154
+ axios.post(parentURL, data, headers).then(function (response) {
155
+ fs.writeFileSync(
156
+ `${themePath}/views/blocks/${newBlockName}.twig`,
157
+ response.data.html
158
+ );
159
+ });
160
+
161
+ console.log(
162
+ `👑 👑 👑 Hurrah! You made a new child block called ${newBlockName} 👑 👑 👑`
163
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@total_onion/onion-library",
3
- "version": "1.1.44",
3
+ "version": "1.1.45",
4
4
  "description": "Component library",
5
5
  "main": "index.js",
6
6
  "scripts": {