shopify-accelerate-app 1.0.24 → 1.0.26

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": "shopify-accelerate-app",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "Shopify App development with full Typescript Support",
5
5
  "author": "Felix Tellmann",
6
6
  "license": "MIT",
@@ -60,7 +60,8 @@
60
60
  "toml": "^3.0.0",
61
61
  "ts-node": "^10.9.2",
62
62
  "tsconfig-paths": "^4.2.0",
63
- "zustand": "^5.0.1"
63
+ "zustand": "^5.0.1",
64
+ "tailwindcss-animate": "^1.0.7"
64
65
  },
65
66
  "devDependencies": {
66
67
  "@types/inquirer": "^9.0.7",
@@ -1,5 +1,7 @@
1
1
  import chalk from "chalk";
2
2
  import path from "path";
3
+ import { delay } from "src/utils/delay";
4
+ import { ShopifyAppBlock } from "types/shopify";
3
5
  // import { require } from "../../require";
4
6
  import { config, root_dir } from "../../shopify-accelerate-app";
5
7
  import { isBlockTs } from "../scaffold-theme/parse-files";
@@ -11,18 +13,51 @@ const { build } = require("esbuild");
11
13
  const watch = require("node-watch");
12
14
  const fs = require("fs");
13
15
 
14
- const transformClassNameStrings = (stringContent) => {
16
+ export const transformClassNameStrings = (
17
+ stringContent,
18
+ final = false,
19
+ cssOutput = "",
20
+ special = false
21
+ ) => {
15
22
  const prefix = process.env.SHOPIFY_ACCELERATE_TAILWIND_PREFIX;
16
23
 
17
- const classNameString = stringContent.replace(/\s+/gi, " ").split(" ");
24
+ if (special) {
25
+ if (["`", "return", "function"].some((val) => stringContent.includes(val))) {
26
+ return stringContent;
27
+ }
28
+ if (stringContent.length <= 2 || !stringContent.trim()) {
29
+ return stringContent;
30
+ }
31
+ }
32
+ const classNameString = special
33
+ ? stringContent.split(" ")
34
+ : stringContent.replace(/\s+/gi, " ").split(" ");
35
+
18
36
  const prefixedClassNames = classNameString.map((className) => {
19
- if (className.includes(":")) {
37
+ if (!className.trim()) return className;
38
+
39
+ if (special && className.length <= 2) {
40
+ return className;
41
+ }
42
+
43
+ if (className.includes(":") && className.split(":").at(-1)?.length >= 2) {
20
44
  return className
21
45
  .split(":")
22
46
  .map((str, index, arr) => {
23
47
  if ((str.match(/\[/g) || []).length !== (str.match(/]/g) || []).length) {
24
48
  return str;
25
49
  }
50
+ if (
51
+ final &&
52
+ (str.startsWith(`${prefix}-`) || str.startsWith(`!${prefix}-`)) &&
53
+ !cssOutput?.includes(str.replace(/([/.[\]])/gi, "\\$1"))
54
+ ) {
55
+ console.log(
56
+ { className: str, b: str.replace(/([/.[\]])/gi, "\\$1") },
57
+ str?.includes(str.replace(/([/.[\]])/gi, "\\$1"))
58
+ );
59
+ return str.replace(`${prefix}-`, "").replace(`!${prefix}-`, "");
60
+ }
26
61
  if (
27
62
  index === arr.length - 1 &&
28
63
  !str.startsWith(`${prefix}-`) &&
@@ -37,6 +72,21 @@ const transformClassNameStrings = (stringContent) => {
37
72
  })
38
73
  .join(":");
39
74
  }
75
+ if (
76
+ final &&
77
+ (className.startsWith(`${prefix}-`) || className.startsWith(`!${prefix}-`)) &&
78
+ !cssOutput?.includes(`${className.replace(/([/.[\]])/gi, "\\$1")} `) &&
79
+ !cssOutput?.includes(`${className.replace(/([/.[\]])/gi, "\\$1")}:`)
80
+ ) {
81
+ console.log(
82
+ { className: className.replace(/([/.[\]])/gi, "\\$1") },
83
+ cssOutput?.includes(className.replace(/([/.[\]])/gi, "\\$1")),
84
+ className.replace(/([/.[\]])/gi, "\\$1")
85
+ );
86
+
87
+ return className.replace(`${prefix}-`, "").replace(`!${prefix}-`, "");
88
+ }
89
+
40
90
  if (className.startsWith(`${prefix}-`) || className.startsWith(`!${prefix}-`)) {
41
91
  return className;
42
92
  } else {
@@ -49,29 +99,43 @@ const transformClassNameStrings = (stringContent) => {
49
99
 
50
100
  return prefixedClassNames.join(" ");
51
101
  };
52
- const transformContent = (input) => {
102
+
103
+ export const transformContent = (input, final = false, cssOutput = "") => {
53
104
  const classNameRegex = /className([=:][_\w$]*)(["'`])([^"'`]+)\2/g;
54
105
  const classNameWithClsxRegex = /className([=:][_\w$]*)\((.*?)\)([},])/g;
55
106
  const classListRegex = /(classList\.[^.(,;'"]*)\(([^)]*)\)/g;
56
107
 
57
- return input
58
- .replace(classListRegex, (match, p1, p2, p3) => {
59
- return `${p1}(${p2.replace(/(["'`])([^"'`]+)\1/g, (match, b1, b2) => {
60
- return `${b1}${transformClassNameStrings(b2)}${b1}`;
61
- })})`;
62
- })
63
- .replace(classNameRegex, (match, p1, p2, p3) => {
64
- return `className${p1}${p2}${transformClassNameStrings(p3)}${p2}`;
108
+ return (
109
+ input
110
+ /* .replace(/"(.*?)"/gm, (match, p1, p2, p3) => {
111
+ return `"${transformClassNameStrings(p1, final, cssOutput, true)}"`;
65
112
  })
66
- .replace(classNameWithClsxRegex, (match, p1, p2, p3) => {
67
- return `className${p1}(${p2.replace(/(["'`])([^"'`]+)\1/g, (match, p1, p2) => {
68
- return `${p1}${transformClassNameStrings(p2)}${p1}`;
69
- })})${p3}`;
70
- });
113
+ .replace(/'(.*?)'/gm, (match, p1, p2, p3) => {
114
+ return `'${transformClassNameStrings(p1, final, cssOutput, true)}'`;
115
+ })*/
116
+ .replace(classListRegex, (match, p1, p2, p3) => {
117
+ return `${p1}(${p2.replace(/(["'`])([^"'`]+)\1/g, (match, b1, b2) => {
118
+ return `${b1}${transformClassNameStrings(b2, final, cssOutput)}${b1}`;
119
+ })})`;
120
+ })
121
+ .replace(classNameRegex, (match, p1, p2, p3) => {
122
+ return `className${p1}${p2}${transformClassNameStrings(p3, final, cssOutput)}${p2}`;
123
+ })
124
+ .replace(classNameWithClsxRegex, (match, p1, p2, p3) => {
125
+ return `className${p1}(${p2.replace(/(["'`])([^"'`]+)\1/g, (match, p1, p2) => {
126
+ return `${p1}${transformClassNameStrings(p2, final, cssOutput)}${p1}`;
127
+ })})${p3}`;
128
+ })
129
+ );
71
130
  };
72
131
 
73
- const runBlockJsEsbuild = async (entryFile, folder) => {
132
+ const current = { timeout: null };
133
+ const runBlockJsEsbuild = async (
134
+ entryFile,
135
+ block: ShopifyAppBlock & { path: string; folder: string }
136
+ ) => {
74
137
  const startTime = Date.now();
138
+ const folder = block.folder;
75
139
 
76
140
  writeOnlyNew(
77
141
  path.join(
@@ -101,12 +165,12 @@ const runBlockJsEsbuild = async (entryFile, folder) => {
101
165
  );
102
166
  await build({
103
167
  entryPoints: [entryFile],
104
-
105
168
  // bundle: true,
106
169
  outfile: outPath,
107
170
  // outdir: path.join(root_dir, config.extension_path, "assets"),
108
171
  bundle: true,
109
172
  metafile: true,
173
+
110
174
  treeShaking: true,
111
175
  loader: { ".js": "jsx" },
112
176
  minify: true,
@@ -124,28 +188,57 @@ const runBlockJsEsbuild = async (entryFile, folder) => {
124
188
  keepNames: false,
125
189
 
126
190
  // splitting: true,
127
- }).catch((error) => {
128
- console.error(error);
129
- // eslint-disable-next-line no-process-exit
130
- });
191
+ })
192
+ .catch((error) => {
193
+ console.error(error);
194
+ // eslint-disable-next-line no-process-exit
195
+ })
196
+ .then((res) => {
197
+ fs.writeFileSync(
198
+ path.join(block.path.replace("schema.ts", ""), "metafile.json"),
199
+ JSON.stringify(res.metafile ?? {})
200
+ );
201
+ });
131
202
 
132
203
  let content = fs.readFileSync(outPath, { encoding: "utf-8" });
204
+
133
205
  if (process.env.SHOPIFY_ACCELERATE_TAILWIND_PREFIX) {
134
206
  content = transformContent(content);
135
207
  }
136
208
  writeCompareFile(finalPath, content);
209
+
210
+ const themePath = path.join(
211
+ process.env.SHOPIFY_ACCELERATE_THEME_OUTPUT_PATH,
212
+ "assets",
213
+ `${folder
214
+ .split(/[\\/]/gi)
215
+ .at(-1)
216
+ .replace(/\.(ts)x?$/gi, "")}.js`
217
+ );
218
+
137
219
  if (process.env.SHOPIFY_ACCELERATE_THEME_OUTPUT_PATH) {
138
- const themePath = path.join(
139
- process.env.SHOPIFY_ACCELERATE_THEME_OUTPUT_PATH,
140
- "assets",
141
- `${folder
142
- .split(/[\\/]/gi)
143
- .at(-1)
144
- .replace(/\.(ts)x?$/gi, "")}.js`
145
- );
146
220
  writeCompareFile(themePath, content);
147
221
  }
148
222
 
223
+ clearTimeout(current.timeout);
224
+ current.timeout = setTimeout(() => {
225
+ Object.values(config.sources.blockSchemas ?? {})?.forEach(({ folder }) => {
226
+ if (!content.includes("/* CSS CROSS CHECKED */")) {
227
+ const finalContent = transformContent(
228
+ content,
229
+ true,
230
+ fs.readFileSync(path.join(config.extension_path, `assets/tailwind.css`), {
231
+ encoding: "utf-8",
232
+ })
233
+ );
234
+ fs.writeFileSync(finalPath, `${finalContent}\n\n/* CSS CROSS CHECKED */`);
235
+ if (process.env.SHOPIFY_ACCELERATE_THEME_OUTPUT_PATH) {
236
+ fs.writeFileSync(themePath, `${finalContent}\n\n/* CSS CROSS CHECKED */`);
237
+ }
238
+ }
239
+ });
240
+ }, 1300);
241
+
149
242
  try {
150
243
  // await delay(20);
151
244
  // fs.unlinkSync(outPath);
@@ -173,7 +266,7 @@ const buildAllBlocks = async () => {
173
266
 
174
267
  if (block && !block.disabled) {
175
268
  try {
176
- await runBlockJsEsbuild(name, block.folder);
269
+ await runBlockJsEsbuild(name, block);
177
270
  } catch (err) {
178
271
  console.log(err);
179
272
  }
@@ -203,7 +296,7 @@ export const runEsbuild = async () => {
203
296
 
204
297
  if (block && !block.disabled) {
205
298
  try {
206
- await runBlockJsEsbuild(`${name.replace(filename, "")}index.tsx`, block.folder);
299
+ await runBlockJsEsbuild(`${name.replace(filename, "")}index.tsx`, block);
207
300
  } catch (err) {
208
301
  console.log(err);
209
302
  }
@@ -2,6 +2,8 @@
2
2
  import child_process from "child_process";
3
3
  import fs from "fs";
4
4
  import path from "path";
5
+ import { delay } from "../utils/delay";
6
+ import { transformContent } from "../esbuild/esbuild";
5
7
  import { config, root_dir } from "../../shopify-accelerate-app";
6
8
  import { deleteFile, writeCompareFile } from "../utils/fs";
7
9
 
@@ -98,6 +100,7 @@ export const runTailwindCSSWatcher = () => {
98
100
  });
99
101
 
100
102
  writeCompareFile(path.join(config.extension_path, `assets/tailwind.css`), content);
103
+
101
104
  if (process.env.SHOPIFY_ACCELERATE_THEME_OUTPUT_PATH) {
102
105
  writeCompareFile(path.join(config.theme_output_path, `assets/tailwind.css`), content);
103
106
  }
@@ -1,14 +1,49 @@
1
+ /** @type {import('tailwindcss').Config} */
1
2
  // eslint-disable-next-line node/no-unpublished-require
2
3
  // import { require } from "../../require";
4
+ const {
5
+ defaultExtractor: createDefaultExtractor,
6
+ } = require("tailwindcss/lib/lib/defaultExtractor");
7
+
8
+ const { default: resolveConfig } = require("tailwindcss/lib/util/resolveConfig");
3
9
  const plugin = require("tailwindcss/plugin");
4
10
  require("dotenv").config();
5
11
 
12
+ /*const defaultExtractor = createDefaultExtractor({
13
+ tailwindConfig: resolveConfig([
14
+ {
15
+ content: [
16
+ `${process.env.SHOPIFY_ACCELERATE_EXTENSION_PATH}/!**!/!*.{html,liquid,js,json}`,
17
+ `!${process.env.SHOPIFY_ACCELERATE_EXTENSION_PATH}/!**!/!*.css`,
18
+ `!${process.env.SHOPIFY_ACCELERATE_EXTENSION_PATH}/!**!/!*.css`,
19
+ ],
20
+ },
21
+ ]),
22
+ });
23
+
24
+ const extractor = (content) => {
25
+ return defaultExtractor(content).map((cls) => {
26
+ console.log({ class: cls });
27
+ return `tw-${cls}`;
28
+ });
29
+ };*/
30
+
6
31
  module.exports = {
7
- content: [
8
- `${process.env.SHOPIFY_ACCELERATE_EXTENSION_PATH}/**/*.{html,liquid,js,json}`,
9
- `!${process.env.SHOPIFY_ACCELERATE_EXTENSION_PATH}/**/*.css`,
10
- `!${process.env.SHOPIFY_ACCELERATE_EXTENSION_PATH}/**/*.css`,
11
- ],
32
+ content: {
33
+ files: [
34
+ `${process.env.SHOPIFY_ACCELERATE_EXTENSION_PATH}/**/*.{html,liquid,js,json}`,
35
+ `!${process.env.SHOPIFY_ACCELERATE_EXTENSION_PATH}/!**!/!*.css`,
36
+ `!${process.env.SHOPIFY_ACCELERATE_EXTENSION_PATH}/!**/!*.css`,
37
+ ],
38
+ /* extract: {
39
+ ts: extractor,
40
+ tsx: extractor,
41
+ html: extractor,
42
+ liquid: extractor,
43
+ js: extractor,
44
+ json: extractor,
45
+ },*/
46
+ },
12
47
  darkMode: "class", // or 'media' or 'class'
13
48
  // mode: process.env.NODE_ENV ? "jit" : undefined,
14
49
  // important: true,
@@ -31,14 +66,6 @@ module.exports = {
31
66
  "2xl": "16px",
32
67
  "3xl": "24px",
33
68
  full: "9999px",
34
- "theme-sm": `var(--plt-rounded-sm)`,
35
- "theme-full": `9999px`,
36
- theme: `var(--plt-rounded)`,
37
- "theme-md": `var(--plt-rounded-md)`,
38
- "theme-lg": `var(--plt-rounded-lg)`,
39
- "theme-xl": `var(--plt-rounded-xl)`,
40
- "theme-2xl": `var(--plt-rounded-2xl)`,
41
- "theme-3xl": `var(--plt-rounded-3xl)`,
42
69
  },
43
70
  columns: {
44
71
  auto: "auto",
@@ -231,14 +258,56 @@ module.exports = {
231
258
  dot: "dot 8.1s linear",
232
259
  typewriter: "typewriter 0.5s linear infinite",
233
260
  },
261
+ colors: {
262
+ border: "hsl(var(--border))",
263
+ input: "hsl(var(--input))",
264
+ ring: "hsl(var(--ring))",
265
+ background: "hsl(var(--background))",
266
+ foreground: "hsl(var(--foreground))",
267
+ primary: {
268
+ DEFAULT: "hsl(var(--primary))",
269
+ foreground: "hsl(var(--primary-foreground))",
270
+ },
271
+ secondary: {
272
+ DEFAULT: "hsl(var(--secondary))",
273
+ foreground: "hsl(var(--secondary-foreground))",
274
+ },
275
+ destructive: {
276
+ DEFAULT: "hsl(var(--destructive))",
277
+ foreground: "hsl(var(--destructive-foreground))",
278
+ },
279
+ muted: {
280
+ DEFAULT: "hsl(var(--muted))",
281
+ foreground: "hsl(var(--muted-foreground))",
282
+ },
283
+ accent: {
284
+ DEFAULT: "hsl(var(--accent))",
285
+ foreground: "hsl(var(--accent-foreground))",
286
+ },
287
+ popover: {
288
+ DEFAULT: "hsl(var(--popover))",
289
+ foreground: "hsl(var(--popover-foreground))",
290
+ },
291
+ card: {
292
+ DEFAULT: "hsl(var(--card))",
293
+ foreground: "hsl(var(--card-foreground))",
294
+ },
295
+ },
296
+ borderRadius: {
297
+ lg: "var(--radius)",
298
+ md: "calc(var(--radius) - 2px)",
299
+ sm: "calc(var(--radius) - 4px)",
300
+ },
234
301
  },
235
302
  variants: {
236
303
  extend: {},
237
304
  },
238
305
  },
239
306
  plugins: [
307
+ require("autoprefixer"),
240
308
  require("@tailwindcss/aspect-ratio"),
241
309
  require("tailwindcss-container-queries-with-max-width"),
310
+ require("tailwindcss-animate"),
242
311
  // require("@tailwindcss/forms"),
243
312
  plugin(({ addVariant, addUtilities, matchUtilities, theme }) => {
244
313
  addVariant("svg", ["& svg"]);
@@ -282,6 +351,7 @@ module.exports = {
282
351
  ".peer:focus-within ~ &",
283
352
  ".peer:active ~ &",
284
353
  ]);
354
+ addVariant("peer-fw", [".peer:focus-within ~ &"]);
285
355
  matchUtilities(
286
356
  {
287
357
  "top-spacing": (value) => ({