The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Point pull users at the apply flag that protects what it could not write (#25808)
Weiko8f1355d96892
diff --git a/packages/twenty-sdk/src/cli/commands/dev/dev-once.ts b/packages/twenty-sdk/src/cli/commands/dev/dev-once.tsindex 49233b9b81c..a0990b54749 100644--- a/packages/twenty-sdk/src/cli/commands/dev/dev-once.ts+++ b/packages/twenty-sdk/src/cli/commands/dev/dev-once.ts@@ -3,6 +3,7 @@ import { APP_ERROR_CODES } from '@/cli/types';import { ConfigService } from '@/cli/utilities/config/config-service';import { CURRENT_EXECUTION_DIRECTORY } from '@/cli/utilities/config/current-execution-directory';import { confirmDestructiveApply } from '@/cli/utilities/dev/confirm-destructive-apply';+import { hasPullBaseFile } from '@/cli/utilities/pull/pull-base-file';import { checkSdkVersionCompatibility } from '@/cli/utilities/version/check-sdk-version-compatibility';import chalk from 'chalk';@@ -14,6 +15,26 @@ export type AppDevOnceCommandOptions = {inferDeletionFromMissingEntities?: boolean;};+const warnWhenDeletingFromAPulledProject = async (+ appPath: string,+): Promise<void> => {+ if (!(await hasPullBaseFile({ appPath }))) {+ return;+ }++ console.log(+ chalk.yellow(+ 'This project was written by `twenty pull`, which is experimental and cannot export every entity yet.',+ ),+ );+ console.log(+ chalk.yellow(+ 'Entities it could not write are missing from your source, so applying will destroy them in the workspace.',+ ),+ );+ console.log(chalk.yellow('Re-run with --no-delete to keep them.\n'));+};+export class AppDevOnceCommand {async execute(options: AppDevOnceCommandOptions): Promise<void> {const appPath = options.appPath ?? CURRENT_EXECUTION_DIRECTORY;@@ -30,6 +51,10 @@ export class AppDevOnceCommand {);console.log(chalk.gray(`App path: ${appPath}\n`));+ if (apply && options.inferDeletionFromMissingEntities !== false) {+ await warnWhenDeletingFromAPulledProject(appPath);+ }+const result = await appDevOnce({appPath,verbose: options.verbose,diff --git a/packages/twenty-sdk/src/cli/commands/dev/pull.ts b/packages/twenty-sdk/src/cli/commands/dev/pull.tsindex 68a71ca63dd..4badb48578f 100644--- a/packages/twenty-sdk/src/cli/commands/dev/pull.ts+++ b/packages/twenty-sdk/src/cli/commands/dev/pull.ts@@ -64,7 +64,7 @@ export class AppPullCommand {console.log(chalk.gray(`Base recorded in ${PULL_BASE_FILE_PATH}`));if (result.data.isSdkResolvable) {- console.log(chalk.gray('Next: yarn twenty plan --no-delete'));+ console.log(chalk.gray('Next: yarn twenty apply --no-delete'));} else {console.log(chalk.yellow(@@ -73,7 +73,7 @@ export class AppPullCommand {);console.log(chalk.gray(- 'Next: install your dependencies, then yarn twenty plan --no-delete',+ 'Next: install your dependencies, then yarn twenty apply --no-delete',),);}diff --git a/packages/twenty-sdk/src/cli/utilities/pull/__tests__/has-pull-base-file.spec.ts b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/has-pull-base-file.spec.tsnew file mode 100644index 00000000000..3e0cca5ba38--- /dev/null+++ b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/has-pull-base-file.spec.ts@@ -0,0 +1,42 @@+import {+ hasPullBaseFile,+ PULL_BASE_FILE_PATH,+} from '@/cli/utilities/pull/pull-base-file';+import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';+import { tmpdir } from 'node:os';+import { dirname, join } from 'node:path';+import { afterEach, beforeEach, describe, expect, it } from 'vitest';++describe('hasPullBaseFile', () => {+ let appPath: string;++ beforeEach(async () => {+ appPath = await mkdtemp(join(tmpdir(), 'has-pull-base-file-'));+ });++ afterEach(async () => {+ await rm(appPath, { recursive: true, force: true });+ });++ it('should report no base in a project that was never pulled into', async () => {+ expect(await hasPullBaseFile({ appPath })).toBe(false);+ });++ it('should report a base in a project that was pulled into', async () => {+ const baseFilePath = join(appPath, PULL_BASE_FILE_PATH);++ await mkdir(dirname(baseFilePath), { recursive: true });+ await writeFile(baseFilePath, '{}');++ expect(await hasPullBaseFile({ appPath })).toBe(true);+ });++ it('should report a base even when its content cannot be parsed', async () => {+ const baseFilePath = join(appPath, PULL_BASE_FILE_PATH);++ await mkdir(dirname(baseFilePath), { recursive: true });+ await writeFile(baseFilePath, '{ "version": 1, ');++ expect(await hasPullBaseFile({ appPath })).toBe(true);+ });+});diff --git a/packages/twenty-sdk/src/cli/utilities/pull/pull-base-file.ts b/packages/twenty-sdk/src/cli/utilities/pull/pull-base-file.tsindex 9e9b6d1ba94..07de35d451e 100644--- a/packages/twenty-sdk/src/cli/utilities/pull/pull-base-file.ts+++ b/packages/twenty-sdk/src/cli/utilities/pull/pull-base-file.ts@@ -68,6 +68,12 @@ const isUsableBaseManifest = (manifest: unknown): manifest is Manifest => {);};+export const hasPullBaseFile = async ({+ appPath,+}: {+ appPath: string;+}): Promise<boolean> => pathExists(join(appPath, PULL_BASE_FILE_PATH));+export const readPullBaseManifest = async ({appPath,applicationUniversalIdentifier,