@bleedingdev/modern-js-sandpack-react 3.2.0-ultramodern.102 → 3.2.0-ultramodern.104

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.
@@ -1,5 +1,4 @@
1
- import { renderString } from '@modern-js/codesmith-api-handlebars';
2
- import { fs } from '@modern-js/codesmith-utils/fs-extra';
1
+ import fs from 'node:fs';
3
2
  import { createRequire } from 'module';
4
3
  import path from 'path';
5
4
  import recursive from 'recursive-readdir';
@@ -14,6 +13,80 @@ const IgnoreFiles = [
14
13
  'README.md',
15
14
  ];
16
15
 
16
+ function renderTemplate(
17
+ template: string,
18
+ data: Record<string, unknown>,
19
+ ): string {
20
+ type ConditionalKind = 'if' | 'unless';
21
+ const tagRegex = /\{\{(~?)(#if|#unless|\/if|\/unless)(?:\s+(\w+))?(~?)\}\}/g;
22
+
23
+ function renderConditionals(
24
+ startIndex: number,
25
+ expectedClose?: ConditionalKind,
26
+ ): {
27
+ rendered: string;
28
+ nextIndex: number;
29
+ } {
30
+ let rendered = '';
31
+ let cursor = startIndex;
32
+ tagRegex.lastIndex = startIndex;
33
+
34
+ while (true) {
35
+ const match = tagRegex.exec(template);
36
+ if (!match) {
37
+ return {
38
+ rendered: rendered + template.slice(cursor),
39
+ nextIndex: template.length,
40
+ };
41
+ }
42
+
43
+ const [raw, , tag, condition, rightTrim] = match;
44
+ const tagIndex = match.index;
45
+ rendered += template.slice(cursor, tagIndex);
46
+ cursor = tagIndex + raw.length;
47
+
48
+ if (tag === '#if' || tag === '#unless') {
49
+ const kind: ConditionalKind = tag === '#if' ? 'if' : 'unless';
50
+ const innerResult = renderConditionals(cursor, kind);
51
+ cursor = innerResult.nextIndex;
52
+ tagRegex.lastIndex = cursor;
53
+
54
+ const conditionValue = Boolean(data[condition ?? '']);
55
+ const shouldInclude = kind === 'if' ? conditionValue : !conditionValue;
56
+ if (shouldInclude) {
57
+ rendered += innerResult.rendered;
58
+ }
59
+ continue;
60
+ }
61
+
62
+ if (tag === '/if' || tag === '/unless') {
63
+ const kind: ConditionalKind = tag === '/if' ? 'if' : 'unless';
64
+ if (expectedClose === kind) {
65
+ let nextIndex = cursor;
66
+ if (rightTrim === '~') {
67
+ const trailingWhitespace = /^\s*/u.exec(template.slice(nextIndex));
68
+ nextIndex += trailingWhitespace?.[0].length ?? 0;
69
+ }
70
+ return {
71
+ rendered,
72
+ nextIndex,
73
+ };
74
+ }
75
+ rendered += raw;
76
+ }
77
+ }
78
+ }
79
+
80
+ let result = renderConditionals(0).rendered;
81
+ const varRegex = /\{\{(\w+)\}\}/g;
82
+ result = result.replace(varRegex, (match, key) => {
83
+ const value = data[key];
84
+ return value !== undefined && value !== null ? String(value) : match;
85
+ });
86
+
87
+ return result;
88
+ }
89
+
17
90
  export async function handleTemplate(
18
91
  templatePath: string,
19
92
  data: Record<string, any> = {},
@@ -35,7 +108,7 @@ export async function handleTemplate(
35
108
  `${routerPrefix}${file
36
109
  .replace('.handlebars', fileExtra)
37
110
  .replace('npmrc', '.npmrc')}`.replace('language', 'ts')
38
- ] = `${renderString(fs.readFileSync(filePath, 'utf-8'), data)}`;
111
+ ] = renderTemplate(fs.readFileSync(filePath, 'utf-8'), data);
39
112
  } else {
40
113
  files[`${routerPrefix}${file}`] = `${fs.readFileSync(
41
114
  filePath,
@@ -70,6 +143,25 @@ async function handleCreateTemplate() {
70
143
 
71
144
  const files = await handleTemplate(templateDir, {
72
145
  packageName: 'modern-app',
146
+ adapterRstestVersion: version,
147
+ appToolsVersion: version,
148
+ bffRuntime: 'effect',
149
+ enableBff: true,
150
+ enableTailwind: true,
151
+ isSubproject: false,
152
+ isTanstackRouter: true,
153
+ pluginBffVersion: version,
154
+ pluginI18nVersion: version,
155
+ pluginTanstackVersion: version,
156
+ pnpmVersion: '11.5.0',
157
+ routerRuntimeImport: '@modern-js/plugin-tanstack/runtime',
158
+ runtimeVersion: version,
159
+ tailwindPostcssVersion: '4.3.0',
160
+ tailwindVersion: '4.3.0',
161
+ tanstackRouterVersion: '1.170.11',
162
+ tsconfigVersion: version,
163
+ useEffectBff: true,
164
+ useHonoBff: false,
73
165
  version,
74
166
  });
75
167