Skip to content

Commit b49e401

Browse files
committed
Bash gymnastics
1 parent 5dfa7d2 commit b49e401

File tree

9 files changed

+55
-286
lines changed

9 files changed

+55
-286
lines changed

packages/ui-extensions/docs/surfaces/admin/build-ab-docs.sh

+27
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ else
3535
echo "If you need to update the 'unstable' version, run this command again without the '$API_VERSION' parameter."
3636
fi
3737

38+
# Read tsconfig.ab.docs.json and extract include/exclude patterns
39+
# Find all .doc.ts files in SRC_PATH
40+
FIND_CMD="find ./$SRC_PATH -name '*.doc.ts'"
41+
42+
# Store original files for restoration
43+
declare -a MODIFIED_FILES
44+
45+
echo "Replacing JSX/tsx references..."
46+
while IFS= read -r file; do
47+
if grep -q "JSX\|\.tsx" "$file"; then
48+
cp "$file" "$file.bak"
49+
MODIFIED_FILES+=("$file")
50+
run_sed 's/JSX/HTML/g' "$file"
51+
run_sed 's/\.tsx/\.html/g' "$file"
52+
fi
53+
done < <(eval "$FIND_CMD")
54+
55+
3856
COMPILE_DOCS="yarn tsc --project $DOCS_PATH/tsconfig.ab.docs.json --moduleResolution node --target esNext --module CommonJS && yarn generate-docs --overridePath ./$DOCS_PATH/typeOverride.json --input ./$DOCS_PATH/reference ./$SRC_PATH --typesInput ./$SRC_PATH --output ./$DOCS_PATH/generated"
3957
# COMPILE_STATIC_PAGES="yarn tsc $DOCS_PATH/staticPages/*.doc.ts --moduleResolution node --target esNext --module CommonJS && yarn generate-docs --isLandingPage --input ./$DOCS_PATH/staticPages --output ./$DOCS_PATH/generated"
4058

@@ -46,6 +64,13 @@ run_sed "s/typeof globalThis.HTMLElement/any/" $COMPONENTS_TS
4664
eval $COMPILE_DOCS
4765
build_exit=$?
4866

67+
# Restore original files
68+
for file in "${MODIFIED_FILES[@]}"; do
69+
if [ -f "$file.bak" ]; then
70+
mv "$file.bak" "$file"
71+
fi
72+
done
73+
4974
# Remove .doc.js files
5075
find ./ -name '*.doc*.js' -exec rm -r {} \;
5176
# Remove components.ts as it's no longer needed
@@ -58,6 +83,8 @@ fi
5883
# Make sure https://shopify.dev URLs are relative so they work in Spin.
5984
# See https://github.com/Shopify/generate-docs/issues/181
6085
run_sed 's/https:\/\/shopify.dev//gi' ./$DOCS_PATH/generated/generated_docs_data.json
86+
87+
6188
sed_exit=$?
6289
if [ $sed_exit -ne 0 ]; then
6390
fail_and_exit $sed_exit

packages/ui-extensions/docs/surfaces/admin/create-doc-files.sh

+22-22
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,33 @@ for componentName in "$@"; do
4040
docs_file="${folder}/${componentName}.doc.ts"
4141
lowercaseComponentName=$(echo "$componentName" | sed -E 's/([a-z])([A-Z])/\1-\2/g' | tr '[:upper:]' '[:lower:]')
4242

43-
# Create TypeScript example file
44-
ts_example="${examples_dir}/basic-${lowercaseComponentName}.example.ts"
45-
if [ ! -f "$ts_example" ]; then
46-
cat << EOF > "$ts_example"
47-
export default function extension() {
48-
const ${componentName} = document.createElement('s-${lowercaseComponentName}');
49-
// Add your s-${componentName} implementation here
50-
document.body.appendChild(${componentName});
51-
};
52-
EOF
53-
echo "Created TS example file for ${componentName}"
54-
fi
55-
5643
# Create TSX example file
5744
tsx_example="${examples_dir}/basic-${lowercaseComponentName}.example.tsx"
5845
if [ ! -f "$tsx_example" ]; then
5946
cat << EOF > "$tsx_example"
60-
import '@shopify/ui-extensions/preact';
61-
import {render} from 'preact';
62-
63-
export default function extension() {
64-
render(<s-${lowercaseComponentName} />, document.body);
47+
<s-${lowercaseComponentName}></s-${lowercaseComponentName}>
6548
}
6649
EOF
6750
echo "Created TSX example file for ${componentName}"
6851
fi
6952

53+
# Create preview file
54+
preview_file="${examples_dir}/preview.html"
55+
if [ ! -f "$preview_file" ]; then
56+
cat << EOF > "$preview_file"
57+
<!DOCTYPE html>
58+
<html>
59+
<head>
60+
<script src="https://cdn.shopify.com/shopifycloud/app-bridge-ui-experimental.js"></script>
61+
</head>
62+
<body>
63+
<s-${lowercaseComponentName}></s-${lowercaseComponentName}>
64+
</body>
65+
</html>
66+
EOF
67+
echo "Created preview file for ${componentName}"
68+
fi
69+
7070
if [ ! -f "$docs_file" ]; then
7171
cat << EOF > "$docs_file"
7272
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs';
@@ -93,14 +93,14 @@ const data: ReferenceEntityTemplateSchema = {
9393
title: 'TODO: add example title',
9494
tabs: [
9595
{
96-
title: 'Preact',
96+
title: 'JSX',
9797
code: './examples/basic-${lowercaseComponentName}.example.tsx',
9898
language: 'jsx',
9999
},
100100
{
101-
title: 'JS',
102-
code: './examples/basic-${lowercaseComponentName}.example.ts',
103-
language: 'js',
101+
title: 'Preview',
102+
code: './examples/preview.html',
103+
language: 'preview',
104104
},
105105
],
106106
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<s-link href="app://baz">Link to app path</s-link>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<s-link href="https://www.shopify.ca/climate/sustainability-fund">
2+
Sustainability fund
3+
</s-link>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<s-link href="/baz">Link relative to current path</s-link>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<s-link href="shopify://admin/orders">Shop's orders</s-link>;

packages/ui-extensions/src/surfaces/admin/components/copy.js

-101
This file was deleted.

packages/ui-extensions/src/surfaces/admin/components/create.js

-78
This file was deleted.

packages/ui-extensions/src/surfaces/admin/components/wrap.js

-85
This file was deleted.

0 commit comments

Comments
 (0)