primitive-admin 1.1.0-alpha.6 → 1.1.0-alpha.61
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/README.md +389 -71
- package/assets/skill/skills/primitive-platform/SKILL.md +670 -0
- package/dist/bin/primitive.d.ts +2 -0
- package/dist/bin/primitive.js +287 -17
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/admins.d.ts +2 -0
- package/dist/src/commands/admins.js +138 -19
- package/dist/src/commands/admins.js.map +1 -1
- package/dist/src/commands/analytics.d.ts +2 -0
- package/dist/src/commands/analytics.js +554 -55
- package/dist/src/commands/analytics.js.map +1 -1
- package/dist/src/commands/apps.d.ts +2 -0
- package/dist/src/commands/apps.js +27 -80
- package/dist/src/commands/apps.js.map +1 -1
- package/dist/src/commands/auth.d.ts +2 -0
- package/dist/src/commands/auth.js +177 -7
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/blob-buckets.d.ts +2 -0
- package/dist/src/commands/blob-buckets.js +330 -0
- package/dist/src/commands/blob-buckets.js.map +1 -0
- package/dist/src/commands/catalog.d.ts +2 -0
- package/dist/src/commands/catalog.js +37 -38
- package/dist/src/commands/catalog.js.map +1 -1
- package/dist/src/commands/collection-type-configs.d.ts +2 -0
- package/dist/src/commands/collection-type-configs.js +92 -0
- package/dist/src/commands/collection-type-configs.js.map +1 -0
- package/dist/src/commands/collections.d.ts +2 -0
- package/dist/src/commands/collections.js +526 -0
- package/dist/src/commands/collections.js.map +1 -0
- package/dist/src/commands/comparisons.d.ts +2 -0
- package/dist/src/commands/comparisons.js +6 -6
- package/dist/src/commands/comparisons.js.map +1 -1
- package/dist/src/commands/config.d.ts +35 -0
- package/dist/src/commands/config.js +437 -0
- package/dist/src/commands/config.js.map +1 -0
- package/dist/src/commands/connections.d.ts +2 -0
- package/dist/src/commands/connections.js +100 -0
- package/dist/src/commands/connections.js.map +1 -0
- package/dist/src/commands/cron-triggers.d.ts +2 -0
- package/dist/src/commands/cron-triggers.js +204 -0
- package/dist/src/commands/cron-triggers.js.map +1 -0
- package/dist/src/commands/database-types.d.ts +2 -0
- package/dist/src/commands/database-types.js +171 -0
- package/dist/src/commands/database-types.js.map +1 -0
- package/dist/src/commands/databases.d.ts +65 -0
- package/dist/src/commands/databases.js +2153 -96
- package/dist/src/commands/databases.js.map +1 -1
- package/dist/src/commands/documents.d.ts +2 -0
- package/dist/src/commands/documents.js +1230 -19
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/email-templates.d.ts +2 -0
- package/dist/src/commands/email-templates.js +174 -0
- package/dist/src/commands/email-templates.js.map +1 -0
- package/dist/src/commands/env.d.ts +12 -0
- package/dist/src/commands/env.js +260 -0
- package/dist/src/commands/env.js.map +1 -0
- package/dist/src/commands/group-type-configs.d.ts +2 -0
- package/dist/src/commands/group-type-configs.js +86 -0
- package/dist/src/commands/group-type-configs.js.map +1 -0
- package/dist/src/commands/groups.d.ts +2 -0
- package/dist/src/commands/groups.js +38 -99
- package/dist/src/commands/groups.js.map +1 -1
- package/dist/src/commands/guides.d.ts +223 -0
- package/dist/src/commands/guides.js +617 -65
- package/dist/src/commands/guides.js.map +1 -1
- package/dist/src/commands/init.d.ts +17 -0
- package/dist/src/commands/init.js +964 -202
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/integrations.d.ts +2 -0
- package/dist/src/commands/integrations.js +484 -205
- package/dist/src/commands/integrations.js.map +1 -1
- package/dist/src/commands/llm.d.ts +2 -0
- package/dist/src/commands/llm.js +13 -8
- package/dist/src/commands/llm.js.map +1 -1
- package/dist/src/commands/locks.d.ts +8 -0
- package/dist/src/commands/locks.js +160 -0
- package/dist/src/commands/locks.js.map +1 -0
- package/dist/src/commands/metadata.d.ts +2 -0
- package/dist/src/commands/metadata.js +406 -0
- package/dist/src/commands/metadata.js.map +1 -0
- package/dist/src/commands/prompts.d.ts +2 -0
- package/dist/src/commands/prompts.js +135 -355
- package/dist/src/commands/prompts.js.map +1 -1
- package/dist/src/commands/rule-sets.d.ts +3 -0
- package/dist/src/commands/rule-sets.js +271 -0
- package/dist/src/commands/rule-sets.js.map +1 -0
- package/dist/src/commands/scripts.d.ts +20 -0
- package/dist/src/commands/scripts.js +739 -0
- package/dist/src/commands/scripts.js.map +1 -0
- package/dist/src/commands/secrets.d.ts +2 -0
- package/dist/src/commands/secrets.js +108 -0
- package/dist/src/commands/secrets.js.map +1 -0
- package/dist/src/commands/sessions.d.ts +2 -0
- package/dist/src/commands/sessions.js +75 -0
- package/dist/src/commands/sessions.js.map +1 -0
- package/dist/src/commands/settings.d.ts +18 -0
- package/dist/src/commands/settings.js +54 -0
- package/dist/src/commands/settings.js.map +1 -0
- package/dist/src/commands/skill.d.ts +2 -0
- package/dist/src/commands/skill.js +29 -0
- package/dist/src/commands/skill.js.map +1 -0
- package/dist/src/commands/sync-app-settings.d.ts +125 -0
- package/dist/src/commands/sync-app-settings.js +380 -0
- package/dist/src/commands/sync-app-settings.js.map +1 -0
- package/dist/src/commands/sync.d.ts +958 -0
- package/dist/src/commands/sync.js +8954 -812
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/tokens.d.ts +2 -0
- package/dist/src/commands/tokens.js +130 -21
- package/dist/src/commands/tokens.js.map +1 -1
- package/dist/src/commands/users.d.ts +2 -0
- package/dist/src/commands/users.js +440 -22
- package/dist/src/commands/users.js.map +1 -1
- package/dist/src/commands/vars.d.ts +8 -0
- package/dist/src/commands/vars.js +96 -0
- package/dist/src/commands/vars.js.map +1 -0
- package/dist/src/commands/waitlist.d.ts +2 -0
- package/dist/src/commands/waitlist.js +10 -10
- package/dist/src/commands/waitlist.js.map +1 -1
- package/dist/src/commands/webhooks.d.ts +2 -0
- package/dist/src/commands/webhooks.js +442 -0
- package/dist/src/commands/webhooks.js.map +1 -0
- package/dist/src/commands/workflows.d.ts +94 -0
- package/dist/src/commands/workflows.js +1581 -448
- package/dist/src/commands/workflows.js.map +1 -1
- package/dist/src/lib/api-client.d.ts +1814 -0
- package/dist/src/lib/api-client.js +1655 -103
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/app-settings-descriptor.d.ts +130 -0
- package/dist/src/lib/app-settings-descriptor.js +262 -0
- package/dist/src/lib/app-settings-descriptor.js.map +1 -0
- package/dist/src/lib/auth-flow.d.ts +8 -0
- package/dist/src/lib/batch.d.ts +26 -0
- package/dist/src/lib/batch.js +32 -0
- package/dist/src/lib/batch.js.map +1 -0
- package/dist/src/lib/block-layout.d.ts +160 -0
- package/dist/src/lib/block-layout.js +451 -0
- package/dist/src/lib/block-layout.js.map +1 -0
- package/dist/src/lib/canonical-json.d.ts +12 -0
- package/dist/src/lib/canonical-json.js +35 -0
- package/dist/src/lib/canonical-json.js.map +1 -0
- package/dist/src/lib/channel.d.ts +30 -0
- package/dist/src/lib/channel.js +68 -0
- package/dist/src/lib/channel.js.map +1 -0
- package/dist/src/lib/cli-manifest.d.ts +68 -0
- package/dist/src/lib/cli-manifest.js +71 -0
- package/dist/src/lib/cli-manifest.js.map +1 -0
- package/dist/src/lib/codegen-shared/generatedFiles.d.ts +97 -0
- package/dist/src/lib/codegen-shared/generatedFiles.js +184 -0
- package/dist/src/lib/codegen-shared/generatedFiles.js.map +1 -0
- package/dist/src/lib/codegen-shared/prettierStable.d.ts +262 -0
- package/dist/src/lib/codegen-shared/prettierStable.js +610 -0
- package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -0
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.d.ts +68 -0
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js +168 -0
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js.map +1 -0
- package/dist/src/lib/config-object-descriptor.d.ts +108 -0
- package/dist/src/lib/config-object-descriptor.js +607 -0
- package/dist/src/lib/config-object-descriptor.js.map +1 -0
- package/dist/src/lib/config-payload.d.ts +85 -0
- package/dist/src/lib/config-payload.js +105 -0
- package/dist/src/lib/config-payload.js.map +1 -0
- package/dist/src/lib/config-surface.d.ts +93 -0
- package/dist/src/lib/config-surface.js +178 -0
- package/dist/src/lib/config-surface.js.map +1 -0
- package/dist/src/lib/config-toml.d.ts +10 -0
- package/dist/src/lib/config-toml.js +42 -0
- package/dist/src/lib/config-toml.js.map +1 -0
- package/dist/src/lib/config.d.ts +53 -0
- package/dist/src/lib/config.js +92 -53
- package/dist/src/lib/config.js.map +1 -1
- package/dist/src/lib/confirm-prompt.d.ts +83 -0
- package/dist/src/lib/confirm-prompt.js +110 -0
- package/dist/src/lib/confirm-prompt.js.map +1 -0
- package/dist/src/lib/constants.d.ts +11 -0
- package/dist/src/lib/constants.js +12 -0
- package/dist/src/lib/constants.js.map +1 -0
- package/dist/src/lib/crash-handlers.d.ts +20 -0
- package/dist/src/lib/crash-handlers.js +49 -0
- package/dist/src/lib/crash-handlers.js.map +1 -0
- package/dist/src/lib/credentials-store.d.ts +89 -0
- package/dist/src/lib/credentials-store.js +330 -0
- package/dist/src/lib/credentials-store.js.map +1 -0
- package/dist/src/lib/csv.d.ts +47 -0
- package/dist/src/lib/csv.js +172 -0
- package/dist/src/lib/csv.js.map +1 -0
- package/dist/src/lib/data-input.d.ts +23 -0
- package/dist/src/lib/data-input.js +50 -0
- package/dist/src/lib/data-input.js.map +1 -0
- package/dist/src/lib/db-codegen/dbFingerprint.d.ts +10 -0
- package/dist/src/lib/db-codegen/dbFingerprint.js +17 -0
- package/dist/src/lib/db-codegen/dbFingerprint.js.map +1 -0
- package/dist/src/lib/db-codegen/dbGenerator.d.ts +67 -0
- package/dist/src/lib/db-codegen/dbGenerator.js +170 -0
- package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -0
- package/dist/src/lib/db-codegen/dbNaming.d.ts +87 -0
- package/dist/src/lib/db-codegen/dbNaming.js +180 -0
- package/dist/src/lib/db-codegen/dbNaming.js.map +1 -0
- package/dist/src/lib/db-codegen/dbTemplates.d.ts +272 -0
- package/dist/src/lib/db-codegen/dbTemplates.js +480 -0
- package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -0
- package/dist/src/lib/db-codegen/dbTsTypes.d.ts +73 -0
- package/dist/src/lib/db-codegen/dbTsTypes.js +139 -0
- package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -0
- package/dist/src/lib/db-codegen/dbTypeIR.d.ts +146 -0
- package/dist/src/lib/db-codegen/dbTypeIR.js +517 -0
- package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -0
- package/dist/src/lib/db-codegen/generated-operation-def-descriptor.d.ts +112 -0
- package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js +211 -0
- package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js.map +1 -0
- package/dist/src/lib/env-resolver.d.ts +62 -0
- package/dist/src/lib/env-resolver.js +121 -0
- package/dist/src/lib/env-resolver.js.map +1 -0
- package/dist/src/lib/fetch.d.ts +5 -0
- package/dist/src/lib/generated-allowlist.d.ts +28 -0
- package/dist/src/lib/generated-allowlist.js +266 -0
- package/dist/src/lib/generated-allowlist.js.map +1 -0
- package/dist/src/lib/generated-config-surfaces.d.ts +578 -0
- package/dist/src/lib/generated-config-surfaces.js +3630 -0
- package/dist/src/lib/generated-config-surfaces.js.map +1 -0
- package/dist/src/lib/generated-template-lint.d.ts +206 -0
- package/dist/src/lib/generated-template-lint.js +589 -0
- package/dist/src/lib/generated-template-lint.js.map +1 -0
- package/dist/src/lib/generated-workflow-model-fields.d.ts +20 -0
- package/dist/src/lib/generated-workflow-model-fields.js +53 -0
- package/dist/src/lib/generated-workflow-model-fields.js.map +1 -0
- package/dist/src/lib/google-client-secret-status.d.ts +35 -0
- package/dist/src/lib/google-client-secret-status.js +56 -0
- package/dist/src/lib/google-client-secret-status.js.map +1 -0
- package/dist/src/lib/init-config.d.ts +81 -0
- package/dist/src/lib/init-config.js +149 -0
- package/dist/src/lib/init-config.js.map +1 -0
- package/dist/src/lib/log-inspection.d.ts +568 -0
- package/dist/src/lib/log-inspection.js +639 -0
- package/dist/src/lib/log-inspection.js.map +1 -0
- package/dist/src/lib/migration-nag.d.ts +49 -0
- package/dist/src/lib/migration-nag.js +163 -0
- package/dist/src/lib/migration-nag.js.map +1 -0
- package/dist/src/lib/output.d.ts +109 -0
- package/dist/src/lib/output.js +191 -8
- package/dist/src/lib/output.js.map +1 -1
- package/dist/src/lib/package-manager.d.ts +140 -0
- package/dist/src/lib/package-manager.js +305 -0
- package/dist/src/lib/package-manager.js.map +1 -0
- package/dist/src/lib/paginate.d.ts +83 -0
- package/dist/src/lib/paginate.js +95 -0
- package/dist/src/lib/paginate.js.map +1 -0
- package/dist/src/lib/platform-owned.d.ts +51 -0
- package/dist/src/lib/platform-owned.js +64 -0
- package/dist/src/lib/platform-owned.js.map +1 -0
- package/dist/src/lib/project-config.d.ts +97 -0
- package/dist/src/lib/project-config.js +219 -0
- package/dist/src/lib/project-config.js.map +1 -0
- package/dist/src/lib/query-operators.d.ts +43 -0
- package/dist/src/lib/query-operators.js +80 -0
- package/dist/src/lib/query-operators.js.map +1 -0
- package/dist/src/lib/record-filter.d.ts +18 -0
- package/dist/src/lib/record-filter.js +55 -0
- package/dist/src/lib/record-filter.js.map +1 -0
- package/dist/src/lib/refresh-admin-credentials.d.ts +65 -0
- package/dist/src/lib/refresh-admin-credentials.js +103 -0
- package/dist/src/lib/refresh-admin-credentials.js.map +1 -0
- package/dist/src/lib/resolve-init-dev-port.d.ts +56 -0
- package/dist/src/lib/resolve-init-dev-port.js +55 -0
- package/dist/src/lib/resolve-init-dev-port.js.map +1 -0
- package/dist/src/lib/resolve-init-server.d.ts +71 -0
- package/dist/src/lib/resolve-init-server.js +94 -0
- package/dist/src/lib/resolve-init-server.js.map +1 -0
- package/dist/src/lib/resolve-platform.d.ts +45 -0
- package/dist/src/lib/resolve-platform.js +43 -0
- package/dist/src/lib/resolve-platform.js.map +1 -0
- package/dist/src/lib/run-status.d.ts +19 -0
- package/dist/src/lib/run-status.generated.d.ts +39 -0
- package/dist/src/lib/run-status.generated.js +66 -0
- package/dist/src/lib/run-status.generated.js.map +1 -0
- package/dist/src/lib/run-status.js +19 -0
- package/dist/src/lib/run-status.js.map +1 -0
- package/dist/src/lib/signing-secret-status.d.ts +81 -0
- package/dist/src/lib/signing-secret-status.js +116 -0
- package/dist/src/lib/signing-secret-status.js.map +1 -0
- package/dist/src/lib/skill-installer.d.ts +25 -0
- package/dist/src/lib/skill-installer.js +266 -0
- package/dist/src/lib/skill-installer.js.map +1 -0
- package/dist/src/lib/snapshots.d.ts +99 -0
- package/dist/src/lib/snapshots.js +357 -0
- package/dist/src/lib/snapshots.js.map +1 -0
- package/dist/src/lib/swift-codegen/dbGenerator.d.ts +100 -0
- package/dist/src/lib/swift-codegen/dbGenerator.js +682 -0
- package/dist/src/lib/swift-codegen/dbGenerator.js.map +1 -0
- package/dist/src/lib/swift-codegen/dbSwiftTypes.d.ts +42 -0
- package/dist/src/lib/swift-codegen/dbSwiftTypes.js +100 -0
- package/dist/src/lib/swift-codegen/dbSwiftTypes.js.map +1 -0
- package/dist/src/lib/swift-codegen/generator.d.ts +85 -0
- package/dist/src/lib/swift-codegen/generator.js +266 -0
- package/dist/src/lib/swift-codegen/generator.js.map +1 -0
- package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +72 -0
- package/dist/src/lib/swift-codegen/schemaToSwift.js +644 -0
- package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -0
- package/dist/src/lib/swift-codegen/siblingSymbols.d.ts +90 -0
- package/dist/src/lib/swift-codegen/siblingSymbols.js +152 -0
- package/dist/src/lib/swift-codegen/siblingSymbols.js.map +1 -0
- package/dist/src/lib/swift-codegen/swiftNaming.d.ts +85 -0
- package/dist/src/lib/swift-codegen/swiftNaming.js +198 -0
- package/dist/src/lib/swift-codegen/swiftNaming.js.map +1 -0
- package/dist/src/lib/sync-paths.d.ts +72 -0
- package/dist/src/lib/sync-paths.js +130 -0
- package/dist/src/lib/sync-paths.js.map +1 -0
- package/dist/src/lib/sync-resource-types.d.ts +445 -0
- package/dist/src/lib/sync-resource-types.js +812 -0
- package/dist/src/lib/sync-resource-types.js.map +1 -0
- package/dist/src/lib/sync-selectors.d.ts +95 -0
- package/dist/src/lib/sync-selectors.js +228 -0
- package/dist/src/lib/sync-selectors.js.map +1 -0
- package/dist/src/lib/template.d.ts +121 -0
- package/dist/src/lib/template.js +447 -67
- package/dist/src/lib/template.js.map +1 -1
- package/dist/src/lib/token-inject.d.ts +56 -0
- package/dist/src/lib/token-inject.js +204 -0
- package/dist/src/lib/token-inject.js.map +1 -0
- package/dist/src/lib/toml-database-config.d.ts +123 -0
- package/dist/src/lib/toml-database-config.js +527 -0
- package/dist/src/lib/toml-database-config.js.map +1 -0
- package/dist/src/lib/toml-metadata-config.d.ts +151 -0
- package/dist/src/lib/toml-metadata-config.js +476 -0
- package/dist/src/lib/toml-metadata-config.js.map +1 -0
- package/dist/src/lib/toml-native-form.d.ts +46 -0
- package/dist/src/lib/toml-native-form.js +78 -0
- package/dist/src/lib/toml-native-form.js.map +1 -0
- package/dist/src/lib/toml-params-validator.d.ts +129 -0
- package/dist/src/lib/toml-params-validator.js +298 -0
- package/dist/src/lib/toml-params-validator.js.map +1 -0
- package/dist/src/lib/toml-scalar-edit.d.ts +43 -0
- package/dist/src/lib/toml-scalar-edit.js +283 -0
- package/dist/src/lib/toml-scalar-edit.js.map +1 -0
- package/dist/src/lib/user-selector.d.ts +24 -0
- package/dist/src/lib/user-selector.js +33 -0
- package/dist/src/lib/user-selector.js.map +1 -0
- package/dist/src/lib/version-check.d.ts +35 -0
- package/dist/src/lib/version-check.js +241 -0
- package/dist/src/lib/version-check.js.map +1 -0
- package/dist/src/lib/watch.d.ts +121 -0
- package/dist/src/lib/watch.js +169 -0
- package/dist/src/lib/watch.js.map +1 -0
- package/dist/src/lib/workflow-apply.d.ts +51 -0
- package/dist/src/lib/workflow-apply.js +89 -0
- package/dist/src/lib/workflow-apply.js.map +1 -0
- package/dist/src/lib/workflow-codegen/generated-schema-descriptor.d.ts +129 -0
- package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js +269 -0
- package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js.map +1 -0
- package/dist/src/lib/workflow-codegen/generator.d.ts +96 -0
- package/dist/src/lib/workflow-codegen/generator.js +361 -0
- package/dist/src/lib/workflow-codegen/generator.js.map +1 -0
- package/dist/src/lib/workflow-codegen/invokerIR.d.ts +83 -0
- package/dist/src/lib/workflow-codegen/invokerIR.js +71 -0
- package/dist/src/lib/workflow-codegen/invokerIR.js.map +1 -0
- package/dist/src/lib/workflow-codegen/naming.d.ts +33 -0
- package/dist/src/lib/workflow-codegen/naming.js +81 -0
- package/dist/src/lib/workflow-codegen/naming.js.map +1 -0
- package/dist/src/lib/workflow-codegen/schemaToTs.d.ts +80 -0
- package/dist/src/lib/workflow-codegen/schemaToTs.js +303 -0
- package/dist/src/lib/workflow-codegen/schemaToTs.js.map +1 -0
- package/dist/src/lib/workflow-config-apply.d.ts +70 -0
- package/dist/src/lib/workflow-config-apply.js +137 -0
- package/dist/src/lib/workflow-config-apply.js.map +1 -0
- package/dist/src/lib/workflow-config-sidecar.d.ts +63 -0
- package/dist/src/lib/workflow-config-sidecar.js +96 -0
- package/dist/src/lib/workflow-config-sidecar.js.map +1 -0
- package/dist/src/lib/workflow-field-descriptor.d.ts +91 -0
- package/dist/src/lib/workflow-field-descriptor.js +153 -0
- package/dist/src/lib/workflow-field-descriptor.js.map +1 -0
- package/dist/src/lib/workflow-fragments.d.ts +64 -0
- package/dist/src/lib/workflow-fragments.js +342 -0
- package/dist/src/lib/workflow-fragments.js.map +1 -0
- package/dist/src/lib/workflow-include-preserve.d.ts +71 -0
- package/dist/src/lib/workflow-include-preserve.js +153 -0
- package/dist/src/lib/workflow-include-preserve.js.map +1 -0
- package/dist/src/lib/workflow-payload.d.ts +86 -0
- package/dist/src/lib/workflow-payload.js +168 -0
- package/dist/src/lib/workflow-payload.js.map +1 -0
- package/dist/src/lib/workflow-toml-validator.d.ts +199 -0
- package/dist/src/lib/workflow-toml-validator.js +754 -0
- package/dist/src/lib/workflow-toml-validator.js.map +1 -0
- package/dist/src/types/index.d.ts +533 -0
- package/dist/src/validators.d.ts +65 -0
- package/dist/src/validators.js +64 -0
- package/dist/src/validators.js.map +1 -0
- package/package.json +32 -6
|
@@ -1,107 +1,599 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { browserLogin } from "../lib/auth-flow.js";
|
|
1
|
+
import { confirm, input, select } from "@inquirer/prompts";
|
|
2
|
+
import { appendFileSync, existsSync, readFileSync, writeFileSync } from "fs";
|
|
3
|
+
import { basename, join, resolve } from "path";
|
|
4
|
+
import { CURRENT_CONFIG_VERSION, PROJECT_CONFIG_DIR, PROJECT_CONFIG_FILENAME, PROJECT_CONFIG_DISPLAY_NAME, saveProjectConfig, loadProjectConfigFromPath, } from "../lib/project-config.js";
|
|
6
5
|
import { ApiClient } from "../lib/api-client.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
6
|
+
import { browserLogin } from "../lib/auth-flow.js";
|
|
7
|
+
import { loadCredentials, setCurrentApp } from "../lib/config.js";
|
|
8
|
+
import { isProjectMode, seedCredentialsForEnvInProject, } from "../lib/credentials-store.js";
|
|
9
|
+
import { getCurrentEnvironment, getProjectConfig } from "../lib/env-resolver.js";
|
|
10
|
+
import { normalizeServerUrl } from "../lib/channel.js";
|
|
11
|
+
import { INIT_CONFIG_FILENAME, loadInitConfig, parseInitConfigToml, resolveSkipInstall, resolveUseExistingAppId, validateInitConfig, } from "../lib/init-config.js";
|
|
12
|
+
import { resolvePlatform, } from "../lib/resolve-platform.js";
|
|
13
|
+
import { resolveInitServer, validateServerUrl, } from "../lib/resolve-init-server.js";
|
|
14
|
+
import { DEFAULT_DEV_PORT, resolveDevPort, validateDevPort, } from "../lib/resolve-init-dev-port.js";
|
|
15
|
+
import { DEFAULT_SERVER_URL } from "../lib/constants.js";
|
|
16
|
+
import { divider, error, info, keyValue, success, warn, } from "../lib/output.js";
|
|
17
|
+
import { installCommand, PRIMITIVE_CLI_PACKAGE } from "../lib/package-manager.js";
|
|
18
|
+
import { gitInitialCommit, gitInitRepo, installPnpmGlobally, installPrimitiveCli, isDirectoryEmpty, isPnpmInstalled, isPortFree, isPrimitiveCliInstalled, isXcodeInstalled, iosTemplateUrl, vueTemplateUrl, resolveTemplateBranch, prepareTemplate, runPnpmInstall, runSwiftPackageResolve, updateEnvFile, updateEnvPort, updatePrimitiveJson, updateViteConfig, } from "../lib/template.js";
|
|
19
|
+
/**
|
|
20
|
+
* The .gitignore lines `init` writes for Primitive CLI local state.
|
|
21
|
+
*
|
|
22
|
+
* Pre-pull sync snapshots (issue #578) are per-machine local recovery state and
|
|
23
|
+
* must never be committed. They can land in three places depending on how the
|
|
24
|
+
* sync dir resolves (see `resolveSnapshotsRoot` in `lib/sync-paths.ts`):
|
|
25
|
+
* - project mode: `<projectRoot>/.primitive/sync-backups/<env>/<appId>/`
|
|
26
|
+
* - legacy `--dir <p>`: `<p>/.snapshots/` (sibling of the user dir)
|
|
27
|
+
* - no-project fallback: `./config-snapshots/`
|
|
28
|
+
* The bare `.snapshots/` and `config-snapshots/` entries (no leading slash)
|
|
29
|
+
* match those directories wherever `--dir` points, so backup copies — including
|
|
30
|
+
* the restored `.primitive-sync.json` baseline — can never surface as untracked
|
|
31
|
+
* files in a tracked custom config dir.
|
|
32
|
+
*/
|
|
33
|
+
export const GITIGNORE_LOCAL_STATE_ENTRIES = [
|
|
34
|
+
".primitive/credentials.json",
|
|
35
|
+
".primitive/sync/**/.primitive-sync.json",
|
|
36
|
+
".primitive/sync-backups/",
|
|
37
|
+
".snapshots/",
|
|
38
|
+
"config-snapshots/",
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* Writes .primitive/config.json into the project directory and ensures the
|
|
42
|
+
* .gitignore entry for local state exists. Safe to call in a directory that
|
|
43
|
+
* already has a config — in that case we add/update the "dev" environment
|
|
44
|
+
* instead of overwriting the file.
|
|
45
|
+
*/
|
|
46
|
+
async function scaffoldProjectConfig(opts) {
|
|
47
|
+
const configPath = join(opts.targetDir, PROJECT_CONFIG_DIR, PROJECT_CONFIG_FILENAME);
|
|
48
|
+
let config;
|
|
49
|
+
if (existsSync(configPath)) {
|
|
50
|
+
// Respect an existing config: merge in the new dev env if missing.
|
|
51
|
+
try {
|
|
52
|
+
config = loadProjectConfigFromPath(configPath);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// Existing file is broken — don't clobber it; just warn and skip.
|
|
56
|
+
warn(`${PROJECT_CONFIG_DISPLAY_NAME} exists but is invalid. Skipping project config scaffold.`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (!config.environments.dev) {
|
|
60
|
+
config.environments.dev = {
|
|
61
|
+
apiUrl: opts.serverUrl,
|
|
62
|
+
appId: opts.appId,
|
|
63
|
+
appName: opts.appName,
|
|
64
|
+
};
|
|
65
|
+
if (!config.defaultEnvironment)
|
|
66
|
+
config.defaultEnvironment = "dev";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
config = {
|
|
71
|
+
version: CURRENT_CONFIG_VERSION,
|
|
72
|
+
defaultEnvironment: "dev",
|
|
73
|
+
environments: {
|
|
74
|
+
dev: {
|
|
75
|
+
apiUrl: opts.serverUrl,
|
|
76
|
+
appId: opts.appId,
|
|
77
|
+
appName: opts.appName,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
saveProjectConfig(configPath, config);
|
|
83
|
+
// Ensure .primitive/ local state (credentials, per-machine sync state) is
|
|
84
|
+
// gitignored. The config.json itself lives in .primitive/ too, but we
|
|
85
|
+
// gitignore only the sensitive / per-machine artifacts — config.json and
|
|
86
|
+
// the exported TOML files under .primitive/sync/<env>/<appId>/ are meant
|
|
87
|
+
// to be committed. Only `.primitive-sync.json` (the auto-managed sync
|
|
88
|
+
// state baseline) is per-machine local state; everything else in the
|
|
89
|
+
// sync directory is the version-controllable export.
|
|
90
|
+
//
|
|
91
|
+
// Legacy note: an earlier version of init wrote `.primitive/sync/` here,
|
|
92
|
+
// which incorrectly hid the TOML export tree from `git status`. If we see
|
|
93
|
+
// that legacy entry, replace it with the targeted pattern in-place so
|
|
94
|
+
// users who re-run init pick up the fix.
|
|
95
|
+
const gitignorePath = join(opts.targetDir, ".gitignore");
|
|
96
|
+
const LEGACY_SYNC_IGNORE = ".primitive/sync/";
|
|
97
|
+
const gitignoreEntries = [...GITIGNORE_LOCAL_STATE_ENTRIES];
|
|
98
|
+
let linesToAdd = [];
|
|
99
|
+
if (existsSync(gitignorePath)) {
|
|
100
|
+
const existing = readFileSync(gitignorePath, "utf-8");
|
|
101
|
+
const trimmedLines = existing.split(/\r?\n/).map((l) => l.trim());
|
|
102
|
+
// Migrate the legacy `.primitive/sync/` entry to the targeted pattern,
|
|
103
|
+
// if present. Preserve original line endings/formatting elsewhere.
|
|
104
|
+
if (trimmedLines.includes(LEGACY_SYNC_IGNORE)) {
|
|
105
|
+
const rewritten = existing
|
|
106
|
+
.split(/\r?\n/)
|
|
107
|
+
.map((line) => line.trim() === LEGACY_SYNC_IGNORE
|
|
108
|
+
? ".primitive/sync/**/.primitive-sync.json"
|
|
109
|
+
: line)
|
|
110
|
+
.join("\n");
|
|
111
|
+
try {
|
|
112
|
+
writeFileSync(gitignorePath, rewritten);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Non-fatal
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// Re-read after potential migration so we don't double-add entries.
|
|
119
|
+
const refreshed = readFileSync(gitignorePath, "utf-8")
|
|
120
|
+
.split(/\r?\n/)
|
|
121
|
+
.map((l) => l.trim());
|
|
122
|
+
for (const entry of gitignoreEntries) {
|
|
123
|
+
if (!refreshed.includes(entry)) {
|
|
124
|
+
linesToAdd.push(entry);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
linesToAdd = [...gitignoreEntries];
|
|
130
|
+
}
|
|
131
|
+
if (linesToAdd.length > 0) {
|
|
132
|
+
try {
|
|
133
|
+
const prefix = existsSync(gitignorePath) ? "\n# Primitive CLI local state\n" : "# Primitive CLI local state\n";
|
|
134
|
+
appendFileSync(gitignorePath, prefix + linesToAdd.join("\n") + "\n");
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// Non-fatal
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
success(`Wrote ${PROJECT_CONFIG_DISPLAY_NAME} with dev environment`);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Prompts for login when credentials are missing or the server has changed.
|
|
144
|
+
* Returns updated credentials on success, or exits/warns on failure.
|
|
145
|
+
* In non-interactive mode, auto-proceeds with login (no confirmation prompt).
|
|
146
|
+
*/
|
|
147
|
+
async function ensureAuthenticated(credentials, serverUrl, serverChanged, context) {
|
|
148
|
+
if (credentials && !serverChanged)
|
|
149
|
+
return credentials;
|
|
150
|
+
if (serverChanged) {
|
|
151
|
+
info(`Switching to ${serverUrl}. You need to log in.`);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
info(`You need to log in to ${context.reason}.`);
|
|
155
|
+
}
|
|
156
|
+
if (context.nonInteractive && context.allowSkip) {
|
|
157
|
+
warn(`Skipping ${context.reason}; no authentication is available.`);
|
|
158
|
+
warn(`Make sure the app ID is correct.`);
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
let shouldLogin;
|
|
162
|
+
if (context.nonInteractive) {
|
|
163
|
+
// In non-interactive mode, auto-proceed with login
|
|
164
|
+
shouldLogin = true;
|
|
165
|
+
info("Attempting automatic login...");
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
shouldLogin = await confirm({
|
|
169
|
+
message: "Log in now?",
|
|
170
|
+
default: true,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (!shouldLogin) {
|
|
174
|
+
if (!context.allowSkip) {
|
|
175
|
+
error(`Cannot ${context.reason} without authentication. Use --use-existing-app-id to skip app creation.`);
|
|
176
|
+
// Authentication happens before template prep, so a bail-out here leaves
|
|
177
|
+
// nothing on disk.
|
|
178
|
+
warn(`No project files were written. Re-run \`primitive init\` once you can authenticate.`);
|
|
179
|
+
process.exit(1);
|
|
180
|
+
}
|
|
181
|
+
warn(`Skipping. Make sure the app ID is correct.`);
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
const result = await browserLogin(serverUrl);
|
|
185
|
+
if (!result.success) {
|
|
186
|
+
error(`Login failed: ${result.error}`);
|
|
187
|
+
warn(`No project files were written. Re-run \`primitive init\` once you can authenticate.`);
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
success(`Logged in as ${result.credentials.email}`);
|
|
191
|
+
return result.credentials;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Finds the name of the project-config environment (if any) whose `apiUrl`
|
|
195
|
+
* matches `serverUrl`, so the project-mode "not logged in" remedy can name a
|
|
196
|
+
* real, working environment instead of a placeholder. Comparison uses the
|
|
197
|
+
* same canonicalization as `resolveInitServer` (trailing-slash-insensitive)
|
|
198
|
+
* so `https://host/` in `.primitive/config.json` still matches.
|
|
199
|
+
*/
|
|
200
|
+
function findEnvironmentForServer(serverUrl) {
|
|
201
|
+
const project = getProjectConfig();
|
|
202
|
+
if (!project)
|
|
203
|
+
return undefined;
|
|
204
|
+
const canonicalTarget = normalizeServerUrl(serverUrl) ?? serverUrl;
|
|
205
|
+
return Object.keys(project.environments).find((name) => {
|
|
206
|
+
const apiUrl = project.environments[name].apiUrl;
|
|
207
|
+
return (normalizeServerUrl(apiUrl) ?? apiUrl) === canonicalTarget;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Loads the init config from --config flag or auto-discovers it in CWD.
|
|
212
|
+
* Returns null if no config file is found/specified.
|
|
213
|
+
* Exits with error if config file is specified but invalid.
|
|
214
|
+
*/
|
|
215
|
+
function loadInitConfigFromOptions(options) {
|
|
216
|
+
let config = null;
|
|
217
|
+
if (options.config) {
|
|
218
|
+
// Explicit config path
|
|
219
|
+
const configPath = resolve(process.cwd(), options.config);
|
|
220
|
+
if (!existsSync(configPath)) {
|
|
221
|
+
error(`Config file not found: ${configPath}`);
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
const content = readFileSync(configPath, "utf-8");
|
|
226
|
+
config = parseInitConfigToml(content);
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
error(`Failed to parse config file: ${err.message}`);
|
|
230
|
+
process.exit(1);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
// Auto-discover in CWD
|
|
235
|
+
config = loadInitConfig(process.cwd());
|
|
236
|
+
}
|
|
237
|
+
if (!config)
|
|
238
|
+
return null;
|
|
239
|
+
// Validate
|
|
240
|
+
info(`Using config file for non-interactive init`);
|
|
241
|
+
const validation = validateInitConfig(config);
|
|
242
|
+
if (!validation.valid) {
|
|
243
|
+
error("Invalid config file:");
|
|
244
|
+
for (const err of validation.errors) {
|
|
245
|
+
error(` - ${err}`);
|
|
246
|
+
}
|
|
247
|
+
process.exit(1);
|
|
248
|
+
}
|
|
249
|
+
return config;
|
|
250
|
+
}
|
|
10
251
|
export function registerInitCommand(program) {
|
|
11
252
|
program
|
|
12
253
|
.command("init")
|
|
13
254
|
.description("Create a new Primitive app from template")
|
|
14
255
|
.argument("[directory]", "Directory to create the project in (default: current directory)")
|
|
15
256
|
.option("--use-existing-app-id <id>", "Use an existing app ID instead of creating a new one")
|
|
16
|
-
.option("-s, --server <url>", "Server URL
|
|
17
|
-
.option("--skip-install", "Skip
|
|
257
|
+
.option("-s, --server <url>", "Server URL (default: current CLI server or https://primitiveapi.com)")
|
|
258
|
+
.option("--skip-install", "Skip dependency installation")
|
|
259
|
+
.option("--config <path>", `Path to an init config file for non-interactive setup (default: auto-discover ${INIT_CONFIG_FILENAME} in the current directory)`)
|
|
260
|
+
.option("-p, --platform <platform>", "Target platform: web or ios (SwiftUI). Omit to be prompted interactively.")
|
|
18
261
|
.addHelpText("after", `
|
|
19
262
|
Examples:
|
|
20
|
-
$ primitive init my-app
|
|
21
|
-
$ primitive init
|
|
263
|
+
$ primitive init my-app # Create web app in ./my-app
|
|
264
|
+
$ primitive init # Interactive: prompt for directory and app name
|
|
265
|
+
$ primitive init my-app --platform ios # Create an iOS (SwiftUI) app
|
|
22
266
|
$ primitive init . --use-existing-app-id 01HXY... # Use existing app in current dir
|
|
23
267
|
$ primitive init my-app --skip-install # Skip dependency install
|
|
268
|
+
$ primitive init --config .primitive-init.toml # Non-interactive from config file
|
|
269
|
+
|
|
270
|
+
Non-interactive mode:
|
|
271
|
+
Create a ${INIT_CONFIG_FILENAME} file (or pass --config <path>) to skip all prompts.
|
|
272
|
+
The config file uses TOML format:
|
|
273
|
+
|
|
274
|
+
action = "create" # "create" or "use-existing"
|
|
275
|
+
app_name = "My App" # Required for action = "create"
|
|
276
|
+
app_id = "01HXY..." # Required for action = "use-existing"
|
|
277
|
+
dir = "my-app" # Project directory (optional)
|
|
278
|
+
platform = "web" # "web" or "ios" (optional, defaults to web)
|
|
279
|
+
access_mode = "invite-only" # "public", "domain", or "invite-only" (optional)
|
|
280
|
+
dev_port = 5173 # Dev server port (optional). Set it to skip the
|
|
281
|
+
# port prompt: init pins the port in
|
|
282
|
+
# vite.config.ts and .env and adds
|
|
283
|
+
# http://localhost:<port> to the app's CORS
|
|
284
|
+
# allowed origins and redirect URIs.
|
|
285
|
+
skip_install = false # Skip pnpm install (optional). Same effect as
|
|
286
|
+
# --skip-install; the flag wins if both are set.
|
|
287
|
+
server = "https://..." # Server to create the app on (optional).
|
|
288
|
+
# Same effect as -s/--server; the flag wins if
|
|
289
|
+
# both are set. If the CLI already points at a
|
|
290
|
+
# different server, init stops and tells you how
|
|
291
|
+
# to point it here first. Outside a Primitive
|
|
292
|
+
# project, if you are not logged in at all, init
|
|
293
|
+
# logs in to this one; inside a project the
|
|
294
|
+
# selected environment's apiUrl is the target
|
|
295
|
+
# even when logged out, so a different value
|
|
296
|
+
# here stops the run.
|
|
297
|
+
invite_emails = ["a@b.com"] # Emails to invite (optional, for invite-only)
|
|
298
|
+
allowed_domains = ["b.com"] # Allowed domains (optional, for domain mode)
|
|
299
|
+
overwrite = false # Overwrite non-empty target directory (optional)
|
|
24
300
|
|
|
25
301
|
This command will:
|
|
26
|
-
1. Download the Primitive app template
|
|
302
|
+
1. Download the Primitive app template (web or Apple SwiftUI)
|
|
27
303
|
2. Prompt for an app name and create it on the Primitive server (or use existing)
|
|
28
304
|
3. Configure the project with your app ID
|
|
29
|
-
4. Install dependencies
|
|
305
|
+
4. Install dependencies (pnpm for web, swift package resolve for Apple)
|
|
30
306
|
`)
|
|
31
307
|
.action(handleInit);
|
|
32
308
|
}
|
|
33
309
|
async function handleInit(projectDirArg, options) {
|
|
34
|
-
|
|
310
|
+
// Validate an explicitly-passed `--platform` flag up front. Only `web` and
|
|
311
|
+
// `ios` are supported (#1009 removed `macos`). An omitted flag is
|
|
312
|
+
// `undefined` (the commander default was dropped) and is resolved below.
|
|
313
|
+
if (options.platform !== undefined &&
|
|
314
|
+
options.platform !== "web" &&
|
|
315
|
+
options.platform !== "ios") {
|
|
316
|
+
error(`Unknown platform "${options.platform}". Supported platforms: web, ios`);
|
|
317
|
+
process.exit(1);
|
|
318
|
+
}
|
|
319
|
+
// `initConfig` is the parsed-and-validated `primitive-init.toml` for
|
|
320
|
+
// non-interactive runs (CI, scripted scaffolding). When non-null, the
|
|
321
|
+
// rest of this function uses it to skip prompts.
|
|
322
|
+
const initConfig = loadInitConfigFromOptions(options);
|
|
323
|
+
// Whether to skip the dependency install (steps 7-8). Both the
|
|
324
|
+
// `--skip-install` flag and the config's `skip_install` key request it; the
|
|
325
|
+
// flag wins. Reading only the flag is what made the documented config key a
|
|
326
|
+
// no-op (#2720).
|
|
327
|
+
const { skipInstall, source: skipInstallSource } = resolveSkipInstall(options.skipInstall, initConfig);
|
|
328
|
+
const skipInstallReason = skipInstallSource === "config" ? "skip_install = true in config" : "--skip-install";
|
|
329
|
+
// Resolve the target platform per the 4-case interactivity contract:
|
|
330
|
+
// (a) explicit --platform flag -> use it (never prompt)
|
|
331
|
+
// (b) init-config TOML present -> use its platform or fall back to web
|
|
332
|
+
// (c) interactive TTY, no flag/cfg -> prompt
|
|
333
|
+
// (d) non-TTY, no flag/cfg -> fall back to web (no hang/crash)
|
|
334
|
+
// The prompt is TTY-guarded inside `resolvePlatform` so a piped/CI stdin
|
|
335
|
+
// never triggers the `@inquirer/prompts` `ERR_USE_AFTER_CLOSE` crash.
|
|
336
|
+
const platform = await resolvePlatform({
|
|
337
|
+
flag: options.platform,
|
|
338
|
+
configPlatform: initConfig?.platform,
|
|
339
|
+
hasConfig: initConfig != null,
|
|
340
|
+
isTTY: Boolean(process.stdin.isTTY),
|
|
341
|
+
promptFn: () => select({
|
|
342
|
+
message: "What platform are you building for?",
|
|
343
|
+
choices: [
|
|
344
|
+
{ value: "web", name: "web (Vue 3 + TypeScript + Tailwind)" },
|
|
345
|
+
{ value: "ios", name: "ios (Swift + SwiftUI)" },
|
|
346
|
+
],
|
|
347
|
+
default: "web",
|
|
348
|
+
}),
|
|
349
|
+
});
|
|
350
|
+
// iOS shares the SwiftUI template, Xcode toolchain, and primitive.json
|
|
351
|
+
// config path. (macOS was removed in #1009.)
|
|
352
|
+
const isApple = platform === "ios";
|
|
353
|
+
// Apple-family platforms require macOS with Xcode.
|
|
354
|
+
if (isApple && process.platform !== "darwin") {
|
|
355
|
+
error("iOS apps require macOS with Xcode installed.");
|
|
356
|
+
process.exit(1);
|
|
357
|
+
}
|
|
358
|
+
if (isApple) {
|
|
359
|
+
const xcodeAvailable = await isXcodeInstalled();
|
|
360
|
+
if (!xcodeAvailable) {
|
|
361
|
+
error("Xcode command-line tools are required for Apple development. Install them with: xcode-select --install");
|
|
362
|
+
process.exit(1);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
35
365
|
// Step 1: Determine project directory
|
|
36
366
|
let projectDir = projectDirArg;
|
|
367
|
+
if (!projectDir && initConfig?.dir) {
|
|
368
|
+
projectDir = initConfig.dir;
|
|
369
|
+
}
|
|
37
370
|
if (!projectDir) {
|
|
38
371
|
projectDir = await input({
|
|
39
|
-
message: "
|
|
40
|
-
default: "
|
|
372
|
+
message: "Project name (a new directory will be created):",
|
|
373
|
+
default: "my-primitive-app",
|
|
41
374
|
validate: (value) => {
|
|
42
375
|
if (!value.trim())
|
|
43
|
-
return "
|
|
376
|
+
return "Project name cannot be empty";
|
|
44
377
|
return true;
|
|
45
378
|
},
|
|
46
379
|
});
|
|
47
380
|
}
|
|
48
381
|
const targetDir = resolve(process.cwd(), projectDir);
|
|
49
382
|
// Used as the default app name suggestion when prompting
|
|
50
|
-
const defaultAppName = projectDir === "." ? basename(targetDir) : projectDir;
|
|
383
|
+
const defaultAppName = projectDir === "." ? basename(targetDir) : basename(projectDir);
|
|
51
384
|
// Step 2: Check if directory exists and is non-empty
|
|
52
385
|
if (existsSync(targetDir) && !isDirectoryEmpty(targetDir)) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
386
|
+
if (initConfig) {
|
|
387
|
+
// Non-interactive: require explicit overwrite opt-in
|
|
388
|
+
if (!initConfig.overwrite) {
|
|
389
|
+
error(`Directory "${projectDir}" already exists and is not empty.`);
|
|
390
|
+
error('Set overwrite = true in your config file to allow overwriting.');
|
|
391
|
+
process.exit(1);
|
|
392
|
+
}
|
|
393
|
+
warn(`Directory "${projectDir}" already exists and is not empty. Overwriting (overwrite = true in config).`);
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
warn(`Directory "${projectDir}" already exists and is not empty.`);
|
|
397
|
+
const overwrite = await confirm({
|
|
398
|
+
message: "Do you want to overwrite the existing contents?",
|
|
399
|
+
default: false,
|
|
400
|
+
});
|
|
401
|
+
if (!overwrite) {
|
|
402
|
+
error("Aborted. Please choose a different project name.");
|
|
403
|
+
process.exit(1);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
// Step 2.5: Determine target server. Precedence: `--server` flag, then the
|
|
408
|
+
// init-config `server` key, then the current login, then the default. The
|
|
409
|
+
// config key used to be dropped on the floor here (#2376).
|
|
410
|
+
if (options.server !== undefined) {
|
|
411
|
+
const validation = validateServerUrl(options.server);
|
|
412
|
+
if (validation !== true) {
|
|
413
|
+
error(validation);
|
|
60
414
|
process.exit(1);
|
|
61
415
|
}
|
|
62
416
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
417
|
+
const existingCredentials = loadCredentials();
|
|
418
|
+
// In project mode the CLI is pinned to the selected environment's `apiUrl`
|
|
419
|
+
// even before that environment has any credentials: `saveCredentialsStore()`
|
|
420
|
+
// writes tokens into the environment's slot and discards the server they were
|
|
421
|
+
// minted for, and `loadCredentialsStore()` blends them back with
|
|
422
|
+
// `env.config.apiUrl`. So "logged out" does not mean "no current server"
|
|
423
|
+
// there — the environment still fixes the target, and the mismatch check
|
|
424
|
+
// below has to compare against it. Reading only the credentials' `serverUrl`
|
|
425
|
+
// let a logged-out environment slip past the guard: init would log in to the
|
|
426
|
+
// config's server and then send every later call to the environment's own
|
|
427
|
+
// `apiUrl`.
|
|
428
|
+
const currentEnvironment = getCurrentEnvironment();
|
|
429
|
+
const currentServer = existingCredentials?.serverUrl ?? currentEnvironment?.config.apiUrl;
|
|
430
|
+
const resolvedServer = await resolveInitServer({
|
|
431
|
+
flagServer: options.server,
|
|
432
|
+
configServer: initConfig?.server,
|
|
433
|
+
hasConfig: initConfig != null,
|
|
434
|
+
currentServer,
|
|
435
|
+
defaultServer: DEFAULT_SERVER_URL,
|
|
436
|
+
isTTY: Boolean(process.stdin.isTTY),
|
|
437
|
+
promptFn: async () => {
|
|
438
|
+
// Only reached when a current server exists (see resolveInitServer).
|
|
439
|
+
const current = currentServer ?? DEFAULT_SERVER_URL;
|
|
440
|
+
console.log();
|
|
441
|
+
const serverChoice = await select({
|
|
442
|
+
message: `The Primitive CLI is currently using ${current}.\nWhere do you want to create this app?`,
|
|
443
|
+
choices: [
|
|
444
|
+
{
|
|
445
|
+
value: current,
|
|
446
|
+
name: `Current server (${current})`,
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
value: DEFAULT_SERVER_URL,
|
|
450
|
+
name: `Production (${DEFAULT_SERVER_URL})`,
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
value: "__custom__",
|
|
454
|
+
name: "Other server",
|
|
455
|
+
},
|
|
456
|
+
],
|
|
457
|
+
default: currentServer,
|
|
458
|
+
});
|
|
459
|
+
if (serverChoice !== "__custom__")
|
|
460
|
+
return serverChoice;
|
|
461
|
+
return input({
|
|
462
|
+
message: "Enter the server URL:",
|
|
463
|
+
validate: validateServerUrl,
|
|
464
|
+
});
|
|
465
|
+
},
|
|
466
|
+
});
|
|
467
|
+
const serverUrl = resolvedServer.serverUrl;
|
|
468
|
+
const serverChanged = resolvedServer.serverChanged;
|
|
469
|
+
if (resolvedServer.source === "config") {
|
|
470
|
+
info(`Server: ${serverUrl} (from config)`);
|
|
70
471
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
472
|
+
// A run that can't get usable credentials for the resolved server must fail
|
|
473
|
+
// loudly here rather than hang on the OAuth callback — or, as in #2376,
|
|
474
|
+
// quietly build the app on the current server. Two cases qualify:
|
|
475
|
+
//
|
|
476
|
+
// * a non-interactive init-config run, which has no way to drive a browser;
|
|
477
|
+
// * any project-mode run, because a login always lands in the selected
|
|
478
|
+
// environment's slot and is read back with that environment's `apiUrl`.
|
|
479
|
+
// Logging in to a different server there would leave the project holding
|
|
480
|
+
// credentials the rest of the CLI sends somewhere else.
|
|
481
|
+
//
|
|
482
|
+
// In legacy mode an interactive run can still log in to the requested server
|
|
483
|
+
// and have it stored correctly, so it goes through the login flow below.
|
|
484
|
+
const inProjectMode = isProjectMode();
|
|
485
|
+
if (serverChanged && (initConfig || inProjectMode)) {
|
|
486
|
+
const requestedBy = resolvedServer.source === "flag"
|
|
487
|
+
? "--server"
|
|
488
|
+
: resolvedServer.source === "config"
|
|
489
|
+
? "the init config's `server`"
|
|
490
|
+
: "the server you selected";
|
|
491
|
+
// `currentServer` is the stored login's server when there is one, and
|
|
492
|
+
// otherwise the selected environment's `apiUrl` — say which, so the user
|
|
493
|
+
// isn't told they're "logged in to" a server they never logged in to.
|
|
494
|
+
const currentDescription = existingCredentials
|
|
495
|
+
? `the CLI is logged in to ${currentServer}`
|
|
496
|
+
: `this project's "${currentEnvironment?.name}" environment targets ${currentServer}`;
|
|
497
|
+
error(`Not logged in to ${serverUrl}.`);
|
|
498
|
+
error(`${requestedBy} requests ${serverUrl}, but ${currentDescription}.`);
|
|
499
|
+
// The remedy differs by mode: `primitive login` resolves its target
|
|
500
|
+
// through `getConfiguredServerUrl()`, which returns the active
|
|
501
|
+
// environment's `apiUrl` whenever a project config is in scope and ignores
|
|
502
|
+
// `PRIMITIVE_SERVER_URL` there. Printing the legacy-mode hint inside a
|
|
503
|
+
// project would send the user in circles.
|
|
504
|
+
if (inProjectMode) {
|
|
505
|
+
error(`Inside a Primitive project, \`primitive login\` targets the selected environment's server, so PRIMITIVE_SERVER_URL has no effect here.`);
|
|
506
|
+
// `primitive -e <env> login` only resolves the mismatch if `<env>` is
|
|
507
|
+
// both logged into AND passed to the init re-run — `currentServer` is
|
|
508
|
+
// always the *selected* environment's apiUrl (that's what made this
|
|
509
|
+
// serverChanged in the first place), so re-running `primitive login`
|
|
510
|
+
// or `primitive init` without `-e` reproduces the identical error.
|
|
511
|
+
// Look up which configured environment (if any) actually targets
|
|
512
|
+
// `serverUrl` so the hint names a real, working command instead of a
|
|
513
|
+
// placeholder.
|
|
514
|
+
const targetEnvName = findEnvironmentForServer(serverUrl);
|
|
515
|
+
// The re-run has to resolve to the same server, and it re-reads every
|
|
516
|
+
// input from scratch. Only a config-selected server survives on its own:
|
|
517
|
+
// when the flag (or the interactive prompt) is what won here, an
|
|
518
|
+
// otherwise-identical re-run would fall back to the config's `server` —
|
|
519
|
+
// or prompt again — and reproduce this exact error. Pin it with
|
|
520
|
+
// `--server`, which outranks both.
|
|
521
|
+
const serverFlag = resolvedServer.source === "config" ? "" : ` --server ${serverUrl}`;
|
|
522
|
+
if (targetEnvName) {
|
|
523
|
+
const configFlag = options.config ? ` --config ${options.config}` : "";
|
|
524
|
+
error(`Log in to the "${targetEnvName}" environment and run init against it: ` +
|
|
525
|
+
`\`primitive -e ${targetEnvName} login\` then ` +
|
|
526
|
+
`\`primitive -e ${targetEnvName} init${configFlag}${serverFlag}\`.`);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
error(`This project has no environment configured for ${serverUrl}. ` +
|
|
530
|
+
`Add one (\`primitive env add <name> --api-url ${serverUrl}\`) and ` +
|
|
531
|
+
`re-run with \`-e <name>${serverFlag}\`, or re-run init outside the project directory.`);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
error(`Log in to the target server first: PRIMITIVE_SERVER_URL=${serverUrl} primitive login`);
|
|
536
|
+
}
|
|
537
|
+
warn("No project files were written.");
|
|
74
538
|
process.exit(1);
|
|
75
539
|
}
|
|
76
|
-
// Step 4: Check authentication
|
|
77
|
-
|
|
540
|
+
// Step 4: Check authentication (credentials were loaded for the server
|
|
541
|
+
// resolution above — reuse them rather than re-reading the file).
|
|
542
|
+
let credentials = existingCredentials;
|
|
78
543
|
let appId;
|
|
79
544
|
let appName;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
545
|
+
let preparedTemplate = null;
|
|
546
|
+
const cleanupPreparedTemplate = () => {
|
|
547
|
+
try {
|
|
548
|
+
preparedTemplate?.cleanup();
|
|
549
|
+
}
|
|
550
|
+
catch {
|
|
551
|
+
// Non-fatal cleanup best effort
|
|
552
|
+
}
|
|
553
|
+
preparedTemplate = null;
|
|
554
|
+
};
|
|
555
|
+
const prepareTemplateOrExit = async () => {
|
|
556
|
+
if (preparedTemplate)
|
|
557
|
+
return;
|
|
558
|
+
// Download and validate the archive before app creation, but keep it staged
|
|
559
|
+
// in a temp directory. That avoids both failure modes: app-creation failure
|
|
560
|
+
// leaves no scaffold, and template-download failure leaves no orphaned app.
|
|
561
|
+
info(`Preparing your ${platform === "ios" ? "iOS" : "web"} project template...`);
|
|
562
|
+
// The branch is the channel (issue #1934): scaffolding against the alpha
|
|
563
|
+
// server pulls the alpha template branch, whose Primitive deps pin the
|
|
564
|
+
// alpha prerelease libraries. Falls back to main (with a warning) if the
|
|
565
|
+
// channel branch isn't available.
|
|
566
|
+
const templateBranch = resolveTemplateBranch(serverUrl);
|
|
567
|
+
const templateUrlFor = isApple ? iosTemplateUrl : vueTemplateUrl;
|
|
568
|
+
try {
|
|
569
|
+
preparedTemplate = await prepareTemplate({
|
|
570
|
+
templateUrl: templateUrlFor(templateBranch),
|
|
571
|
+
fallbackTemplateUrl: templateBranch !== "main" ? templateUrlFor("main") : undefined,
|
|
572
|
+
onFallback: (reason) => warn(`Template branch "${templateBranch}" unavailable (${reason}) — falling back to main.`),
|
|
573
|
+
onProgress: info,
|
|
89
574
|
});
|
|
90
|
-
if (shouldLogin) {
|
|
91
|
-
const result = await browserLogin(serverUrl);
|
|
92
|
-
if (!result.success) {
|
|
93
|
-
error(`Login failed: ${result.error}`);
|
|
94
|
-
warn(`Template files were extracted to "${targetDir}" but VITE_APP_ID is not configured.`);
|
|
95
|
-
warn("You'll need to manually set VITE_APP_ID in your .env file to use this project.");
|
|
96
|
-
process.exit(1);
|
|
97
|
-
}
|
|
98
|
-
credentials = result.credentials;
|
|
99
|
-
success(`Logged in as ${credentials.email}`);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
warn("Skipping app verification. Make sure the app ID is correct.");
|
|
103
|
-
}
|
|
104
575
|
}
|
|
576
|
+
catch (err) {
|
|
577
|
+
error(`Failed to download template: ${err.message}`);
|
|
578
|
+
error("Check your internet connection and try again.");
|
|
579
|
+
process.exit(1);
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
// An existing app can be selected two ways: the `--use-existing-app-id` flag,
|
|
583
|
+
// or `action = "use-existing"` + `app_id` in the init-config TOML. Reading
|
|
584
|
+
// only the flag (the old behavior) made a use-existing TOML fall through to
|
|
585
|
+
// the create branch and prompt for an app name — hanging non-interactive
|
|
586
|
+
// runs. (#1217)
|
|
587
|
+
const useExistingAppId = resolveUseExistingAppId(options.useExistingAppId, initConfig);
|
|
588
|
+
if (useExistingAppId) {
|
|
589
|
+
// Using existing app ID - verify it exists
|
|
590
|
+
appId = useExistingAppId;
|
|
591
|
+
appName = "(existing app)"; // Default if we can't verify
|
|
592
|
+
credentials = await ensureAuthenticated(credentials, serverUrl, serverChanged, {
|
|
593
|
+
reason: "verify the app",
|
|
594
|
+
allowSkip: true,
|
|
595
|
+
nonInteractive: !!initConfig,
|
|
596
|
+
});
|
|
105
597
|
if (credentials) {
|
|
106
598
|
try {
|
|
107
599
|
const client = new ApiClient();
|
|
@@ -113,36 +605,27 @@ async function handleInit(projectDirArg, options) {
|
|
|
113
605
|
warn(`Could not verify app: ${err.message}`);
|
|
114
606
|
}
|
|
115
607
|
}
|
|
608
|
+
await prepareTemplateOrExit();
|
|
116
609
|
}
|
|
117
610
|
else {
|
|
118
611
|
// Creating new app - authentication required
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
612
|
+
credentials = await ensureAuthenticated(credentials, serverUrl, serverChanged, {
|
|
613
|
+
reason: "create an app",
|
|
614
|
+
allowSkip: false,
|
|
615
|
+
nonInteractive: !!initConfig,
|
|
616
|
+
});
|
|
617
|
+
// Determine app name
|
|
618
|
+
if (initConfig?.app_name) {
|
|
619
|
+
appName = initConfig.app_name;
|
|
620
|
+
info(`App name: ${appName} (from config)`);
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
appName = await input({
|
|
624
|
+
message: "What would you like to name your app?",
|
|
625
|
+
default: defaultAppName,
|
|
124
626
|
});
|
|
125
|
-
if (!shouldLogin) {
|
|
126
|
-
error("Cannot create app without authentication. Use --use-existing-app-id to skip app creation.");
|
|
127
|
-
warn(`Template files were extracted to "${targetDir}" but VITE_APP_ID is not configured.`);
|
|
128
|
-
warn("You'll need to manually set VITE_APP_ID in your .env file to use this project.");
|
|
129
|
-
process.exit(1);
|
|
130
|
-
}
|
|
131
|
-
const result = await browserLogin(serverUrl);
|
|
132
|
-
if (!result.success) {
|
|
133
|
-
error(`Login failed: ${result.error}`);
|
|
134
|
-
warn(`Template files were extracted to "${targetDir}" but VITE_APP_ID is not configured.`);
|
|
135
|
-
warn("You'll need to manually set VITE_APP_ID in your .env file to use this project.");
|
|
136
|
-
process.exit(1);
|
|
137
|
-
}
|
|
138
|
-
credentials = result.credentials;
|
|
139
|
-
success(`Logged in as ${credentials.email}`);
|
|
140
627
|
}
|
|
141
|
-
|
|
142
|
-
appName = await input({
|
|
143
|
-
message: "What would you like to name your app?",
|
|
144
|
-
default: defaultAppName,
|
|
145
|
-
});
|
|
628
|
+
await prepareTemplateOrExit();
|
|
146
629
|
// Create app
|
|
147
630
|
info("Creating app on Primitive server...");
|
|
148
631
|
try {
|
|
@@ -162,52 +645,68 @@ async function handleInit(projectDirArg, options) {
|
|
|
162
645
|
catch (err) {
|
|
163
646
|
error(`Failed to create app: ${err.message}`);
|
|
164
647
|
error("You can try again or use --use-existing-app-id with an existing app.");
|
|
165
|
-
|
|
166
|
-
|
|
648
|
+
// The template archive has been validated in a temp directory, but it has
|
|
649
|
+
// not been installed into targetDir yet (#1218).
|
|
650
|
+
warn("No project files were written. Re-run `primitive init` after resolving the app creation error.");
|
|
651
|
+
cleanupPreparedTemplate();
|
|
167
652
|
process.exit(1);
|
|
168
653
|
}
|
|
169
654
|
// Configure app access mode
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
655
|
+
let accessMode;
|
|
656
|
+
if (initConfig?.access_mode) {
|
|
657
|
+
accessMode = initConfig.access_mode;
|
|
658
|
+
info(`Access mode: ${accessMode} (from config)`);
|
|
659
|
+
}
|
|
660
|
+
else {
|
|
661
|
+
console.log();
|
|
662
|
+
info("Let's configure who can access your app.");
|
|
663
|
+
info("(You can change this later in app.toml, then 'primitive sync push --only app')");
|
|
664
|
+
accessMode = await select({
|
|
665
|
+
message: "Who should be able to sign up for your app?",
|
|
666
|
+
choices: [
|
|
667
|
+
{
|
|
668
|
+
value: "public",
|
|
669
|
+
name: "Anyone (public)",
|
|
670
|
+
description: "Anyone can create an account",
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
value: "domain",
|
|
674
|
+
name: "Domain restricted",
|
|
675
|
+
description: "Only users with email addresses from specific domains",
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
value: "invite-only",
|
|
679
|
+
name: "Invite only",
|
|
680
|
+
description: "Only users you explicitly invite can sign up",
|
|
681
|
+
},
|
|
682
|
+
],
|
|
683
|
+
default: "invite-only",
|
|
684
|
+
});
|
|
685
|
+
}
|
|
194
686
|
const client = new ApiClient();
|
|
195
687
|
const settingsPayload = {
|
|
196
688
|
mode: accessMode,
|
|
197
689
|
};
|
|
198
690
|
if (accessMode === "domain") {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
691
|
+
let allowedDomains;
|
|
692
|
+
if (initConfig?.allowed_domains && initConfig.allowed_domains.length > 0) {
|
|
693
|
+
allowedDomains = initConfig.allowed_domains;
|
|
694
|
+
info(`Allowed domains: ${allowedDomains.join(", ")} (from config)`);
|
|
695
|
+
}
|
|
696
|
+
else {
|
|
697
|
+
const domainsInput = await input({
|
|
698
|
+
message: "Enter allowed email domain(s) (comma-separated, e.g., 'acme.com, example.org'):",
|
|
699
|
+
validate: (value) => {
|
|
700
|
+
if (!value.trim())
|
|
701
|
+
return "Please enter at least one domain";
|
|
702
|
+
return true;
|
|
703
|
+
},
|
|
704
|
+
});
|
|
705
|
+
allowedDomains = domainsInput
|
|
706
|
+
.split(",")
|
|
707
|
+
.map((d) => d.trim().toLowerCase())
|
|
708
|
+
.filter((d) => d.length > 0);
|
|
709
|
+
}
|
|
211
710
|
settingsPayload.allowedDomains = allowedDomains;
|
|
212
711
|
}
|
|
213
712
|
// Update app settings with the chosen mode
|
|
@@ -218,34 +717,57 @@ async function handleInit(projectDirArg, options) {
|
|
|
218
717
|
catch (err) {
|
|
219
718
|
warn(`Could not update app settings: ${err.message}`);
|
|
220
719
|
}
|
|
221
|
-
// If invite-only, offer to add
|
|
720
|
+
// If invite-only, auto-add the authenticated user and offer to add others
|
|
222
721
|
if (accessMode === "invite-only") {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const emailsInput = await input({
|
|
229
|
-
message: "Enter email address(es) to allow (comma-separated):",
|
|
230
|
-
validate: (value) => {
|
|
231
|
-
if (!value.trim())
|
|
232
|
-
return "Please enter at least one email";
|
|
233
|
-
const emails = value.split(",").map((e) => e.trim());
|
|
234
|
-
for (const email of emails) {
|
|
235
|
-
if (!email.includes("@")) {
|
|
236
|
-
return `Invalid email: ${email}`;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return true;
|
|
240
|
-
},
|
|
722
|
+
try {
|
|
723
|
+
await client.createInvitation(appId, {
|
|
724
|
+
email: credentials.email,
|
|
725
|
+
role: "member",
|
|
726
|
+
sendEmail: false,
|
|
241
727
|
});
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
728
|
+
success(`${credentials.email} added to the invite list.`);
|
|
729
|
+
}
|
|
730
|
+
catch (err) {
|
|
731
|
+
if (!err.message?.includes("already has a pending invitation")) {
|
|
732
|
+
warn(`Could not add your email to the invite list: ${err.message}`);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
// Determine emails to invite
|
|
736
|
+
let emailsToInvite = [];
|
|
737
|
+
if (initConfig?.invite_emails && initConfig.invite_emails.length > 0) {
|
|
738
|
+
emailsToInvite = initConfig.invite_emails;
|
|
739
|
+
info(`Inviting users from config: ${emailsToInvite.join(", ")}`);
|
|
740
|
+
}
|
|
741
|
+
else if (!initConfig) {
|
|
742
|
+
const inviteNow = await confirm({
|
|
743
|
+
message: "Would you like to add initial users who can sign up? (no emails will be sent)",
|
|
744
|
+
default: false,
|
|
745
|
+
});
|
|
746
|
+
if (inviteNow) {
|
|
747
|
+
const emailsInput = await input({
|
|
748
|
+
message: "Enter email address(es) to allow (comma-separated):",
|
|
749
|
+
validate: (value) => {
|
|
750
|
+
if (!value.trim())
|
|
751
|
+
return "Please enter at least one email";
|
|
752
|
+
const emails = value.split(",").map((e) => e.trim());
|
|
753
|
+
for (const email of emails) {
|
|
754
|
+
if (!email.includes("@")) {
|
|
755
|
+
return `Invalid email: ${email}`;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
return true;
|
|
759
|
+
},
|
|
760
|
+
});
|
|
761
|
+
emailsToInvite = emailsInput
|
|
762
|
+
.split(",")
|
|
763
|
+
.map((e) => e.trim())
|
|
764
|
+
.filter((e) => e.length > 0);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
if (emailsToInvite.length > 0) {
|
|
246
768
|
info("Adding invited users...");
|
|
247
769
|
let inviteCount = 0;
|
|
248
|
-
for (const email of
|
|
770
|
+
for (const email of emailsToInvite) {
|
|
249
771
|
try {
|
|
250
772
|
await client.createInvitation(appId, {
|
|
251
773
|
email,
|
|
@@ -264,98 +786,338 @@ async function handleInit(projectDirArg, options) {
|
|
|
264
786
|
}
|
|
265
787
|
}
|
|
266
788
|
}
|
|
267
|
-
// Step
|
|
268
|
-
|
|
789
|
+
// Step 3 (deferred): install the already-prepared template + init git, now
|
|
790
|
+
// that the app exists. The network download and archive validation already
|
|
791
|
+
// happened before createApp, without touching targetDir.
|
|
792
|
+
info(`Setting up your ${platform === "ios" ? "iOS" : "web"} project...`);
|
|
269
793
|
try {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
794
|
+
preparedTemplate.install(targetDir);
|
|
795
|
+
success("Template extracted successfully.");
|
|
796
|
+
}
|
|
797
|
+
catch (err) {
|
|
798
|
+
error(`Failed to write template files: ${err.message}`);
|
|
799
|
+
cleanupPreparedTemplate();
|
|
800
|
+
process.exit(1);
|
|
801
|
+
}
|
|
802
|
+
finally {
|
|
803
|
+
cleanupPreparedTemplate();
|
|
804
|
+
}
|
|
805
|
+
// Initialize git repository (commit happens later, after env + install)
|
|
806
|
+
try {
|
|
807
|
+
await gitInitRepo(targetDir);
|
|
808
|
+
}
|
|
809
|
+
catch {
|
|
810
|
+
// Non-fatal: git may not be installed, or already a git repo
|
|
811
|
+
}
|
|
812
|
+
// Step 4.5: Update CLI to point at this app
|
|
813
|
+
try {
|
|
814
|
+
setCurrentApp(appId, appName);
|
|
815
|
+
info(`CLI now using app: ${appName} (${appId})`);
|
|
816
|
+
}
|
|
817
|
+
catch (err) {
|
|
818
|
+
// Not critical - user may not be logged in (e.g. used --use-existing-app-id without login)
|
|
819
|
+
warn(`Could not set current app in CLI config: ${err.message}`);
|
|
820
|
+
}
|
|
821
|
+
// Step 4.6: Scaffold .primitive/config.json with a "dev" environment bound
|
|
822
|
+
// to this app, and seed its credential slot with the session we just
|
|
823
|
+
// authenticated — so `primitive` commands run from inside the project pick
|
|
824
|
+
// up project mode without a second login.
|
|
825
|
+
try {
|
|
826
|
+
await scaffoldProjectConfig({ targetDir, appId, appName, serverUrl });
|
|
827
|
+
if (credentials) {
|
|
828
|
+
seedCredentialsForEnvInProject(targetDir, "dev", credentials);
|
|
280
829
|
}
|
|
830
|
+
success(`Project environment "dev" configured (.primitive/config.json).`);
|
|
281
831
|
}
|
|
282
832
|
catch (err) {
|
|
283
|
-
warn(`Could not
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
833
|
+
warn(`Could not scaffold .primitive/config.json: ${err.message}`);
|
|
834
|
+
}
|
|
835
|
+
// Steps 5-8: Platform-specific configuration and dependency installation
|
|
836
|
+
if (isApple) {
|
|
837
|
+
// ── Apple (SwiftUI) path ──────────────────────────────────────────
|
|
838
|
+
// Step 5: Update primitive.json
|
|
839
|
+
info("Configuring primitive.json...");
|
|
840
|
+
try {
|
|
841
|
+
const updated = updatePrimitiveJson(targetDir, appId, serverUrl, appName);
|
|
842
|
+
if (!updated) {
|
|
843
|
+
warn("No primitive.json file found in template.");
|
|
844
|
+
warn(`Please manually set appId to "${appId}" in your primitive.json.`);
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
success("primitive.json configured.");
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
catch (err) {
|
|
851
|
+
warn(`Could not update primitive.json: ${err.message}`);
|
|
852
|
+
warn(`Please manually set appId to "${appId}" in your primitive.json.`);
|
|
853
|
+
}
|
|
854
|
+
// Step 6-7: Skip port selection and pnpm (not applicable to Apple)
|
|
855
|
+
// Step 8: Resolve Swift packages
|
|
856
|
+
if (!skipInstall) {
|
|
857
|
+
info("Resolving Swift packages (this may take a few minutes)...");
|
|
297
858
|
try {
|
|
298
|
-
await
|
|
299
|
-
success("
|
|
859
|
+
await runSwiftPackageResolve(targetDir);
|
|
860
|
+
success("Swift packages resolved.");
|
|
300
861
|
}
|
|
301
862
|
catch (err) {
|
|
302
|
-
warn(`
|
|
303
|
-
warn("
|
|
863
|
+
warn(`Swift package resolution failed: ${err.message}`);
|
|
864
|
+
warn("You can try running 'swift package resolve' manually.");
|
|
304
865
|
}
|
|
305
866
|
}
|
|
867
|
+
else {
|
|
868
|
+
info(`Skipping dependency installation (${skipInstallReason}).`);
|
|
869
|
+
}
|
|
306
870
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
871
|
+
else {
|
|
872
|
+
// ── Web path ──────────────────────────────────────────────────────
|
|
873
|
+
// Step 5: Update .env file
|
|
874
|
+
info("Configuring environment...");
|
|
875
|
+
try {
|
|
876
|
+
const envResult = updateEnvFile(targetDir, appId, serverUrl, appName);
|
|
877
|
+
if (!envResult.envUpdated) {
|
|
878
|
+
warn("No .env or .env.example file found in template.");
|
|
879
|
+
warn(`Please manually set VITE_APP_ID=${appId} in your .env file.`);
|
|
880
|
+
}
|
|
881
|
+
else if (!envResult.envProductionUpdated) {
|
|
882
|
+
info(".env configured. No .env.production file found (this is optional).");
|
|
883
|
+
}
|
|
884
|
+
else {
|
|
885
|
+
success("Environment configured (.env and .env.production).");
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
catch (err) {
|
|
889
|
+
warn(`Could not update .env file: ${err.message}`);
|
|
890
|
+
warn(`Please manually set VITE_APP_ID=${appId} in your .env file.`);
|
|
891
|
+
}
|
|
892
|
+
// Step 6: Determine the dev port. Default to 5173; warn about taken ports
|
|
893
|
+
// when prompting. The init config's `dev_port` decides it non-interactively
|
|
894
|
+
// — this was the one branch in the command that prompted unconditionally,
|
|
895
|
+
// so the documented key was ignored and a closed stdin threw
|
|
896
|
+
// ERR_USE_AFTER_CLOSE into the catch below (#2720).
|
|
310
897
|
try {
|
|
311
|
-
|
|
312
|
-
|
|
898
|
+
const defaultPort = DEFAULT_DEV_PORT;
|
|
899
|
+
const defaultOrigin = `http://localhost:${defaultPort}`;
|
|
900
|
+
const resolvedPort = await resolveDevPort({
|
|
901
|
+
configPort: initConfig?.dev_port,
|
|
902
|
+
hasConfig: initConfig != null,
|
|
903
|
+
isTTY: Boolean(process.stdin.isTTY),
|
|
904
|
+
defaultPort,
|
|
905
|
+
promptFn: async () => {
|
|
906
|
+
console.log();
|
|
907
|
+
// Scan up to 10 ports starting from 5173 to surface what's already in use
|
|
908
|
+
const takenPorts = [];
|
|
909
|
+
for (let p = defaultPort; p < defaultPort + 10; p++) {
|
|
910
|
+
if (!(await isPortFree(p)))
|
|
911
|
+
takenPorts.push(p);
|
|
912
|
+
else
|
|
913
|
+
break;
|
|
914
|
+
}
|
|
915
|
+
if (takenPorts.length > 0) {
|
|
916
|
+
warn(`Port${takenPorts.length > 1 ? "s" : ""} ${takenPorts.join(", ")} ${takenPorts.length > 1 ? "are" : "is"} already in use.`);
|
|
917
|
+
}
|
|
918
|
+
const portInput = await input({
|
|
919
|
+
message: "Dev server port for this project:",
|
|
920
|
+
default: String(defaultPort),
|
|
921
|
+
validate: validateDevPort,
|
|
922
|
+
});
|
|
923
|
+
return parseInt(portInput, 10);
|
|
924
|
+
},
|
|
925
|
+
});
|
|
926
|
+
const chosenPort = resolvedPort.port;
|
|
927
|
+
if (resolvedPort.source === "config") {
|
|
928
|
+
info(`Dev server port: ${chosenPort} (from config)`);
|
|
929
|
+
}
|
|
930
|
+
if (chosenPort !== defaultPort) {
|
|
931
|
+
const devOrigin = `http://localhost:${chosenPort}`;
|
|
932
|
+
// Pin the port in vite.config.ts and update .env. A vite config whose
|
|
933
|
+
// shape we can't patch must be said out loud — otherwise the dev
|
|
934
|
+
// server keeps 5173 while .env and the redirect URIs point elsewhere.
|
|
935
|
+
const viteUpdated = updateViteConfig(targetDir, chosenPort);
|
|
936
|
+
if (!viteUpdated) {
|
|
937
|
+
warn(`Could not pin port ${chosenPort} in vite.config.ts — set \`server.port\` there manually.`);
|
|
938
|
+
}
|
|
939
|
+
updateEnvPort(targetDir, chosenPort);
|
|
940
|
+
// Update app settings: CORS, redirect URIs, baseUrl
|
|
941
|
+
if (!credentials) {
|
|
942
|
+
info(`Local files updated. Skipping server CORS/redirect config — not authenticated.`);
|
|
943
|
+
}
|
|
944
|
+
else {
|
|
945
|
+
try {
|
|
946
|
+
const client = new ApiClient();
|
|
947
|
+
let existingOrigins = [];
|
|
948
|
+
let existingRedirectUris = [];
|
|
949
|
+
try {
|
|
950
|
+
const currentSettings = await client.getAppSettings(appId);
|
|
951
|
+
if (currentSettings.corsMode === "custom" &&
|
|
952
|
+
Array.isArray(currentSettings.corsAllowedOrigins)) {
|
|
953
|
+
existingOrigins = currentSettings.corsAllowedOrigins;
|
|
954
|
+
}
|
|
955
|
+
if (Array.isArray(currentSettings.redirectUris)) {
|
|
956
|
+
existingRedirectUris = currentSettings.redirectUris;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
catch {
|
|
960
|
+
// Ignore — will set a fresh config
|
|
961
|
+
}
|
|
962
|
+
// Always include 5173 since it's the universal localhost default
|
|
963
|
+
const corsOrigins = Array.from(new Set([...existingOrigins, defaultOrigin, devOrigin]));
|
|
964
|
+
const redirectUris = Array.from(new Set([
|
|
965
|
+
...existingRedirectUris,
|
|
966
|
+
`${defaultOrigin}/oauth/callback`,
|
|
967
|
+
`${devOrigin}/oauth/callback`,
|
|
968
|
+
]));
|
|
969
|
+
await client.updateAppSettings(appId, {
|
|
970
|
+
corsMode: "custom",
|
|
971
|
+
corsAllowedOrigins: corsOrigins,
|
|
972
|
+
corsAllowCredentials: true,
|
|
973
|
+
redirectUris,
|
|
974
|
+
baseUrl: devOrigin,
|
|
975
|
+
});
|
|
976
|
+
success(`Dev port set to ${chosenPort}: ${viteUpdated ? "vite.config.ts, " : ""}.env, CORS, redirect URIs, and base URL updated.`);
|
|
977
|
+
}
|
|
978
|
+
catch (err) {
|
|
979
|
+
warn(`Could not update app settings: ${err.message}`);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
}
|
|
313
983
|
}
|
|
314
984
|
catch (err) {
|
|
315
|
-
|
|
316
|
-
|
|
985
|
+
// Non-fatal — but say so. A silent swallow here is what hid the closed
|
|
986
|
+
// stdin crash in #2720: the run kept 5173 and still exited 0.
|
|
987
|
+
warn(`Could not configure the dev server port: ${err.message}`);
|
|
988
|
+
warn("The project keeps the default port 5173.");
|
|
989
|
+
}
|
|
990
|
+
// Step 7: Check if pnpm is installed globally, offer to install if not
|
|
991
|
+
const pnpmInstalled = await isPnpmInstalled();
|
|
992
|
+
if (!pnpmInstalled) {
|
|
993
|
+
console.log();
|
|
994
|
+
info("pnpm is not installed globally on your system.");
|
|
995
|
+
const installPnpm = await confirm({
|
|
996
|
+
message: "Install pnpm globally? (recommended for future use)",
|
|
997
|
+
default: true,
|
|
998
|
+
});
|
|
999
|
+
if (installPnpm) {
|
|
1000
|
+
info("Installing pnpm...");
|
|
1001
|
+
try {
|
|
1002
|
+
await installPnpmGlobally();
|
|
1003
|
+
success("pnpm installed globally. You can now use 'pnpm' commands.");
|
|
1004
|
+
}
|
|
1005
|
+
catch (err) {
|
|
1006
|
+
warn(`Could not install pnpm: ${err.message}`);
|
|
1007
|
+
warn("Will use npx to run pnpm for dependency installation.");
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
// Step 8: Install dependencies with pnpm (via npx to handle version management)
|
|
1012
|
+
if (!skipInstall) {
|
|
1013
|
+
info("Installing dependencies...");
|
|
1014
|
+
try {
|
|
1015
|
+
await runPnpmInstall(targetDir);
|
|
1016
|
+
success("Dependencies installed.");
|
|
1017
|
+
}
|
|
1018
|
+
catch (err) {
|
|
1019
|
+
warn(`Dependency installation failed: ${err.message}`);
|
|
1020
|
+
warn("You can try running 'npx pnpm install' manually.");
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
else {
|
|
1024
|
+
info(`Skipping dependency installation (${skipInstallReason}).`);
|
|
317
1025
|
}
|
|
318
1026
|
}
|
|
319
|
-
|
|
320
|
-
info("Skipping dependency installation (--skip-install).");
|
|
321
|
-
}
|
|
322
|
-
// Step 8: Install primitive CLI globally if not already installed
|
|
1027
|
+
// Step 9: Install primitive CLI globally if not already installed
|
|
323
1028
|
const cliInstalled = await isPrimitiveCliInstalled();
|
|
324
1029
|
if (!cliInstalled) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
const installCli = await confirm({
|
|
328
|
-
message: "Install the Primitive CLI globally?",
|
|
329
|
-
default: true,
|
|
330
|
-
});
|
|
331
|
-
if (installCli) {
|
|
1030
|
+
if (initConfig) {
|
|
1031
|
+
// Non-interactive: auto-install CLI
|
|
332
1032
|
info("Installing Primitive CLI...");
|
|
333
1033
|
try {
|
|
334
1034
|
await installPrimitiveCli();
|
|
335
|
-
success("Primitive CLI installed.
|
|
1035
|
+
success("Primitive CLI installed.");
|
|
336
1036
|
}
|
|
337
1037
|
catch (err) {
|
|
338
1038
|
warn(`Could not install CLI: ${err.message}`);
|
|
339
|
-
warn(
|
|
1039
|
+
warn(`You can install it manually with: ${installCommand(PRIMITIVE_CLI_PACKAGE)}`);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
else {
|
|
1043
|
+
console.log();
|
|
1044
|
+
info("The Primitive CLI helps you manage your app from the command line.");
|
|
1045
|
+
const installCli = await confirm({
|
|
1046
|
+
message: "Install the Primitive CLI globally?",
|
|
1047
|
+
default: true,
|
|
1048
|
+
});
|
|
1049
|
+
if (installCli) {
|
|
1050
|
+
info("Installing Primitive CLI...");
|
|
1051
|
+
try {
|
|
1052
|
+
await installPrimitiveCli();
|
|
1053
|
+
success("Primitive CLI installed. You can now use 'primitive' commands.");
|
|
1054
|
+
}
|
|
1055
|
+
catch (err) {
|
|
1056
|
+
warn(`Could not install CLI: ${err.message}`);
|
|
1057
|
+
warn(`You can install it manually with: ${installCommand(PRIMITIVE_CLI_PACKAGE)}`);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
// Step 10: Offer to install Claude Code skill if not already installed
|
|
1063
|
+
try {
|
|
1064
|
+
const { isSkillInstalled, installSkillExplicit, checkSkillStatus } = await import("../lib/skill-installer.js");
|
|
1065
|
+
if (isSkillInstalled()) {
|
|
1066
|
+
// Already installed — silently auto-update if a newer version is bundled
|
|
1067
|
+
await checkSkillStatus();
|
|
1068
|
+
}
|
|
1069
|
+
else if (initConfig) {
|
|
1070
|
+
// Non-interactive: auto-install skill
|
|
1071
|
+
await installSkillExplicit();
|
|
1072
|
+
}
|
|
1073
|
+
else {
|
|
1074
|
+
console.log();
|
|
1075
|
+
info("The Primitive platform skill gives Claude Code expertise with Primitive APIs and patterns.");
|
|
1076
|
+
const installSkill = await confirm({
|
|
1077
|
+
message: "Install the Primitive platform skill for Claude Code?",
|
|
1078
|
+
default: true,
|
|
1079
|
+
});
|
|
1080
|
+
if (installSkill) {
|
|
1081
|
+
await installSkillExplicit();
|
|
340
1082
|
}
|
|
341
1083
|
}
|
|
342
1084
|
}
|
|
343
|
-
|
|
1085
|
+
catch {
|
|
1086
|
+
// Non-fatal: skill installation should never block init
|
|
1087
|
+
}
|
|
1088
|
+
// Step 11: Create initial git commit (captures env config + installed dependencies)
|
|
1089
|
+
try {
|
|
1090
|
+
await gitInitialCommit(targetDir);
|
|
1091
|
+
}
|
|
1092
|
+
catch {
|
|
1093
|
+
// Non-fatal: git may not be installed, or already committed
|
|
1094
|
+
}
|
|
1095
|
+
// Step 12: Show success message
|
|
344
1096
|
divider();
|
|
345
1097
|
success("Project initialized successfully!");
|
|
346
1098
|
divider();
|
|
347
1099
|
keyValue("Directory", targetDir);
|
|
348
1100
|
keyValue("App Name", appName);
|
|
349
1101
|
keyValue("App ID", appId);
|
|
1102
|
+
keyValue("Platform", platform === "ios" ? "iOS (SwiftUI)" : "Web");
|
|
350
1103
|
divider();
|
|
351
1104
|
info("Next steps:");
|
|
352
1105
|
if (projectDir !== ".") {
|
|
353
1106
|
console.log(` cd ${projectDir}`);
|
|
354
1107
|
}
|
|
355
|
-
if (
|
|
356
|
-
|
|
1108
|
+
if (isApple) {
|
|
1109
|
+
if (skipInstall) {
|
|
1110
|
+
console.log(" swift package resolve");
|
|
1111
|
+
}
|
|
1112
|
+
console.log(" open *.xcodeproj");
|
|
1113
|
+
console.log(" # or: ./run-ios.sh (iOS Simulator)");
|
|
1114
|
+
}
|
|
1115
|
+
else {
|
|
1116
|
+
if (skipInstall) {
|
|
1117
|
+
console.log(" pnpm install");
|
|
1118
|
+
}
|
|
1119
|
+
console.log(" pnpm dev");
|
|
357
1120
|
}
|
|
358
|
-
console.log(" pnpm run dev");
|
|
359
1121
|
console.log();
|
|
360
1122
|
}
|
|
361
1123
|
//# sourceMappingURL=init.js.map
|