shopify-accelerate-app 1.2.12 → 1.2.13

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.2.12",
3
+ "version": "1.2.13",
4
4
  "description": "Shopify App development with full Typescript Support",
5
5
  "author": "Felix Tellmann",
6
6
  "license": "MIT",
@@ -92,7 +92,12 @@
92
92
  "react/no-unescaped-entities": 0,
93
93
  "react/jsx-sort-props": 0,
94
94
  "node/no-unpublished-require": 0,
95
- "max-len": ["error", { "code": 140 }]
95
+ "max-len": [
96
+ "error",
97
+ {
98
+ "code": 140
99
+ }
100
+ ]
96
101
  }
97
102
  },
98
103
  "prettier": {
@@ -1,4 +1,5 @@
1
1
  // import { require } from "../../require";
2
+ import chalk from "chalk";
2
3
  import child_process from "child_process";
3
4
  import fs from "fs";
4
5
  import path from "path";
@@ -7,48 +8,113 @@ import { writeCompareFile } from "../utils/fs";
7
8
 
8
9
  const watch = require("node-watch");
9
10
 
11
+ const log = (message: string) => {
12
+ console.log(`[${chalk.gray(new Date().toLocaleTimeString())}] ${chalk.magenta("[tailwind]")} ${message}`);
13
+ };
14
+
15
+ /** Find a config file, checking .cjs first (safe in ESM projects), then .js */
16
+ const findLocalConfig = (dir: string, basename: string): string | null => {
17
+ for (const ext of [".cjs", ".js"]) {
18
+ const file_path = path.join(dir, `${basename}${ext}`);
19
+ if (fs.existsSync(file_path)) return file_path;
20
+ }
21
+ return null;
22
+ };
23
+
10
24
  export const runTailwindCSSWatcher = () => {
11
25
  const { package_root } = config;
12
26
 
13
- const hasConfig = fs.existsSync(path.join(root_dir, "tailwind.config.js"));
14
- const hasPostCss = fs.existsSync(path.join(root_dir, "postcss.config.js"));
15
- const inputFile = fs.existsSync(path.join(root_dir, `assets`, `_tailwind.css`));
16
- const resetInputFile = fs.existsSync(path.join(root_dir, `assets`, `_reset.css`));
17
-
18
- if (!inputFile) {
19
- console.log("Tailwind Input file not found");
27
+ const inputPath = path.join(root_dir, "assets", "_tailwind.css");
28
+ if (!fs.existsSync(inputPath)) {
29
+ log(chalk.red("Input file not found: ") + chalk.yellow(inputPath));
20
30
  return;
21
31
  }
22
32
 
23
- const filePath = path.join(config.extension_path, `assets`, `tailwind_pre_sort.css`);
33
+ const localTailwindConfig = findLocalConfig(root_dir, "tailwind.config");
34
+ const localPostcssConfig = findLocalConfig(root_dir, "postcss.config");
35
+
36
+ const tailwindConfig = localTailwindConfig ?? path.join(package_root, "src", "tailwind", "tailwind.config.js");
37
+ const postcssConfig = localPostcssConfig ?? path.join(package_root, "src", "tailwind", "postcss.config.js");
38
+ const filePath = path.join(config.extension_path, "assets", "tailwind_pre_sort.css");
39
+ const outputPath = path.join(config.extension_path, "assets", "tailwind.css");
40
+ const assetsDir = path.join(config.extension_path, "assets");
41
+
42
+ log(chalk.cyan("Starting Tailwind CSS watcher"));
43
+ log(` Input: ${chalk.yellow(inputPath)}`);
44
+ log(` Output: ${chalk.yellow(outputPath)}`);
45
+ log(` Config: ${chalk.yellow(tailwindConfig)}${localTailwindConfig ? chalk.green(" (local)") : chalk.gray(" (package)")}`);
46
+ log(` PostCSS: ${chalk.yellow(postcssConfig)}${localPostcssConfig ? chalk.green(" (local)") : chalk.gray(" (package)")}`);
47
+
48
+ // Ensure the assets output directory exists before Tailwind writes to it
49
+ if (!fs.existsSync(assetsDir)) {
50
+ log(chalk.yellow(`Creating assets directory: ${assetsDir}`));
51
+ fs.mkdirSync(assetsDir, { recursive: true });
52
+ }
24
53
 
25
54
  /*= =============== Tailwind Watcher ================ */
26
- console.log(path.join(root_dir, `assets`, `_tailwind.css`));
27
- console.log(path.join(package_root, `src/tailwind/tailwind.config.js`));
28
- child_process.spawn(
29
- "npx",
30
- [
31
- "tailwindcss",
32
- "--config",
33
- /*hasConfig ? "tailwind.config.js" :*/ path.join(package_root, `src/tailwind/tailwind.config.js`),
34
- "--postcss",
35
- /*hasPostCss ? "postcss.config.js" : */ path.join(package_root, `src/tailwind/postcss.config.js`),
36
- "-i",
37
- path.join(root_dir, `assets`, `_tailwind.css`),
38
- "-o",
39
- filePath,
40
- "--watch",
41
- ],
42
- {
43
- shell: true,
44
- stdio: "inherit",
55
+ const args = [
56
+ "tailwindcss",
57
+ "--config",
58
+ tailwindConfig,
59
+ "--postcss",
60
+ postcssConfig,
61
+ "-i",
62
+ inputPath,
63
+ "-o",
64
+ filePath,
65
+ "--watch",
66
+ ];
67
+
68
+ const proc = child_process.spawn("npx", args, {
69
+ shell: true,
70
+ stdio: ["pipe", "pipe", "pipe"],
71
+ });
72
+
73
+ proc.stdout?.on("data", (data: Buffer) => {
74
+ const output = data.toString().trim();
75
+ if (!output) return;
76
+ if (output.includes("Done in")) {
77
+ log(chalk.green(output));
78
+ } else if (output.includes("Rebuilding")) {
79
+ log(chalk.gray(output));
80
+ } else {
81
+ log(output);
45
82
  }
46
- );
83
+ });
84
+
85
+ proc.stderr?.on("data", (data: Buffer) => {
86
+ const output = data.toString().trim();
87
+ if (!output) return;
88
+ // Browserslist warnings are noise — suppress them
89
+ if (output.includes("Browserslist") || output.includes("npx update-browserslist")) return;
90
+ // Tailwind CLI sends build status to stderr
91
+ if (output.includes("Done in")) {
92
+ log(chalk.green(output));
93
+ } else if (output.includes("Rebuilding")) {
94
+ log(chalk.gray(output));
95
+ } else if (output.includes("warn")) {
96
+ log(chalk.yellow(`[warn] ${output}`));
97
+ } else {
98
+ log(chalk.red(`[error] ${output}`));
99
+ }
100
+ });
101
+
102
+ proc.on("error", (err) => {
103
+ log(chalk.red(`Failed to start Tailwind process: ${err.message}`));
104
+ });
105
+
106
+ proc.on("exit", (code, signal) => {
107
+ if (code !== null && code !== 0) {
108
+ log(chalk.red(`Tailwind process exited with code ${code}`));
109
+ } else if (signal) {
110
+ log(chalk.yellow(`Tailwind process killed by signal ${signal}`));
111
+ }
112
+ });
47
113
 
48
114
  /*= =============== Tailwind Plugin Order ================ */
49
- watch(path.join(config.extension_path, "assets"), { recursive: false }, async (evt, name) => {
115
+ watch(assetsDir, { recursive: false }, async (_evt: string, name: string) => {
50
116
  try {
51
- if (!name.match(/tailwind_pre_sort.css$/) || !fs.existsSync(filePath)) return;
117
+ if (!name.match(/tailwind_pre_sort\.css$/) || !fs.existsSync(filePath)) return;
52
118
  const file = fs.readFileSync(filePath, { encoding: "utf-8" });
53
119
 
54
120
  const top = file
@@ -61,7 +127,7 @@ export const runTailwindCSSWatcher = () => {
61
127
  .join("\n}")}\n`;
62
128
  const content = top + bottom;
63
129
 
64
- const classesInOrder = [];
130
+ const classesInOrder: string[] = [];
65
131
  const omitCompoundClasses = [":not", ":where", ">", "*", ","];
66
132
 
67
133
  content.split("\n").forEach((line) => {
@@ -86,10 +152,10 @@ export const runTailwindCSSWatcher = () => {
86
152
  }
87
153
  });
88
154
 
89
- writeCompareFile(path.join(config.extension_path, `assets/tailwind.css`), content);
155
+ writeCompareFile(path.join(config.extension_path, "assets", "tailwind.css"), content);
90
156
 
91
157
  if (process.env.SHOPIFY_ACCELERATE_THEME_OUTPUT_PATH) {
92
- writeCompareFile(path.join(config.theme_output_path, `assets/listify-dev-tailwind.css`), content);
158
+ writeCompareFile(path.join(config.theme_output_path, "assets", "listify-dev-tailwind.css"), content);
93
159
  }
94
160
 
95
161
  writeCompareFile(
@@ -105,7 +171,7 @@ export const runTailwindCSSWatcher = () => {
105
171
  )
106
172
  );
107
173
  } catch (err) {
108
- console.log(err);
174
+ log(chalk.red(`Post-processing error: ${err}`));
109
175
  }
110
176
  });
111
177
  };