@fugood/bricks-project 2.21.0-beta.16 → 2.21.0-beta.16-1

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.
package/api/instance.ts CHANGED
@@ -64,7 +64,7 @@ export const deployApp = async (
64
64
  stage: Stage,
65
65
  appId: string,
66
66
  config: Config,
67
- lastCommitId: string,
67
+ lastCommitId?: string,
68
68
  ) => {
69
69
  const app = await pullApp(stage, appId)
70
70
  if (app.config?.bricks_project_last_commit_id === lastCommitId)
@@ -135,7 +135,7 @@ export const deployModule = async (
135
135
  stage: Stage,
136
136
  modId: string,
137
137
  config: Config,
138
- lastCommitId: string,
138
+ lastCommitId?: string,
139
139
  ) => {
140
140
  const mod = await pullModule(stage, modId)
141
141
  if (mod.config?.bricks_project_last_commit_id === lastCommitId)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fugood/bricks-project",
3
- "version": "2.21.0-beta.16",
3
+ "version": "2.21.0-beta.16-1",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "build": "node scripts/build.js"
@@ -12,6 +12,5 @@
12
12
  "escodegen": "^2.1.0",
13
13
  "lodash": "^4.17.4",
14
14
  "uuid": "^8.3.1"
15
- },
16
- "gitHead": "5a3d442c4eca74ab88878feac51c927c3fdbd6f6"
15
+ }
17
16
  }
package/tools/deploy.ts CHANGED
@@ -3,10 +3,21 @@ import { deployApp, deployModule } from '../api'
3
3
 
4
4
  const cwd = process.cwd()
5
5
 
6
- const unstagedChanges = await $`cd ${cwd} && git diff --name-only --diff-filter=ACMR`.text()
7
- if (unstagedChanges) throw new Error('Unstaged changes found, please commit or stash your changes before deploying')
6
+ const { exitCode } = await $`cd ${cwd} && git status`.nothrow()
7
+ const isGitRepo = exitCode === 0
8
+
9
+ let commitId = ''
10
+ if (isGitRepo) {
11
+ const unstagedChanges = await $`cd ${cwd} && git diff --name-only --diff-filter=ACMR`.text()
12
+ if (unstagedChanges)
13
+ throw new Error('Unstaged changes found, please commit or stash your changes before deploying')
14
+
15
+ commitId = (await $`cd ${cwd} && git rev-parse HEAD`.text()).trim()
16
+ } else {
17
+ const confirmContinue = prompt('No git repository found, continue? (y/n)')
18
+ if (confirmContinue !== 'y') throw new Error('Deployment cancelled')
19
+ }
8
20
 
9
- const commitId = (await $`cd ${cwd} && git rev-parse HEAD`.text()).trim()
10
21
  const app = await Bun.file(`${cwd}/application.json`).json()
11
22
  const stage = app.stage || 'production'
12
23
  const config = await Bun.file(`${cwd}/.bricks/build/application-config.json`).json()
package/tools/pull.ts CHANGED
@@ -15,24 +15,34 @@ const { files, lastCommitId } =
15
15
  ? await pullModuleProject(stage, app.id)
16
16
  : await pullApplicationProject(stage, app.id)
17
17
 
18
- const found = (await $`cd ${cwd} && git rev-list -1 ${lastCommitId}`.nothrow().text())
19
- .trim()
20
- .match(/^[a-f0-9]{40}$/)
18
+ const { exitCode } = await $`cd ${cwd} && git status`.nothrow()
19
+ const isGitRepo = exitCode === 0
21
20
 
22
- const commitId = (await $`cd ${cwd} && git rev-parse HEAD`.text()).trim()
21
+ let useMain = false
22
+ if (isGitRepo) {
23
+ const found = (await $`cd ${cwd} && git rev-list -1 ${lastCommitId}`.nothrow().text())
24
+ .trim()
25
+ .match(/^[a-f0-9]{40}$/)
23
26
 
24
- if (commitId === lastCommitId) throw new Error('Commit not changed')
27
+ const commitId = (await $`cd ${cwd} && git rev-parse HEAD`.text()).trim()
25
28
 
26
- const branchName = 'BRICKS_PROJECT_try-pull-application'
29
+ if (commitId === lastCommitId) throw new Error('Commit not changed')
27
30
 
28
- await $`cd ${cwd} && git branch -D ${branchName}`.nothrow()
31
+ const branchName = 'BRICKS_PROJECT_try-pull-application'
29
32
 
30
- let useMain = false
31
- if (found) {
32
- await $`cd ${cwd} && git checkout -b ${branchName} ${lastCommitId}`.nothrow()
33
+ await $`cd ${cwd} && git branch -D ${branchName}`.nothrow()
34
+
35
+ if (found) {
36
+ await $`cd ${cwd} && git checkout -b ${branchName} ${lastCommitId}`.nothrow()
37
+ } else {
38
+ await $`cd ${cwd} && git checkout -b ${branchName}`
39
+ useMain = true
40
+ }
33
41
  } else {
34
- await $`cd ${cwd} && git checkout -b ${branchName}`
35
- useMain = true
42
+ const confirmContinue = prompt(
43
+ 'No git repository found, so it will not be safe to pull, continue? (y/n)',
44
+ )
45
+ if (confirmContinue !== 'y') throw new Error('Pull cancelled')
36
46
  }
37
47
 
38
48
  await Promise.all(
@@ -44,8 +54,10 @@ await Promise.all(
44
54
  ),
45
55
  )
46
56
 
47
- await $`cd ${cwd} && git add .`
48
- await $`cd ${cwd} && git commit -m 'Apply ${app.name} file changes'`
49
- if (!useMain) {
50
- await $`cd ${cwd} && git merge main`
57
+ if (isGitRepo) {
58
+ await $`cd ${cwd} && git add .`
59
+ await $`cd ${cwd} && git commit -m 'Apply ${app.name} file changes'`
60
+ if (!useMain) {
61
+ await $`cd ${cwd} && git merge main`
62
+ }
51
63
  }