create-preview-workflow 1.0.3 → 1.0.5

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.
Files changed (2) hide show
  1. package/index.js +64 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -7,15 +7,32 @@ const prompts = require("prompts");
7
7
  (async () => {
8
8
  const response = await prompts([
9
9
  {
10
- type: "text",
10
+ type: "select",
11
+ name: "action",
12
+ message: "What would you like to do with the shared directory?",
13
+ choices: [
14
+ {
15
+ title: "Create/Update - Sync content to shared directory",
16
+ value: "sync",
17
+ },
18
+ {
19
+ title: "Delete - Remove content from shared directory",
20
+ value: "delete",
21
+ },
22
+ ],
23
+ },
24
+ {
25
+ type: (prev) => (prev === "sync" ? "text" : null),
11
26
  name: "sourcePath",
12
27
  message:
13
28
  "Enter the source directory to sync (e.g., 2_scripts) without leading slash:",
14
29
  },
15
-
16
30
  ]);
17
31
 
18
- const workflow = `# .github/workflows/sync.yml
32
+ let workflow;
33
+
34
+ if (response.action === "sync") {
35
+ workflow = `# .github/workflows/sync.yml
19
36
  name: Sync Directory
20
37
 
21
38
  on:
@@ -36,9 +53,9 @@ jobs:
36
53
  echo "REPO=\$REPO" >> \$GITHUB_ENV
37
54
  echo "DIR=\$DIR" >> \$GITHUB_ENV
38
55
 
39
- - name: Clone target repo
56
+ - name: Clone target repo and sync content
40
57
  run: |
41
- git clone https://${{ secrets.GH_SYNC_TOKEN }}@github.com/ssm123ssm/preview.git
58
+ git clone https://\${{ secrets.GH_SYNC_TOKEN }}@github.com/ssm123ssm/preview.git
42
59
  rm -rf preview/public/protected/\$DIR
43
60
  mkdir -p preview/public/protected/\$DIR
44
61
  cp -r ${response.sourcePath}/. preview/public/protected/\$DIR/
@@ -47,18 +64,58 @@ jobs:
47
64
  git config user.email "actions@github.com"
48
65
  git add .
49
66
  if ! git diff --cached --quiet; then
50
- git commit -m "Sync from source repo"
67
+ git commit -m "Sync content from source repo"
68
+ git push
69
+ else
70
+ echo "No changes to commit"
71
+ fi
72
+ `;
73
+ } else {
74
+ workflow = `# .github/workflows/sync.yml
75
+ name: Delete Directory
76
+
77
+ on:
78
+ push:
79
+
80
+ jobs:
81
+ delete:
82
+ runs-on: ubuntu-latest
83
+ steps:
84
+ - uses: actions/checkout@v3
85
+
86
+ - name: Set variables
87
+ run: |
88
+ USER="\${{ github.actor }}"
89
+ REPO="\${{ github.event.repository.name }}"
90
+ DIR="\${USER}@\${REPO}"
91
+ echo "USER=\$USER" >> \$GITHUB_ENV
92
+ echo "REPO=\$REPO" >> \$GITHUB_ENV
93
+ echo "DIR=\$DIR" >> \$GITHUB_ENV
94
+
95
+ - name: Clone target repo and remove directory
96
+ run: |
97
+ git clone https://\${{ secrets.GH_SYNC_TOKEN }}@github.com/ssm123ssm/preview.git
98
+ rm -rf preview/public/protected/\$DIR
99
+ cd preview
100
+ git config user.name "GitHub Actions"
101
+ git config user.email "actions@github.com"
102
+ git add .
103
+ if ! git diff --cached --quiet; then
104
+ git commit -m "Remove directory from shared repo"
51
105
  git push
52
106
  else
53
107
  echo "No changes to commit"
54
108
  fi
55
109
  `;
110
+ }
56
111
 
57
112
  const destDir = path.join(process.cwd(), ".github", "workflows");
58
113
  fs.mkdirSync(destDir, { recursive: true });
59
114
  fs.writeFileSync(path.join(destDir, "sync.yml"), workflow);
60
115
 
116
+ const actionText =
117
+ response.action === "sync" ? "sync content to" : "delete content from";
61
118
  console.log(
62
- "✅ GitHub Actions workflow for Preview created at .github/workflows/sync.yml. Make sure to add the GH_SYNC_TOKEN secret in your repository settings."
119
+ `✅ GitHub Actions workflow to ${actionText} shared directory created at .github/workflows/sync.yml. Make sure to add the GH_SYNC_TOKEN secret in your repository settings.`
63
120
  );
64
121
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-preview-workflow",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "bin": {
5
5
  "create-preview-workflow": "index.js"
6
6
  },