Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release

permissions:
contents: write
id-token: write

on:
push:
tags:
- 'v*'
workflow_dispatch:

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v6
with:
node-version: 22
registry-url: 'https://registry.npmjs.org'

- run: pnpm install --frozen-lockfile

- run: pnpm build

- run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- run: npm i -g npm@latest
- run: pnpm -r --dir packages --no-git-checks publish --access public --provenance
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"lint": "eslint --fix packages/**/*.{ts,js,json}",
"test": "pnpm -r test",
"test:watch": "pnpm -r test:watch",
"release": "pnpm build && bumpp packages/*/package.json --commit \"release: v\" --push --tag && pnpm -r release"
"bump": "bumpp package.json packages/*/package.json --commit \"release: v\" --push --tag",
"release": "pnpm bump"
},
"workspaces": {
"packages": [
Expand Down Expand Up @@ -39,6 +40,12 @@
"ejs@<3.1.10": ">=3.1.10",
"tar@<6.2.1": ">=6.2.1",
"ws@>=8.0.0 <8.17.1": ">=8.17.1"
}
},
"onlyBuiltDependencies": [
"esbuild",
"mmap-io",
"shmmap",
"yarn"
]
}
}
5 changes: 2 additions & 3 deletions packages/app/lib/cli/commands/app/dev.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Cli, Worker } from '@youcan/cli-kit';
import process from 'node:process';
import { bootAppWorker, bootExtensionWorker, bootTunnelWorker, bootWebWorker } from '@/cli/services/dev/workers';
import { getAppEnvironmentVariables } from '@/cli/services/environment-variables';
import { APP_CONFIG_FILENAME } from '@/constants';
import { AppCommand } from '@/util/app-command';
import { load } from '@/util/app-loader';
Expand Down Expand Up @@ -196,9 +197,7 @@ class Dev extends AppCommand {
}

return {
YOUCAN_API_KEY: this.app.remote_config.client_id,
YOUCAN_API_SECRET: this.app.remote_config.client_secret,
YOUCAN_API_SCOPES: this.app.remote_config.scopes.join(','),
...getAppEnvironmentVariables(this.app),
APP_URL: this.app.network_config.app_url,
PORT: this.app.network_config.app_port.toString(),
};
Expand Down
49 changes: 49 additions & 0 deletions packages/app/lib/cli/commands/app/env/pull.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { getAppEnvironmentVariables } from '@/cli/services/environment-variables';
import { AppCommand } from '@/util/app-command';
import { load } from '@/util/app-loader';
import { Flags } from '@oclif/core';
import { Color, Filesystem, Path, Session, Tasks, UI } from '@youcan/cli-kit';

class EnvPull extends AppCommand {
static description = 'Create or update a .env file with app environment variables';

static flags = {
'env-file': Flags.string({
description: 'Path to the .env file to create or update',
default: '.env',
}),
};

async run(): Promise<any> {
const { flags } = await this.parse(EnvPull);
const envFilePath = Path.resolve(flags['env-file']);

this.app = await load();
this.session = await Session.authenticate(this);

await Tasks.run({}, [
{
title: 'Syncing app configuration..',
task: async () => { await this.syncAppConfig(); },
},
]);

await this.writeEnvFile(envFilePath);
}

private async writeEnvFile(filePath: string) {
const envVars = getAppEnvironmentVariables(this.app);

const envContent = Object.entries(envVars)
.map(([key, value]) => `${key}=${value}`)
.join('\n');

await Filesystem.writeFile(filePath, `${envContent}\n`);

this.log();
this.log(`${Color.green('[OK]')} Environment variables written to ${Color.cyan(filePath)}`);
this.log();
}
}

export default EnvPull;
13 changes: 6 additions & 7 deletions packages/app/lib/cli/commands/app/env/show.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getAppEnvironmentVariables } from '@/cli/services/environment-variables';
import { AppCommand } from '@/util/app-command';
import { load } from '@/util/app-loader';
import { Color, Session, Tasks } from '@youcan/cli-kit';
import { Color, Env, Session, Tasks } from '@youcan/cli-kit';

class EnvShow extends AppCommand {
static description = 'Display app environment variables';
Expand All @@ -20,14 +21,12 @@ class EnvShow extends AppCommand {
}

private async printEnvironmentVariables() {
if (!this.app.remote_config) {
throw new Error('remote app config not loaded');
}
const envVars = getAppEnvironmentVariables(this.app);

this.log();
this.log(`${Color.yellow('YOUCAN_API_KEY')}=%s`, this.app.remote_config.client_id);
this.log(`${Color.yellow('YOUCAN_API_SECRET')}=%s`, this.app.remote_config.client_secret);
this.log(`${Color.yellow('YOUCAN_API_SCOPES')}=%s`, this.app.remote_config.scopes.join(','));
for (const [key, value] of Object.entries(envVars)) {
this.log(`${Color.yellow(key)}=${value}`);
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions packages/app/lib/cli/services/environment-variables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { App } from '@/types';
import { Env } from '@youcan/cli-kit';

export function getAppEnvironmentVariables(app: App): Record<string, string> {
if (!app.remote_config) {
throw new Error('remote app config not loaded');
}

return {
YOUCAN_API_KEY: app.remote_config.client_id,
YOUCAN_API_SECRET: app.remote_config.client_secret,
YOUCAN_API_SCOPES: app.remote_config.scopes.join(','),
YOUCAN_API_URL: `https://${Env.apiHostname()}`,
YOUCAN_SELLER_AREA_URL: `https://${Env.sellerAreaHostname()}`,
};
}
14 changes: 10 additions & 4 deletions packages/create-app/lib/services/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ async function initService(command: Cli.Command, options: InitServiceOptions) {
{
title: 'Configuring app...',
task: async () => {
await Filesystem.writeJsonFile(
Path.join(templateDownloadDirectory, 'youcan.app.json'),
{ name: slug },
);
const configPath = Path.join(templateDownloadDirectory, 'youcan.app.json');
const configExists = await Filesystem.exists(configPath);

if (configExists) {
const existingConfig = await Filesystem.readJsonFile(configPath);
await Filesystem.writeJsonFile(configPath, { ...existingConfig, name: slug });
}
else {
await Filesystem.writeJsonFile(configPath, { name: slug });
}
},
},
{
Expand Down