Skip to content

Commit

Permalink
Merge pull request #514 from Shopify/ap.expand-liquid-check-unstaged
Browse files Browse the repository at this point in the history
Ensure no unstaged changes after expanding liquid
  • Loading branch information
adampetro authored Jan 29, 2025
2 parents de24310 + 8f92311 commit 1c7c55e
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 3,028 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- name: Install dependencies
run: yarn
- name: Expand liquid
run: yarn expand-liquid vanilla-js
run: CI=1 yarn expand-liquid vanilla-js
- name: Install workspace dependencies
run: yarn
- name: Generate types
run: yarn typegen
- name: Test
run: yarn test-js
run: yarn workspaces run test run
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install node dependencies
run: yarn
- name: Expand liquid
run: yarn expand-liquid rust
run: CI=1 yarn expand-liquid rust
- name: Run cargo fmt
run: cargo fmt --check
- name: Run clippy
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- name: Install dependencies
run: yarn
- name: Expand liquid
run: yarn expand-liquid typescript
run: CI=1 yarn expand-liquid typescript
- name: Install workspace dependencies
run: yarn
- name: Generate types
run: yarn typegen
- name: Test
run: yarn test-ts
run: yarn workspaces run test run
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
.env
.DS_Store
.yalc
yarn.lock

# These files are generated from Shopify CLI templating and should not be committed to this repo

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"scripts": {
"expand-liquid": "node ./util/expand-liquid.js",
"typegen": "yarn workspaces run graphql-code-generator --config package.json",
"test-js": "yarn expand-liquid vanilla-js && yarn workspaces run test run",
"test-ts": "yarn expand-liquid typescript && yarn workspaces run test run"
"test-js": "yarn expand-liquid vanilla-js && yarn && yarn typegen && yarn workspaces run test run",
"test-ts": "yarn expand-liquid typescript && yarn && yarn typegen && yarn workspaces run test run"
},
"private": true,
"workspaces": [
Expand Down
27 changes: 26 additions & 1 deletion util/expand-liquid.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import path from 'path';
import fs from 'node:fs/promises';
import { existsSync } from 'fs';
import toml from '@iarna/toml';
import { exec } from 'child_process';

async function expandLiquidTemplates(template, liquidData) {
const entries = await glob([path.join(template, "**/*.liquid")], {
Expand Down Expand Up @@ -106,6 +107,26 @@ async function expandExtensionLiquidTemplates(domainName, flavor) {
console.log();
}

function ensureNoGitChanges() {
exec('git status --porcelain', (error, stdout, _stderr) => {
if (error) {
console.error(`error calling \`git status\`: ${error}`);
process.exit(1);;
}
if (stdout) {
console.error('Untracked files detected:\n', stdout);
exec('git diff', (error, stdout, _stderr) => {
if (error) {
console.error(`error calling \`git diff\`: ${error}`);
} else {
console.log(`Git diff:\n${stdout}`);
}
process.exit(1);
});
}
});
}

const flavor = process.argv[2] || "vanilla-js";

const SAMPLE_APP_DIR = 'sample-apps';
Expand All @@ -116,4 +137,8 @@ for (const domain of DOMAINS) {
await expandExtensionLiquidTemplates(domain, flavor);
}

console.log('The above files should be added to .gitignore if they have not already been added.');
console.log('The above files should be added to .gitignore if they have not already been added.\n');

if (process.env.CI) {
ensureNoGitChanges();
}
Loading

0 comments on commit 1c7c55e

Please sign in to comment.