-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2/] Improvement: Introduce new command structure (#16)
- Loading branch information
1 parent
9f3876a
commit 16efd1e
Showing
26 changed files
with
554 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
packages/cli/src/commands/site/deploy/siteDeployCommand.mts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2023 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { consola } from "consola"; | ||
|
||
import { | ||
artifacts, | ||
ArtifactsSitesAdminV2Service, | ||
createConjureContext, | ||
thirdPartyApplicationService, | ||
} from "#net"; | ||
import archiver from "archiver"; | ||
import * as fs from "node:fs"; | ||
import { Readable } from "node:stream"; | ||
import { ExitProcessError } from "../../../ExitProcessError.js"; | ||
import { autoVersion as findAutoVersion } from "../../../util/autoVersion.js"; | ||
import type { SiteDeployArgs } from "./SiteDeployArgs.js"; | ||
|
||
export default async function siteDeployCommand( | ||
{ | ||
version, | ||
application, | ||
foundryUrl, | ||
autoVersion, | ||
gitTagPrefix, | ||
uploadOnly, | ||
directory, | ||
}: SiteDeployArgs, | ||
) { | ||
if (!version && !autoVersion) { | ||
throw new ExitProcessError( | ||
2, | ||
"Either version or autoVersion must be specified", | ||
); | ||
} | ||
|
||
const siteVersion = !version ? await findAutoVersion(gitTagPrefix) : version; | ||
if (autoVersion) { | ||
consola.info( | ||
`Auto version inferred next version to be: ${siteVersion}`, | ||
); | ||
} | ||
|
||
const stat = await fs.promises.stat(directory); | ||
if (!stat.isDirectory()) { | ||
consola.error("Specified path is not a directory"); | ||
throw new ExitProcessError(2); | ||
} | ||
|
||
consola.start("Zippping site files"); | ||
|
||
const archive = archiver("zip").directory(directory, false); | ||
|
||
await Promise.all([ | ||
artifacts.SiteAssetArtifactsService.uploadZippedSiteAsset( | ||
foundryUrl, | ||
application, | ||
siteVersion, | ||
Readable.toWeb(archive) as ReadableStream<any>, // This cast is because the dom fetch doesnt align type wise with streams | ||
), | ||
archive.finalize(), | ||
]); | ||
|
||
consola.success("Upload complete"); | ||
|
||
if (!uploadOnly) { | ||
const repositoryRid = await thirdPartyApplicationService | ||
.fetchWebsiteRepositoryRid(foundryUrl, application); | ||
|
||
const ctx = createConjureContext(foundryUrl, "/artifacts/api"); | ||
await ArtifactsSitesAdminV2Service.updateDeployedVersion( | ||
ctx, | ||
repositoryRid, | ||
{ siteVersion: { version: siteVersion } }, | ||
); | ||
|
||
consola.success(`Deployed ${siteVersion} successfully`); | ||
} else { | ||
consola.debug("Upload only mode enabled, skipping deployment"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.