Skip to content

Commit

Permalink
feature/improve docs and cli messaging, change package.json script to…
Browse files Browse the repository at this point in the history
… a new project value
  • Loading branch information
dogfrogfog committed Nov 12, 2024
1 parent b4e6510 commit 1ef365f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/new-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ jobs:
echo -e "\nREPO_PROD_BRANCH=\"main\"\nREPO_TYPE=\"github\"\nREPO_ID=${{ github.event.repository.id }}\nREPO_NAME=${{ github.repository }}" >> apps/sanity/.env
echo -e "\nREPO_PROD_BRANCH=\"main\"\nREPO_TYPE=\"github\"\nREPO_ID=${{ github.event.repository.id }}\nREPO_NAME=${{ github.repository }}" >> apps/storyblok/.env
- name: Remove unnecessary scripts
run: |
jq 'del(.scripts["pull-schemas"]) | del(.scripts["pull-stories"])' apps/storyblok/package.json > apps/storyblok/package.json.tmp
mv apps/storyblok/package.json.tmp apps/storyblok/package.json
# - name: Remove unnecessary scripts
# run: |
# jq 'del(.scripts["pull-stories"])' apps/storyblok/package.json > apps/storyblok/package.json.tmp
# mv apps/storyblok/package.json.tmp apps/storyblok/package.json
- name: Commit, push, and remove GitHub Actions workflow
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,19 @@ cd apps/sanity
7. Generate types for added section

```bash
# For Storyblok you will additionally
# need to log into CLI
pnpm sb-login

pnpm gen:types
```

⚠️If you generating types for Storyblok, make sure you logged into CLI⚠️

```bash

```

### Update existing section

1. Updata design
Expand Down
23 changes: 18 additions & 5 deletions apps/storyblok/CLI/sb.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
createProjectDeployment,
createVercelProject,
} from "./services/vercel.mjs";
import { modifyFile } from "./utils/file.mjs";
import { openUrlAndConfirm } from "./utils/open.mjs";
import {
promptForProjectName,
Expand All @@ -29,10 +30,6 @@ const main = async () => {
colorText("ℹ️ Configuration will be saved to .env.local", "yellow"),
);

execSync("rm -rf ../../sanity", {
stdio: "ignore",
});

try {
const sbPersonalAccessToken = await promptForToken(
"SB_PERSONAL_ACCESS_TOKEN",
Expand Down Expand Up @@ -145,14 +142,30 @@ const main = async () => {
"Successfully created Vercel production and preview deployments 🎉",
);

// Success message
if (!process.env.DEBUG) {
spinner.start("Updating apps/storyblok/package.json ⏳");
modifyFile("../package.json", "293915", spaceId);
spinner.succeed("apps/storyblok/package.json updated ✅");

spinner.start("Removing Sanity folder ⏳");
execSync("rm -rf ../../sanity", {
stdio: "ignore",
});
spinner.succeed("Sanity folder removed ✅");
}

console.log(
colorText(
"\nStoryblok project setup completed successfully! 🎉",
"green",
),
);
console.log(
colorText(
"\nNow wait for production and preview deployments to finish, and use your new platform! ⏳",
"green",
),
);
console.log(
colorText("Storyblok dashboard:", "cyan"),
colorText(
Expand Down
2 changes: 0 additions & 2 deletions apps/storyblok/CLI/services/storyblok.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,6 @@ export async function uploadBackupStories(spaceId) {
};

if (story.slug === "home") {
console.log("updated story data");

const homeStory = await getStoryBySlug(spaceId, "home");
await updateStory(spaceId, homeStory.id, storyData);
} else {
Expand Down
19 changes: 19 additions & 0 deletions apps/storyblok/CLI/utils/file.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import fs from "fs";

export function modifyFile(path, oldText, newText) {
fs.readFile(path, "utf8", (err, data) => {
if (err) {
console.error(err);
return;
}

const modifiedData = data.replace(oldText, newText);

fs.writeFile(path, modifiedData, (err) => {
if (err) {
console.error(err);
return;
}
});
});
}

0 comments on commit 1ef365f

Please sign in to comment.