@fluid-app/fluid-cli-mist 0.1.17 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +47 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import chalk from "chalk";
|
|
3
|
-
import { getAuthToken } from "@fluid-app/fluid-cli";
|
|
3
|
+
import { getAuthToken, gitSyncActorFromMe, gitSyncCommitSubject, parseNameStatusZ, resolveGitSyncActor, summarizeChanges } from "@fluid-app/fluid-cli";
|
|
4
4
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
5
|
import path, { join, resolve } from "node:path";
|
|
6
6
|
import os from "node:os";
|
|
@@ -655,6 +655,31 @@ function excludeMistMarkerFromGit(cwd) {
|
|
|
655
655
|
* is left alone — this only prevents *new* adds, it does not untrack
|
|
656
656
|
* anything or rewrite history.
|
|
657
657
|
*/
|
|
658
|
+
/**
|
|
659
|
+
* The staged file set, as {@link ChangeEntry}s — the input a
|
|
660
|
+
* {@link CommitMessage} resolver summarizes.
|
|
661
|
+
*
|
|
662
|
+
* `-z` (NUL-delimited) rather than the default: paths with spaces or
|
|
663
|
+
* quotes are legal in git and common in themes and asset folders, and
|
|
664
|
+
* the newline form quotes and escapes them, which would corrupt both the
|
|
665
|
+
* path and the count.
|
|
666
|
+
*
|
|
667
|
+
* Best-effort — a summary is a nicety, never a reason to fail a publish.
|
|
668
|
+
* An empty result makes the resolver fall back to its own constant.
|
|
669
|
+
*/
|
|
670
|
+
async function stagedChanges(cwd) {
|
|
671
|
+
try {
|
|
672
|
+
const { stdout } = await execa("git", [
|
|
673
|
+
"diff",
|
|
674
|
+
"--cached",
|
|
675
|
+
"--name-status",
|
|
676
|
+
"-z"
|
|
677
|
+
], { cwd });
|
|
678
|
+
return parseNameStatusZ(stdout);
|
|
679
|
+
} catch {
|
|
680
|
+
return [];
|
|
681
|
+
}
|
|
682
|
+
}
|
|
658
683
|
async function gitAutoCommit(cwd, message) {
|
|
659
684
|
await ensureBotIdentity(cwd);
|
|
660
685
|
let repoRoot = cwd;
|
|
@@ -690,6 +715,7 @@ async function gitAutoCommit(cwd, message) {
|
|
|
690
715
|
".mist-desktop"
|
|
691
716
|
], { cwd: repoRoot });
|
|
692
717
|
} catch {}
|
|
718
|
+
const subject = typeof message === "string" ? message : await message(await stagedChanges(cwd));
|
|
693
719
|
const identityArgs = [
|
|
694
720
|
"-c",
|
|
695
721
|
`user.name=${MIST_GIT_AUTHOR_NAME}`,
|
|
@@ -707,7 +733,7 @@ async function gitAutoCommit(cwd, message) {
|
|
|
707
733
|
...identityArgs,
|
|
708
734
|
"commit",
|
|
709
735
|
"-m",
|
|
710
|
-
|
|
736
|
+
subject
|
|
711
737
|
], {
|
|
712
738
|
cwd,
|
|
713
739
|
env: {
|
|
@@ -2094,6 +2120,8 @@ async function fetchCurrentUser(client) {
|
|
|
2094
2120
|
* `fluid mist push [--watch]` — mints a credential, pushes to origin, and
|
|
2095
2121
|
* (with --watch) polls /deployments until READY/ERROR. Spec §3 + §4.
|
|
2096
2122
|
*/
|
|
2123
|
+
/** Used when there's no `-m` and no readable diff to describe. */
|
|
2124
|
+
const FALLBACK_ACTION = "Publish from Mist Desktop";
|
|
2097
2125
|
const POLL_MS$1 = 2e3;
|
|
2098
2126
|
const LOCATE_TIMEOUT_MS = 2 * 6e4;
|
|
2099
2127
|
const READY_TIMEOUT_MS = 5 * 6e4;
|
|
@@ -2144,24 +2172,24 @@ const pushCommand = new Command("push").description("Commit working-tree changes
|
|
|
2144
2172
|
}
|
|
2145
2173
|
if (opts.commit !== false) {
|
|
2146
2174
|
if (await hasUncommittedChanges(cwd)) {
|
|
2147
|
-
const
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
}
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
}
|
|
2160
|
-
const message = `${namePrefix}${baseMessage}${idSuffix}`;
|
|
2161
|
-
const commitSpinner = ora(`Committing changes (${message.length > 60 ? message.slice(0, 57) + "…" : message})…`).start();
|
|
2175
|
+
const explicit = opts.message?.trim();
|
|
2176
|
+
const actor = await resolveGitSyncActor(async () => {
|
|
2177
|
+
try {
|
|
2178
|
+
return gitSyncActorFromMe(await withTimeout(fetchCurrentUser(client), 5e3));
|
|
2179
|
+
} catch (err) {
|
|
2180
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
2181
|
+
console.warn(chalk.yellow(` (skipping user-stamp on commit — couldn't fetch /api/me: ${reason})`));
|
|
2182
|
+
return null;
|
|
2183
|
+
}
|
|
2184
|
+
});
|
|
2185
|
+
let subject = "";
|
|
2186
|
+
const commitSpinner = ora("Committing changes…").start();
|
|
2162
2187
|
try {
|
|
2163
|
-
await gitAutoCommit(cwd,
|
|
2164
|
-
|
|
2188
|
+
await gitAutoCommit(cwd, (changes) => {
|
|
2189
|
+
subject = gitSyncCommitSubject(explicit || summarizeChanges(changes) || FALLBACK_ACTION, actor);
|
|
2190
|
+
return subject;
|
|
2191
|
+
});
|
|
2192
|
+
commitSpinner.succeed(subject ? `Committed — ${subject}` : "Committed");
|
|
2165
2193
|
} catch (err) {
|
|
2166
2194
|
commitSpinner.fail("Commit failed");
|
|
2167
2195
|
throw err;
|