shopify-accelerate-app 1.0.5 → 1.0.7

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.5",
3
+ "version": "1.0.7",
4
4
  "description": "Shopify App development with full Typescript Support",
5
5
  "author": "Felix Tellmann",
6
6
  "license": "MIT",
@@ -52,6 +52,7 @@
52
52
  "node-watch": "^0.7.4",
53
53
  "postcss": "^8.4.38",
54
54
  "postcss-import": "^16.1.0",
55
+ "preact": "^10.24.3",
55
56
  "prompts": "^2.4.2",
56
57
  "regenerator-runtime": "^0.14.1",
57
58
  "shopify-typed-node-api": "^2.1.1",
@@ -129,7 +129,7 @@ export const config: GlobalsState = {
129
129
  folders: {
130
130
  types: process.env.SHOPIFY_ACCELERATE_TYPES
131
131
  ? path.join(process.cwd(), process.env.SHOPIFY_ACCELERATE_TYPES)
132
- : path.join(root_dir, "@types"),
132
+ : path.join(process.cwd(), "@types"),
133
133
  utils: process.env.SHOPIFY_ACCELERATE_UTILS
134
134
  ? path.join(process.cwd(), process.env.SHOPIFY_ACCELERATE_UTILS)
135
135
  : path.join(root_dir, "@utils"),
@@ -1,8 +1,9 @@
1
- import { require } from "../../require";
2
- import { dtsPlugin } from "esbuild-plugin-d.ts";
1
+ import chalk from "chalk";
3
2
  import path from "path";
3
+ import { require } from "../../require";
4
4
  import { config, root_dir } from "../../shopify-accelerate-app";
5
- import { isBlockTs, isSectionTs } from "../scaffold-theme/parse-files";
5
+ import { isBlockTs } from "../scaffold-theme/parse-files";
6
+ import { writeCompareFile, writeOnlyNew } from "../utils/fs";
6
7
 
7
8
  const { build } = require("esbuild");
8
9
 
@@ -10,54 +11,180 @@ const { build } = require("esbuild");
10
11
  const watch = require("node-watch");
11
12
  const fs = require("fs");
12
13
 
13
- const runBlockJsEsbuild = (entryFile) => {
14
- build({
14
+ const transformClassNameStrings = (stringContent) => {
15
+ const prefix = process.env.SHOPIFY_ACCELERATE_TAILWIND_PREFIX;
16
+
17
+ const classNameString = stringContent.replace(/\s+/gi, " ").split(" ");
18
+ const prefixedClassNames = classNameString.map((className) => {
19
+ if (className.includes(":")) {
20
+ return className
21
+ .split(":")
22
+ .map((str, index, arr) => {
23
+ if ((str.match(/\[/g) || []).length !== (str.match(/]/g) || []).length) {
24
+ return str;
25
+ }
26
+ if (
27
+ index === arr.length - 1 &&
28
+ !str.startsWith(`${prefix}-`) &&
29
+ !str.startsWith(`!${prefix}-`)
30
+ ) {
31
+ if (/^!/gi.test(str)) {
32
+ return `!${prefix}-${str.replace(/^!/gi, "")}`;
33
+ }
34
+ return `${prefix}-${str}`;
35
+ }
36
+ return str;
37
+ })
38
+ .join(":");
39
+ }
40
+ if (className.startsWith(`${prefix}-`) || className.startsWith(`!${prefix}-`)) {
41
+ return className;
42
+ } else {
43
+ if (/^!/gi.test(className)) {
44
+ return `!${prefix}-${className.replace(/^!/gi, "")}`;
45
+ }
46
+ return `${prefix}-${className}`;
47
+ }
48
+ });
49
+
50
+ return prefixedClassNames.join(" ");
51
+ };
52
+ const transformContent = (input) => {
53
+ const classNameRegex = /className([=:][_\w$]*)(["'`])([^"'`]+)\2/g;
54
+ const classNameWithClsxRegex = /className([=:][_\w$]*)\((.*?)\)([},])/g;
55
+ const classListRegex = /(classList\.[^.(,;'"]*)\(([^)]*)\)/g;
56
+
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}`;
65
+ })
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
+ });
71
+ };
72
+
73
+ const runBlockJsEsbuild = async (entryFile, folder) => {
74
+ const startTime = Date.now();
75
+
76
+ writeOnlyNew(
77
+ path.join(process.cwd(), "tsconfig.theme-extension.json"),
78
+ fs.readFileSync(path.join(config.package_root, "tsconfig.theme-extension.json"), {
79
+ encoding: "utf-8",
80
+ })
81
+ );
82
+
83
+ const outPath = path.join(
84
+ config.extension_path,
85
+ "assets",
86
+ `__pre-compiled--${folder
87
+ .split(/[\\/]/gi)
88
+ .at(-1)
89
+ .replace(/\.(ts)x?$/gi, "")}.js`
90
+ );
91
+ const finalPath = path.join(
92
+ config.extension_path,
93
+ "assets",
94
+ `${folder
95
+ .split(/[\\/]/gi)
96
+ .at(-1)
97
+ .replace(/\.(ts)x?$/gi, "")}.js`
98
+ );
99
+ await build({
15
100
  entryPoints: [entryFile],
101
+
102
+ // bundle: true,
103
+ outfile: outPath,
104
+ // outdir: path.join(root_dir, config.extension_path, "assets"),
105
+ bundle: true,
16
106
  metafile: true,
17
- target: "es2020",
18
- // sourcemap: "external",
19
107
  treeShaking: true,
20
- // bundle: true,
21
- outfile: path.join(
22
- root_dir,
23
- config.extension_path,
108
+ loader: { ".js": "jsx" },
109
+ minify: true,
110
+ tsconfig: path.join(process.cwd(), "tsconfig.theme-extension.json"),
111
+ format: "iife",
112
+ // platform: "browser",
113
+ legalComments: "none",
114
+ jsxFactory: "h",
115
+ jsx: "transform",
116
+ jsxImportSource: "preact",
117
+ jsxSideEffects: false,
118
+ keepNames: false,
119
+
120
+ // splitting: true,
121
+ }).catch((error) => {
122
+ console.error(error);
123
+ // eslint-disable-next-line no-process-exit
124
+ });
125
+
126
+ let content = fs.readFileSync(outPath, { encoding: "utf-8" });
127
+ if (process.env.SHOPIFY_ACCELERATE_TAILWIND_PREFIX) {
128
+ content = transformContent(content);
129
+ }
130
+ writeCompareFile(finalPath, content);
131
+ if (process.env.SHOPIFY_ACCELERATE_THEME_OUTPUT_PATH) {
132
+ const themePath = path.join(
133
+ process.env.SHOPIFY_ACCELERATE_THEME_OUTPUT_PATH,
24
134
  "assets",
25
- `__block--${entryFile
135
+ `${folder
26
136
  .split(/[\\/]/gi)
27
137
  .at(-1)
28
- .replace(/\.(ts)x?$/gi, ".js")}`
29
- ),
30
- // outdir: path.join(root_dir, config.extension_path, "assets"),
31
- minify: false,
32
- ignoreAnnotations: true,
33
- packages: "external",
34
- format: "esm",
35
- legalComments: "none",
36
- keepNames: true,
37
- plugins: [dtsPlugin({})],
138
+ .replace(/\.(ts)x?$/gi, "")}.js`
139
+ );
140
+ writeCompareFile(themePath, content);
141
+ }
38
142
 
39
- // splitting: true,
40
- })
41
- .then((e) => {
42
- console.log(
43
- `__block--${entryFile
44
- .split(/[\\/]/gi)
45
- .at(-1)
46
- .replace(/\.(ts)x?$/gi, ".js")} - bundled`
47
- );
143
+ try {
144
+ fs.unlinkSync(outPath);
145
+ } catch (err) {
146
+ console.log(err);
147
+ }
148
+
149
+ console.log(
150
+ `[${chalk.gray(new Date().toLocaleTimeString())}]: [${chalk.magentaBright(
151
+ `${Date.now() - startTime}ms`
152
+ )}] ${chalk.magenta(`File Bundled: ${finalPath}`)}`
153
+ );
154
+ return true;
155
+ };
156
+
157
+ const buildAllBlocks = async () => {
158
+ return await Promise.all(
159
+ config.sources.blocksJs.map(async (name) => {
160
+ if (isBlockTs(name) && name.includes("index.ts")) {
161
+ const filename = name.split(/[\\/]/gi).at(-1);
162
+
163
+ const block = Object.values(config.sources.blockSchemas).find((block) =>
164
+ block.path.includes(name.replace(filename, ""))
165
+ );
166
+
167
+ if (block && !block.disabled) {
168
+ try {
169
+ await runBlockJsEsbuild(name, block.folder);
170
+ } catch (err) {
171
+ console.log(err);
172
+ }
173
+ }
174
+ return;
175
+ }
176
+ return;
48
177
  })
49
- .catch((error) => {
50
- console.error(error);
51
- // eslint-disable-next-line no-process-exit
52
- });
178
+ );
53
179
  };
54
180
 
55
- export const runEsbuild = () => {
181
+ export const runEsbuild = async () => {
56
182
  let running = false;
57
- console.log({ root_dir });
183
+
58
184
  watch(root_dir, { recursive: true }, async (event, name) => {
59
185
  if (running || event === "remove") return;
60
186
  if (!name.match(/\.(ts)x?$/) || /schema\.ts$/gi.test(name)) return;
187
+
61
188
  running = true;
62
189
 
63
190
  if (isBlockTs(name)) {
@@ -69,36 +196,21 @@ export const runEsbuild = () => {
69
196
 
70
197
  if (block && !block.disabled) {
71
198
  try {
72
- runBlockJsEsbuild(name);
199
+ await runBlockJsEsbuild(`${name.replace(filename, "")}index.tsx`, block.folder);
73
200
  } catch (err) {
74
201
  console.log(err);
75
202
  }
76
203
  }
77
204
  running = false;
78
205
  return;
206
+ } else {
207
+ await buildAllBlocks();
79
208
  }
80
209
 
81
210
  running = false;
211
+ return;
82
212
  });
83
213
 
84
- config.sources.blocksJs.forEach((name) => {
85
- running = true;
86
- if (isBlockTs(name)) {
87
- const filename = name.split(/[\\/]/gi).at(-1);
88
-
89
- const block = Object.values(config.sources.blockSchemas).find((block) =>
90
- block.path.includes(name.replace(filename, ""))
91
- );
92
-
93
- if (block && !block.disabled) {
94
- try {
95
- runBlockJsEsbuild(name);
96
- } catch (err) {
97
- console.log(err);
98
- }
99
- }
100
- running = false;
101
- return;
102
- }
103
- });
214
+ await buildAllBlocks();
215
+ running = false;
104
216
  };
@@ -236,10 +236,10 @@ declare global {
236
236
  path.join(process.cwd(), extension_path, "locales", "en.default.json"),
237
237
  JSON.stringify(translations, undefined, 2)
238
238
  );
239
- writeCompareFile(
239
+ /*writeCompareFile(
240
240
  path.join(process.cwd(), extension_path, "snippets", "_layout.translations.liquid"),
241
241
  translationsJs
242
- );
242
+ );*/
243
243
  writeCompareFile(path.join(folders.types, "translations.ts"), translationTypes);
244
244
 
245
245
  const dynamicJsImports = [];
@@ -289,10 +289,10 @@ declare global {
289
289
  config.targets.dynamicJs = config.targets.dynamicJs.filter((target) => target !== name);
290
290
  });
291
291
 
292
- writeCompareFile(
292
+ /* writeCompareFile(
293
293
  path.join(process.cwd(), extension_path, "snippets", "_layout.dynamic-imports.liquid"),
294
294
  dynamicJsImports.join("\n")
295
- );
295
+ );*/
296
296
 
297
297
  if (delete_external_snippets) {
298
298
  targets.snippets.forEach((file) => {
@@ -3,7 +3,7 @@ import child_process from "child_process";
3
3
  import fs from "fs";
4
4
  import path from "path";
5
5
  import { config, root_dir } from "../../shopify-accelerate-app";
6
- import { deleteFile } from "../utils/fs";
6
+ import { deleteFile, writeCompareFile } from "../utils/fs";
7
7
 
8
8
  const watch = require("node-watch");
9
9
 
@@ -19,7 +19,7 @@ export const runTailwindCSSWatcher = () => {
19
19
  return;
20
20
  }
21
21
 
22
- const filePath = path.join(root_dir, `assets`, `tailwind_pre_sort.css.liquid`);
22
+ const filePath = path.join(config.extension_path, `assets`, `tailwind_pre_sort.css.liquid`);
23
23
  deleteFile(filePath);
24
24
  /*= =============== Tailwind Watcher ================ */
25
25
  child_process.spawn(
@@ -44,50 +44,14 @@ export const runTailwindCSSWatcher = () => {
44
44
  ],
45
45
  {
46
46
  shell: true,
47
- stdio: "inherit",
48
- }
49
- );
50
-
51
- if (!resetInputFile) {
52
- console.log("Tailwind Reset Input file not found");
53
- return;
54
- }
55
- /*= =============== Tailwind Reset ================ */
56
- child_process.spawn(
57
- "npx",
58
- [
59
- "tailwindcss",
60
- "--config",
61
- /*hasConfig ? "tailwind.config.js" :*/ path.join(
62
- package_root,
63
- `src/tailwind/tailwind.config.js`
64
- ),
65
- "--postcss",
66
- /*hasPostCss ? "postcss.config.js" :*/ path.join(
67
- package_root,
68
- `src/tailwind/postcss.config.js`
69
- ),
70
- "-i",
71
- path.join(root_dir, `assets`, `_reset.css`),
72
- "-o",
73
- path.join(root_dir, `assets`, `reset.css.liquid`),
74
- ],
75
- {
76
- shell: true,
77
- stdio: "inherit",
47
+ // stdio: "inherit",
78
48
  }
79
49
  );
80
50
 
81
51
  /*= =============== Tailwind Plugin Order ================ */
82
- watch(path.join(root_dir, "assets"), { recursive: false }, async (evt, name) => {
83
- if (
84
- !name.match(/tailwind_pre_sort.css.liquid$/) ||
85
- !fs.existsSync(path.join(root_dir, "./assets/tailwind_pre_sort.css.liquid"))
86
- )
87
- return;
88
- const file = fs.readFileSync(path.join(root_dir, "./assets/tailwind_pre_sort.css.liquid"), {
89
- encoding: "utf-8",
90
- });
52
+ watch(path.join(config.extension_path, "assets"), { recursive: false }, async (evt, name) => {
53
+ if (!name.match(/tailwind_pre_sort.css.liquid$/) || !fs.existsSync(filePath)) return;
54
+ const file = fs.readFileSync(filePath, { encoding: "utf-8" });
91
55
 
92
56
  const top = file
93
57
  .split(/\n}/gi)
@@ -129,7 +93,11 @@ export const runTailwindCSSWatcher = () => {
129
93
  }
130
94
  });
131
95
 
132
- fs.writeFileSync(path.join(root_dir, `assets/tailwind.css.liquid`), content);
133
- fs.writeFileSync(path.join(process.cwd(), ".tailwindorder"), classesInOrder.join("\n"));
96
+ writeCompareFile(path.join(config.extension_path, `assets/tailwind.css.liquid`), content);
97
+ if (process.env.SHOPIFY_ACCELERATE_THEME_OUTPUT_PATH) {
98
+ writeCompareFile(path.join(config.theme_output_path, `assets/tailwind.css.liquid`), content);
99
+ }
100
+ fs.unlinkSync(filePath);
101
+ writeCompareFile(path.join(process.cwd(), ".tailwindorder"), classesInOrder.join("\n"));
134
102
  });
135
103
  };
@@ -5,13 +5,20 @@ require("dotenv").config();
5
5
 
6
6
  module.exports = {
7
7
  content: [
8
- `${process.env.THEME_PATH}/**/*{html,liquid,js,json}`,
9
- `!${process.env.THEME_PATH}/**/*.css.liquid`,
10
- `!${process.env.THEME_PATH}/**/*.css`,
8
+ `${process.env.SHOPIFY_ACCELERATE_EXTENSION_PATH}/**/*{html,liquid,js,json}`,
9
+ `!${process.env.SHOPIFY_ACCELERATE_EXTENSION_PATH}/**/*.css.liquid`,
10
+ `!${process.env.SHOPIFY_ACCELERATE_EXTENSION_PATH}/**/*.css`,
11
11
  ],
12
12
  darkMode: "class", // or 'media' or 'class'
13
13
  // mode: process.env.NODE_ENV ? "jit" : undefined,
14
14
  // important: true,
15
+ important: process.env.SHOPIFY_ACCELERATE_TAILWIND_IMPORTANT,
16
+ prefix: process.env.SHOPIFY_ACCELERATE_TAILWIND_PREFIX
17
+ ? `${process.env.SHOPIFY_ACCELERATE_TAILWIND_PREFIX}-`
18
+ : undefined,
19
+ corePlugins: {
20
+ preflight: false,
21
+ },
15
22
  mode: "jit",
16
23
  theme: {
17
24
  extend: {
@@ -20,11 +27,23 @@ module.exports = {
20
27
  xs: "427px" /*smaller than iphone pro max*/,
21
28
  },
22
29
  fontSize: {
30
+ 8: ["9px", "1.55"],
23
31
  9: ["9px", "1.5"],
24
32
  10: ["10px", "1.5"],
25
33
  11: ["11px", "1.5"],
26
34
  12: ["12px", "1.5"],
27
35
  13: ["13px", "1.5"],
36
+ 14: ["14px", "1.5"],
37
+ 15: ["15px", "1.5"],
38
+ 16: ["16px", "1.5"],
39
+ 17: ["17px", "1.5"],
40
+ 18: ["18px", "1.45"],
41
+ 19: ["19px", "1.45"],
42
+ 20: ["20px", "1.45"],
43
+ 21: ["21px", "1.45"],
44
+ 22: ["22px", "1.4"],
45
+ 23: ["23px", "1.4"],
46
+ 24: ["24px", "1.4"],
28
47
  },
29
48
  padding: {
30
49
  gutter: "var(--layout-container-gutter)",
@@ -0,0 +1,46 @@
1
+ {
2
+ "compilerOptions": {
3
+ "exactOptionalPropertyTypes": false,
4
+ "noPropertyAccessFromIndexSignature": false,
5
+ "noUncheckedIndexedAccess": false,
6
+ "esModuleInterop": true,
7
+ "module": "ESNext",
8
+ "noImplicitAny": false,
9
+ "removeComments": true,
10
+ "preserveConstEnums": true,
11
+ "isolatedModules": false,
12
+ "resolveJsonModule": false,
13
+ "noEmit": false,
14
+ "declaration": false,
15
+ "incremental": false,
16
+ "allowJs": false,
17
+ "experimentalDecorators": true,
18
+ "typeRoots": ["./node_modules/@types", "./@types/types", "./@types"],
19
+ "paths": {
20
+ "types/*": ["./@types/*"],
21
+ "/*": ["./*"],
22
+ "react": ["./node_modules/preact/compat/"],
23
+ "react-dom": ["./node_modules/preact/compat/"]
24
+ },
25
+ "strict": false,
26
+ "strictNullChecks": false,
27
+ "strictPropertyInitialization": false,
28
+ "jsx": "react-jsx",
29
+ "target": "es6",
30
+ "lib": ["dom", "es2015", "dom.iterable"],
31
+ "noEmitHelpers": true,
32
+ "importHelpers": true,
33
+ "jsxImportSource": "preact",
34
+ "types": ["preact/jsx-runtime", "react", "@types/node", "node"],
35
+ "baseUrl": ".",
36
+ "sourceMap": true,
37
+ "moduleResolution": "node",
38
+ "skipLibCheck": true,
39
+ "forceConsistentCasingInFileNames": true,
40
+ "downlevelIteration": true,
41
+ "noImplicitReturns": false,
42
+ "allowSyntheticDefaultImports": true
43
+ },
44
+ "include": ["theme-extension/**/*.ts", "theme-extension/**/*.tsx", "utils/**/*.tsx", "theme-extension/**/*.svg"],
45
+ "exclude": ["node_modules"]
46
+ }