Skip to content

Commit

Permalink
Support extraction to permanent space (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
rnreekez authored Jul 24, 2021
1 parent d477eab commit 3628edd
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default async function caxa({
),
removeBuildDirectory = true,
uncompressionMessage,
temporaryDirectory
}: {
input: string;
output: string;
Expand All @@ -59,6 +60,7 @@ export default async function caxa({
identifier?: string;
removeBuildDirectory?: boolean;
uncompressionMessage?: string;
temporaryDirectory?: boolean;
}): Promise<void> {
if (!(await fs.pathExists(input)) || !(await fs.lstat(input)).isDirectory())
throw new Error(
Expand Down Expand Up @@ -181,7 +183,7 @@ export default async function caxa({
await appendTarballOfBuildDirectoryToOutput();
await fs.appendFile(
output,
"\n" + JSON.stringify({ identifier, command, uncompressionMessage })
"\n" + JSON.stringify({ identifier, command, uncompressionMessage, temporaryDirectory })
);
}

Expand Down Expand Up @@ -247,6 +249,12 @@ if (require.main === module)
"-m, --uncompression-message <message>",
"[Advanced] A message to show when uncompressing, for example, ‘This may take a while to run the first time, please wait...’."
)
.option(
"-t, --temporary-directory",
"[Advanced] Extract application to temporary OS space.",
true
)
.option("-T, --no-temporary-directory")
.arguments("<command...>")
.description("Package Node.js applications into executable binaries.", {
command:
Expand Down Expand Up @@ -285,6 +293,7 @@ Examples:
identifier,
removeBuildDirectory,
uncompressionMessage,
temporaryDirectory
}: {
input: string;
output: string;
Expand All @@ -297,6 +306,7 @@ Examples:
identifier?: string;
removeBuildDirectory?: boolean;
uncompressionMessage?: string;
temporaryDirectory?: boolean;
}
) => {
try {
Expand All @@ -313,6 +323,7 @@ Examples:
identifier,
removeBuildDirectory,
uncompressionMessage,
temporaryDirectory
});
} catch (error) {
console.error(error.message);
Expand Down
Binary file modified stubs/stub--darwin--arm64
Binary file not shown.
Binary file modified stubs/stub--darwin--x64
Binary file not shown.
Binary file modified stubs/stub--linux--arm
Binary file not shown.
Binary file modified stubs/stub--linux--arm64
Binary file not shown.
Binary file modified stubs/stub--linux--x64
Binary file not shown.
Binary file modified stubs/stub--win32--x64
Binary file not shown.
13 changes: 11 additions & 2 deletions stubs/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,24 @@ func main() {
Identifier string `json:"identifier"`
Command []string `json:"command"`
UncompressionMessage string `json:"uncompressionMessage"`
TemporaryDirectory bool `json:"temporaryDirectory"`
}
if err := json.Unmarshal(footerString, &footer); err != nil {
log.Fatalf("caxa stub: Failed to parse JSON in footer: %v", err)
}

var extractionDirectory string = os.TempDir()
if footer.TemporaryDirectory == false {
extractionDirectory, err = os.UserCacheDir()
if err != nil {
log.Fatalf("caxa stub: Failed to find user cache directory: %v", err)
}
}

var applicationDirectory string
for extractionAttempt := 0; true; extractionAttempt++ {
lock := path.Join(os.TempDir(), "caxa/locks", footer.Identifier, strconv.Itoa(extractionAttempt))
applicationDirectory = path.Join(os.TempDir(), "caxa/applications", footer.Identifier, strconv.Itoa(extractionAttempt))
lock := path.Join(extractionDirectory, "caxa/locks", footer.Identifier, strconv.Itoa(extractionAttempt))
applicationDirectory = path.Join(extractionDirectory, "caxa/applications", footer.Identifier, strconv.Itoa(extractionAttempt))
applicationDirectoryFileInfo, err := os.Stat(applicationDirectory)
if err != nil && !errors.Is(err, os.ErrNotExist) {
log.Fatalf("caxa stub: Failed to find information about the application directory: %v", err)
Expand Down

0 comments on commit 3628edd

Please sign in to comment.