@nocobase/cli 3.0.0-alpha.7 → 3.0.0-alpha.8

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.
@@ -24,6 +24,10 @@ import { listPortalWorkspaces } from './portal-list.js';
24
24
  import { findPortalListItem } from './portal-info.js';
25
25
  import { resolvePnpmInstallCommand, run, runPnpmInstallCommand } from './run-npm.js';
26
26
  const execFileAsync = promisify(execFile);
27
+ const NOCOBASE_CLI_GIT_IDENTITY = {
28
+ name: 'NocoBase CLI',
29
+ email: '314549027+nocobase-cli@users.noreply.github.com',
30
+ };
27
31
  const portalSourceText = (key, values, fallback) => translateCli(`commands.portalSource.${key}`, values, { fallback });
28
32
  const PULL_SOURCE_OPERATION = {
29
33
  method: 'POST',
@@ -215,6 +219,33 @@ async function runGit(args, cwd) {
215
219
  maxBuffer: 10 * 1024 * 1024,
216
220
  });
217
221
  }
222
+ function isValidGitIdentity(identity) {
223
+ return (!/[\r\n<>]/.test(identity.name) &&
224
+ !/[\r\n<>\s]/.test(identity.email) &&
225
+ identity.email.includes('@'));
226
+ }
227
+ async function resolveLocalGitIdentity(cwd) {
228
+ let output;
229
+ try {
230
+ output = (await runGit(['var', 'GIT_AUTHOR_IDENT'], cwd)).stdout;
231
+ }
232
+ catch {
233
+ return undefined;
234
+ }
235
+ const match = /^(.*) <([^<>]+)> -?\d+ [+-]\d{4}$/.exec(trimValue(output));
236
+ if (!match) {
237
+ return undefined;
238
+ }
239
+ const identity = { name: match[1], email: match[2] };
240
+ if (!isValidGitIdentity(identity)) {
241
+ return undefined;
242
+ }
243
+ if (identity.name === NOCOBASE_CLI_GIT_IDENTITY.name &&
244
+ identity.email === NOCOBASE_CLI_GIT_IDENTITY.email) {
245
+ return undefined;
246
+ }
247
+ return identity;
248
+ }
218
249
  async function installPortalDependencies(params) {
219
250
  if (params.installDependencies === false) {
220
251
  return {
@@ -488,6 +519,7 @@ async function pullGitPortalSource(params) {
488
519
  }
489
520
  async function pushGitPortalSource(params) {
490
521
  const git = assertGitSourceConfig(params.context);
522
+ const localIdentity = await resolveLocalGitIdentity(params.context.portalDir);
491
523
  const tempDir = await mkdtemp(path.join(os.tmpdir(), 'nocobase-cli-portal-git-push-'));
492
524
  try {
493
525
  const repoDir = await cloneGitSource({
@@ -506,15 +538,20 @@ async function pushGitPortalSource(params) {
506
538
  if (!status.stdout.trim()) {
507
539
  return undefined;
508
540
  }
509
- await runGit([
541
+ const commitIdentity = localIdentity ?? NOCOBASE_CLI_GIT_IDENTITY;
542
+ const commitArgs = [
510
543
  '-c',
511
- 'user.name=NocoBase CLI',
544
+ `user.name=${commitIdentity.name}`,
512
545
  '-c',
513
- 'user.email=nocobase-cli@localhost',
546
+ `user.email=${commitIdentity.email}`,
514
547
  'commit',
515
548
  '-m',
516
549
  trimValue(params.message) || `chore(portal): update ${params.context.portal}`,
517
- ], repoDir);
550
+ ];
551
+ if (localIdentity) {
552
+ commitArgs.push('-m', `Co-authored-by: ${NOCOBASE_CLI_GIT_IDENTITY.name} <${NOCOBASE_CLI_GIT_IDENTITY.email}>`);
553
+ }
554
+ await runGit(commitArgs, repoDir);
518
555
  await runGit(['push', 'origin', git.branch], repoDir);
519
556
  const revision = await runGit(['rev-parse', 'HEAD'], repoDir);
520
557
  return revision.stdout.trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli",
3
- "version": "3.0.0-alpha.7",
3
+ "version": "3.0.0-alpha.8",
4
4
  "description": "NocoBase Command Line Tool",
5
5
  "type": "module",
6
6
  "main": "dist/generated/command-registry.js",
@@ -147,5 +147,5 @@
147
147
  "type": "git",
148
148
  "url": "git+https://github.com/nocobase/nocobase.git"
149
149
  },
150
- "gitHead": "19cd28c710f3b3c614ebe2fd7d5a415d527ee559"
150
+ "gitHead": "ce017f3deb8b2414c6b13818042c4187270d1d8a"
151
151
  }