Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions configuration
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export DENO=v1.46.3
# TODO figure out where 0.1.41 apple silicon libs are available
export DENO_DOM=v0.1.41-alpha-artifacts
export PANDOC=3.6.3
export DARTSASS=1.85.1
export ESBUILD=0.19.12
export DARTSASS=1.87.0
export ESBUILD=0.25.3
export TYPST=0.13.0


Expand Down
9 changes: 7 additions & 2 deletions package/src/cmd/pkg-cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import { Command } from "cliffy/command/mod.ts";
import { join } from "../../../src/deno_ral/path.ts";

import { printConfiguration } from "../common/config.ts";
import { configurationAST, printConfiguration } from "../common/config.ts";

import {
Configuration,
kValidArch,
kValidOS,
readConfiguration,
} from "../common/config.ts";
import { logPandocJson } from "../../../src/core/log.ts";

export const kLogLevel = "logLevel";
export const kVersion = "setVersion";
Expand Down Expand Up @@ -49,7 +50,11 @@ export function packageCommand(run: (config: Configuration) => Promise<void>) {
Deno.env.set("QUARTO_DEBUG", "true");

// Print the configuration
printConfiguration(config);
try {
await logPandocJson(configurationAST(config));
} catch (e) {
printConfiguration(config);
}

// Run the command
await run(config);
Expand Down
23 changes: 9 additions & 14 deletions package/src/common/archive-binary-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import { join } from "../../../src/deno_ral/path.ts";
import { info } from "../../../src/deno_ral/log.ts";
import { logPandoc } from "../../../src/core/log.ts";

import { execProcess } from "../../../src/core/process.ts";
import { Configuration, withWorkingDir } from "./config.ts";
Expand Down Expand Up @@ -34,7 +35,7 @@ export function archiveUrl(
// Archives dependencies (if they are not present in the archive already)
export async function archiveBinaryDependencies(_config: Configuration) {
await withWorkingDir(async (workingDir) => {
info(`Updating binary dependencies...\n`);
await logPandoc(`## Updating binary dependencies`);

for (const dependency of kDependencies) {
await archiveBinaryDependency(dependency, workingDir);
Expand All @@ -45,7 +46,7 @@ export async function archiveBinaryDependencies(_config: Configuration) {
// Archives dependencies (if they are not present in the archive already)
export async function checkBinaryDependencies(_config: Configuration) {
await withWorkingDir(async (workingDir) => {
info(`Updating binary dependencies...\n`);
await logPandoc(`## Checking binary dependencies`);

for (const dependency of kDependencies) {
await checkBinaryDependency(dependency, workingDir);
Expand Down Expand Up @@ -99,10 +100,9 @@ export async function archiveBinaryDependency(
dependency: Dependency,
workingDir: string,
) {
info(`** ${dependency.name} ${dependency.version} **`);
await logPandoc(`## ${dependency.name} ${dependency.version}\n\nChecking archive status...`, "markdown");

const dependencyBucketPath = `${dependency.bucket}/${dependency.version}`;
info("Checking archive status...\n");

const archive = async (
architectureDependency: ArchitectureDependency,
Expand All @@ -117,7 +117,7 @@ export async function archiveBinaryDependency(

const dependencyAwsPath =
`${kBucket}/${dependencyBucketPath}/${platformDep.filename}`;
info(`Checking ${dependencyAwsPath}`);
await logPandoc(`Checking \`${dependencyAwsPath}\``, "markdown");
const response = await s3cmd("ls", [dependencyAwsPath]);
if (response?.includes('Unable to locate credentials')) {
throw new Error("Unable to locate S3 credentials, please try again.");
Expand All @@ -126,8 +126,8 @@ export async function archiveBinaryDependency(

if (!response) {
// This dependency doesn't exist, archive it
info(
`Archiving ${dependencyBucketPath} - ${platformDep.filename}`,
await logPandoc(
`Archiving \`${dependencyBucketPath}\` - ${platformDep.filename}`,
);

// Download the file
Expand All @@ -144,23 +144,18 @@ export async function archiveBinaryDependency(
"--acl",
"public-read",
]);

info(`(Reponse): ${result}`);

info(` (Response): ${result}`);
} else {
info(`${dependencyAwsPath} already archived.`);
info(` ${dependencyAwsPath.split("/").slice(-1)[0]} already archived.\n`);
}
}
}
};

for (const arch of Object.keys(dependency.architectureDependencies)) {
info(`Archiving ${dependency.name}`);
const archDep = dependency.architectureDependencies[arch];
await archive(archDep);
}

info("");
}

async function s3cmd(cmd: string, args: string[]) {
Expand Down
32 changes: 32 additions & 0 deletions package/src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { info } from "../../../src/deno_ral/log.ts";
import { getEnv } from "../util/utils.ts";

import { os as platformOs } from "../../../src/deno_ral/platform.ts"
import * as Pandoc from "../../../src/core/pandoc/json.ts";
import { fromObjects } from "../../../src/core/pandoc/table.ts";

// The core configuration for the packaging process
export interface Configuration extends PlatformConfiguration {
Expand Down Expand Up @@ -116,6 +118,36 @@ export function readConfiguration(
};
}

export function configurationAST(config: Configuration): Pandoc.Block[] {
const makeObject = (
obj: {
key: string,
value: string
},
) => ({
"key": [Pandoc.plain([Pandoc.str(obj.key)])],
"value": [Pandoc.plain([Pandoc.code(obj.value)])]
});
const configTable = fromObjects([
{key: "OS", value: config.os},
{key: "Arch", value: config.arch},
{key: "Version", value: config.version},
{key: "Cwd", value: Deno.cwd()},
{key: "Package folder (build source)", value: config.directoryInfo.pkg},
{key: "Dist folder (output folder)", value: config.directoryInfo.dist},
{key: "Bin folder", value: config.directoryInfo.bin},
{key: "Share folder", value: config.directoryInfo.share},
{key: "Package working folder", value: config.directoryInfo.pkgWorking.root},
].map(makeObject), undefined, [
Pandoc.colspec("AlignLeft", {t: "ColWidth", c: 0.3}),
Pandoc.colspec("AlignLeft", {t: "ColWidth", c: 0.6}),
]);
return [
Pandoc.header(2, [Pandoc.str("Configuration:")]),
configTable,
];
}

export function printConfiguration(config: Configuration) {
info("");
info("******************************************");
Expand Down
42 changes: 42 additions & 0 deletions src/core/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import { lines } from "./text.ts";
import { debug, error, getLogger, setup, warning } from "../deno_ral/log.ts";
import { asErrorEx, InternalError } from "./lib/error.ts";
import { onCleanup } from "./cleanup.ts";
import { execProcess } from "./process.ts";
import { pandocBinaryPath } from "./resources.ts";
import { Block, pandoc } from "./pandoc/json.ts";

export type LogLevel = "DEBUG" | "INFO" | "WARN" | "ERROR";

Expand Down Expand Up @@ -459,3 +462,42 @@ const levelMap: Record<
warning: "WARN",
error: "ERROR",
};

export async function logPandocJson(
blocks: Block[],
) {
const src = JSON.stringify(pandoc({}, blocks), null, 2);
return logPandoc(src, "json");
}

const getColumns = () => {
try {
// Catch error in none tty mode: Inappropriate ioctl for device (os error 25)
return Deno.consoleSize().columns ?? 130;
} catch (_error) {
return 130;
}
};

export async function logPandoc(
src: string,
format: string = "markdown",
) {
const cols = getColumns();
const result = await execProcess({
cmd: [
pandocBinaryPath(),
"-f",
format,
"-t",
"ansi",
`--columns=${cols}`,
],
stdout: "piped",
}, src);
if (result.code !== 0) {
error(result.stderr);
} else {
log.info(result.stdout);
}
}
Loading
Loading