-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathwriteManifest.R
88 lines (82 loc) · 2.95 KB
/
writeManifest.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#' Create a `manifest.json`
#'
#' @description
#' Use `writeManifest()` to generate a `manifest.json`. Among other things,
#' you can commit this file to git to activate
#' [Git-Backed content](https://docs.posit.co/connect/user/git-backed/)
#' for Posit Connect.
#'
#' `manifest.json` contains a list of all files in the app along with their
#' dependencies, so you will need to re-run `writeManifest()` when either of
#' these change.
#'
#' @inheritParams deployApp
#' @param contentCategory Set this to `"site"` if you'd deploy with
#' [deploySite()]; otherwise leave as is.
#' @param verbose If `TRUE`, prints detailed progress messages.
#' @param quiet If `FALSE`, prints progress messages.
#' @export
writeManifest <- function(appDir = getwd(),
appFiles = NULL,
appFileManifest = NULL,
appPrimaryDoc = NULL,
appMode = NULL,
contentCategory = NULL,
python = NULL,
forceGeneratePythonEnvironment = FALSE,
quarto = NA,
image = NULL,
envManagement = NULL,
envManagementR = NULL,
envManagementPy = NULL,
verbose = FALSE,
quiet = FALSE) {
appFiles <- listDeploymentFiles(
appDir,
appFiles = appFiles,
appFileManifest = appFileManifest
)
appMetadata <- appMetadata(
appDir = appDir,
appFiles = appFiles,
appPrimaryDoc = appPrimaryDoc,
quarto = quarto,
appMode = appMode,
contentCategory = contentCategory,
)
# copy files to bundle dir to stage
bundleDir <- bundleAppDir(
appDir = appDir,
appFiles = appFiles,
appPrimaryDoc = appMetadata$appPrimaryDoc
)
defer(unlink(bundleDir, recursive = TRUE))
python <- getPython(python)
pythonConfig <- pythonConfigurator(python, forceGeneratePythonEnvironment)
# generate the manifest and write it into the bundle dir
manifest <- createAppManifest(
appDir = bundleDir,
appMetadata = appMetadata,
pythonConfig = pythonConfig,
retainPackratDirectory = FALSE,
image = image,
envManagement = envManagement,
envManagementR = envManagementR,
envManagementPy = envManagementPy,
verbose = verbose,
quiet = quiet
)
manifestJson <- toJSON(manifest)
manifestPath <- file.path(appDir, "manifest.json")
writeLines(manifestJson, manifestPath, useBytes = TRUE)
requirementsFilename <- manifest$python$package_manager$package_file
if (is.null(requirementsFilename)) {
requirementsFilename <- "requirements.txt"
}
srcRequirementsFile <- file.path(bundleDir, requirementsFilename)
dstRequirementsFile <- file.path(appDir, requirementsFilename)
if (file.exists(srcRequirementsFile) && !file.exists(dstRequirementsFile)) {
file.copy(srcRequirementsFile, dstRequirementsFile)
}
invisible()
}