0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor: use connector link in workflows

This commit is contained in:
Gao Sun 2023-04-02 14:12:30 +08:00
parent 0f9ac8ee70
commit 612a1d5301
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
10 changed files with 45 additions and 18 deletions

View file

@ -3,7 +3,7 @@
"features": { "features": {
"ghcr.io/devcontainers/features/node:1": {} "ghcr.io/devcontainers/features/node:1": {}
}, },
"updateContentCommand": "npm i -g pnpm && pnpm i && pnpm prepack && pnpm cli connector add --official -p .", "updateContentCommand": "npm i -g pnpm && pnpm i && pnpm prepack && pnpm connectors:build && pnpm cli connector link -p .",
"postStartCommand": "docker run -d -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=p0stgr3s postgres:14-alpine", "postStartCommand": "docker run -d -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=p0stgr3s postgres:14-alpine",
"postAttachCommand": "pnpm cli db seed && [[ ! -z $CODESPACES ]] && export ENDPOINT=https://$CODESPACE_NAME-3001.preview.app.github.dev", "postAttachCommand": "pnpm cli db seed && [[ ! -z $CODESPACES ]] && export ENDPOINT=https://$CODESPACE_NAME-3001.preview.app.github.dev",
"containerEnv": { "containerEnv": {

View file

@ -101,7 +101,9 @@ If you are developing something with database alterations, see [packages/schemas
### Add connectors (optional) ### Add connectors (optional)
Run `pnpm cli connector add --official -p .` to add all Logto official connectors. See [Manage connectors](https://docs.logto.io/docs/tutorials/using-cli/manage-connectors) for details about managing connectors via CLI. Run `logto connector link -p .` to link all local connectors. You can also use `logto connector add <name> -p .` to install connector from NPM.
See [Manage connectors](https://docs.logto.io/docs/tutorials/using-cli/manage-connectors) for details about managing connectors via CLI.
## Start dev ## Start dev

View file

@ -107,7 +107,7 @@ jobs:
working-directory: tests working-directory: tests
run: | run: |
npm run cli connector list -- -p ../logto | grep OFFICIAL npm run cli connector list -- -p ../logto | grep OFFICIAL
npm run cli connector add @logto/connector-mock-sms @logto/connector-mock-email @logto/connector-mock-standard-email @logto/connector-mock-social -- -p ../logto npm run cli connector link -- --mock -p ../logto
- name: Run Logto - name: Run Logto
working-directory: logto/ working-directory: logto/

View file

@ -12,7 +12,8 @@ tasks:
cd packages/core cd packages/core
pnpm build pnpm build
cd - cd -
pnpm cli connector add --official -p . pnpm connectors:build
pnpm cli connector link
command: | command: |
gp ports await 5432 gp ports await 5432
sleep 3 sleep 3

View file

@ -26,7 +26,7 @@ packages/**/*.config.js packages/**/*.config.ts packages/**/tsconfig*.json \
# Add official connectors # Add official connectors
cloud_option=$( [[ "$IS_CLOUD" =~ ^(1|true|y|yes|yep|yeah)$ ]] && echo "--cloud" || echo "" ) cloud_option=$( [[ "$IS_CLOUD" =~ ^(1|true|y|yes|yep|yeah)$ ]] && echo "--cloud" || echo "" )
pnpm cli connector add --official $cloud_option -p . pnpm cli connector link $cloud_option -p .
echo Tar echo Tar
cd .. cd ..

View file

@ -21,7 +21,7 @@ RUN pnpm -r build
### Add official connectors ### ### Add official connectors ###
ARG additional_connector_args ARG additional_connector_args
ENV ADDITIONAL_CONNECTOR_ARGS=${additional_connector_args} ENV ADDITIONAL_CONNECTOR_ARGS=${additional_connector_args}
RUN pnpm cli connector add --official $ADDITIONAL_CONNECTOR_ARGS -p . RUN pnpm cli connector link $ADDITIONAL_CONNECTOR_ARGS -p .
### Prune dependencies for production ### ### Prune dependencies for production ###
RUN rm -rf node_modules packages/**/node_modules RUN rm -rf node_modules packages/**/node_modules

View file

@ -24,10 +24,10 @@ ENV IS_CLOUD=1
ARG applicationinsights_connection_string ARG applicationinsights_connection_string
ENV APPLICATIONINSIGHTS_CONNECTION_STRING=${applicationinsights_connection_string} ENV APPLICATIONINSIGHTS_CONNECTION_STRING=${applicationinsights_connection_string}
RUN pnpm prepack RUN pnpm prepack
RUN pnpm -r --filter @logto/console --filter @logto/cloud build RUN pnpm connectors:build && pnpm -r --filter @logto/console --filter @logto/cloud build
### Add official connectors ### ### Add official connectors ###
RUN pnpm cli connector add --official -p . RUN pnpm cli connector link -p .
### Prune dependencies for production ### ### Prune dependencies for production ###
RUN rm -rf node_modules packages/**/node_modules RUN rm -rf node_modules packages/**/node_modules

View file

@ -10,12 +10,13 @@
"prepack": "pnpm -r prepack", "prepack": "pnpm -r prepack",
"dev": "pnpm -r prepack && pnpm start:dev", "dev": "pnpm -r prepack && pnpm start:dev",
"dev:cloud": "pnpm -r prepack && pnpm start:dev:cloud", "dev:cloud": "pnpm -r prepack && pnpm start:dev:cloud",
"start:dev": "pnpm -r --parallel --filter=!@logto/integration-tests --filter=!@logto/cloud dev", "start:dev": "pnpm -r --parallel --filter=!@logto/integration-tests --filter \"!./packages/connectors/connector-*\" --filter=!@logto/cloud dev",
"start:dev:cloud": "CONSOLE_PUBLIC_URL=/ IS_CLOUD=1 pnpm -r --parallel --filter=!@logto/integration-tests dev", "start:dev:cloud": "CONSOLE_PUBLIC_URL=/ IS_CLOUD=1 pnpm -r --parallel --filter=!@logto/integration-tests --filter \"!./packages/connectors/connector-*\" dev",
"start": "cd packages/core && NODE_ENV=production node .", "start": "cd packages/core && NODE_ENV=production node .",
"start:cloud": "cd packages/cloud && NODE_ENV=production node .", "start:cloud": "cd packages/cloud && NODE_ENV=production node .",
"cli": "logto", "cli": "logto",
"alteration": "logto db alt", "alteration": "logto db alt",
"connectors:build": "pnpm -r --filter \"./packages/connectors/connector-*\" build",
"//": "# `changeset version` won't run version lifecycle scripts, see https://github.com/changesets/changesets/issues/860", "//": "# `changeset version` won't run version lifecycle scripts, see https://github.com/changesets/changesets/issues/860",
"ci:version": "changeset version && pnpm -r version", "ci:version": "changeset version && pnpm -r version",
"ci:build": "pnpm -r build", "ci:build": "pnpm -r build",

View file

@ -7,22 +7,45 @@ import { log } from '../../utils.js';
import { getConnectorDirectory, getLocalConnectorPackages, inquireInstancePath } from './utils.js'; import { getConnectorDirectory, getLocalConnectorPackages, inquireInstancePath } from './utils.js';
const link: CommandModule<{ path?: string }, { path?: string }> = { const link: CommandModule<{ path?: string }, { path?: string; cloud: boolean; mock: boolean }> = {
command: ['link', 'ln'], command: ['link', 'ln'],
describe: 'Link all connectors in `packages/connectors`, useful for adding local connectors.', describe: 'Link all connectors in `packages/connectors`, useful for adding local connectors.',
handler: async ({ path: inputPath }) => { builder: (yargs) =>
yargs
.option('cloud', {
describe: 'Add additional connectors for Logto Cloud',
type: 'boolean',
default: false,
hidden: true,
})
.option('mock', {
describe: 'Add mock connectors',
type: 'boolean',
default: false,
hidden: true,
}),
handler: async ({ path: inputPath, cloud, mock }) => {
const instancePath = await inquireInstancePath(inputPath); const instancePath = await inquireInstancePath(inputPath);
const packages = await getLocalConnectorPackages(instancePath); const packages = await getLocalConnectorPackages(instancePath);
const connectorDirectory = getConnectorDirectory(instancePath);
await fs.mkdir(connectorDirectory, { recursive: true });
await Promise.all( await Promise.all(
packages.map(async ([packageName, packagePath]) => { packages.map(async ([packageName, packagePath]) => {
if (!cloud && packageName.startsWith('connector-logto-')) {
return;
}
if (!mock && packageName.startsWith('connector-mock-')) {
return;
}
try { try {
const targetPath = path.join( const targetPath = path.join(connectorDirectory, '@logto-' + packageName);
getConnectorDirectory(instancePath),
'@logto-' + packageName
);
await fs.rm(targetPath, { recursive: true, force: true }); await fs.rm(targetPath, { recursive: true, force: true });
await fs.symlink(path.resolve(packagePath), targetPath); await fs.symlink(path.relative(connectorDirectory, packagePath), targetPath);
} catch (error) { } catch (error) {
log.warn(error); log.warn(error);

View file

@ -14,7 +14,7 @@ const checkConnectorKitVersion = (dependencies: unknown, ignoreVersionMismatch:
const value = dependencies[connectorKit]; const value = dependencies[connectorKit];
if (typeof value === 'string') { if (typeof value === 'string') {
if (satisfies(currentVersion, value)) { if (value.startsWith('workspace:') || satisfies(currentVersion, value)) {
return; return;
} }