|
|
|
@ -42,23 +42,27 @@ async function runHooks(hooks: undefined | string | string[]) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default async function publish(options: { dry: boolean }) {
|
|
|
|
|
const meta: IMeta = await getMeta();
|
|
|
|
|
const originalMeta = await getMeta();
|
|
|
|
|
|
|
|
|
|
if (originalMeta.hooks) {
|
|
|
|
|
log("Running prepublish hooks");
|
|
|
|
|
await runHooks(originalMeta.hooks.prepublish);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const meta = await getMeta();
|
|
|
|
|
|
|
|
|
|
//TODO: Output Diff between original and result meta
|
|
|
|
|
|
|
|
|
|
if (!meta.name) throw new Error("name is not set in meta.json");
|
|
|
|
|
if (!meta.version) throw new Error("version is not set in meta.json");
|
|
|
|
|
if (!meta.files || !Array.isArray(meta.files) || meta.files.length <= 0)
|
|
|
|
|
throw new Error("files is not set or empty in meta.json");
|
|
|
|
|
|
|
|
|
|
if (meta.hooks) {
|
|
|
|
|
log("Running prepublish hooks");
|
|
|
|
|
await runHooks(meta.hooks.prepublish);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tmpDir = await Deno.makeTempDir();
|
|
|
|
|
const packedFile = (await Deno.makeTempFile()) + ".tar";
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const walker = FS.walk(".", {
|
|
|
|
|
const walker = FS.walk(meta.root || ".", {
|
|
|
|
|
includeDirs: false,
|
|
|
|
|
includeFiles: true,
|
|
|
|
|
match: meta.files.map((file) => Path.globToRegExp(file)),
|
|
|
|
@ -66,17 +70,18 @@ export default async function publish(options: { dry: boolean }) {
|
|
|
|
|
|
|
|
|
|
log("Copying files to package to", tmpDir);
|
|
|
|
|
|
|
|
|
|
const copy = async (path: string) => {
|
|
|
|
|
const dest = Path.join(tmpDir, path);
|
|
|
|
|
const copy = async (path: string, abs?: boolean) => {
|
|
|
|
|
const relative = abs ? path : Path.relative(meta.root || ".", path);
|
|
|
|
|
log("Adding file:", path, "as", relative);
|
|
|
|
|
const dest = Path.join(tmpDir, relative);
|
|
|
|
|
await FS.ensureDir(Path.dirname(dest));
|
|
|
|
|
await FS.copy(path, dest);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await copy("meta.json");
|
|
|
|
|
await copy("meta.json", true);
|
|
|
|
|
|
|
|
|
|
for await (const file of walker) {
|
|
|
|
|
await copy(file.path);
|
|
|
|
|
log("Adding file:", file.path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log("Compressing files into", packedFile);
|
|
|
|
@ -88,9 +93,14 @@ export default async function publish(options: { dry: boolean }) {
|
|
|
|
|
const url = new URL(getConfig("registry"));
|
|
|
|
|
url.pathname = "/api/package/" + meta.name;
|
|
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
|
"Pushing version",
|
|
|
|
|
Colors.blue(meta.version),
|
|
|
|
|
"to repository"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!options.dry) {
|
|
|
|
|
log("Uploading new package version");
|
|
|
|
|
|
|
|
|
|
await fetch(url, {
|
|
|
|
|
method: "POST",
|
|
|
|
|
body: await Deno.readFile(packedFile),
|
|
|
|
|