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
2 changes: 1 addition & 1 deletion apps/csk-marketing-site/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uniformdev/csk-marketing-site",
"version": "6.1.52",
"version": "6.1.53",
"private": true,
"engines": {
"yarn": "please-use-npm",
Expand Down
2 changes: 1 addition & 1 deletion apps/csk-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uniformdev/csk-storybook",
"version": "6.1.52",
"version": "6.1.53",
"description": "CSK vNext Storybook is an interactive Storybook build showcasing components from the CSK vNext component starter kit. It provides detailed documentation, live previews, and testing capabilities for easy integration into your projects.",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion apps/csk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uniformdev/component-starter-kit",
"version": "6.1.52",
"version": "6.1.53",
"private": true,
"engines": {
"yarn": "please-use-npm",
Expand Down
572 changes: 327 additions & 245 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "csk-packages",
"version": "6.1.52",
"version": "6.1.53",
"private": true,
"scripts": {
"build": "turbo build",
Expand Down
2 changes: 1 addition & 1 deletion packages/csk-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uniformdev/csk-cli",
"version": "6.1.52",
"version": "6.1.53",
"description": "Command-line interface (CLI) tool designed to streamline the development workflow within Uniform projects. It provides commands for pulling additional data and generating components based on Canvas data",
"license": "SEE LICENSE IN LICENSE.txt",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/csk-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uniformdev/csk-components",
"version": "6.1.52",
"version": "6.1.53",
"description": "Components Starter Kit that provides a set of basic components for building websites within a Uniform project",
"license": "SEE LICENSE IN LICENSE.txt",
"engines": {
Expand Down
6 changes: 4 additions & 2 deletions packages/csk-recipes/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uniformdev/csk-recipes",
"version": "6.1.52",
"version": "6.1.53",
"description": "command-line interface (CLI) and utility functions to help you work with recipes in a CSK project. It simplifies project initialization by allowing you to choose templates and include specific recipes",
"license": "SEE LICENSE IN LICENSE.txt",
"engines": {
Expand Down Expand Up @@ -40,12 +40,14 @@
"dotenv": "16.4.7",
"open": "^10.1.2",
"ora": "^8.2.0",
"prettier": "3.6.2"
"prettier": "3.6.2",
"unzipper": "^0.12.3"
},
"devDependencies": {
"@repo/eslint-config": "*",
"@repo/typescript-config": "*",
"@types/jest": "^29.5.14",
"@types/unzipper": "^0.10.11",
"@uniformdev/canvas": "20.7.1-alpha.97",
"next": "^16.0.7",
"react": "^19.2.1",
Expand Down
98 changes: 95 additions & 3 deletions packages/csk-recipes/src/commands/init/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

import fsSync from 'fs';
import fs from 'fs/promises';
import { mkdir } from 'node:fs/promises';
import https from 'node:https';
import * as ora from 'ora';
import path from 'path';
import { Extract } from 'unzipper';
import { select, checkbox, confirm, input } from '@inquirer/prompts';
import { EnvVariable, Recipe, Template } from './types';
import {
Expand All @@ -24,8 +27,92 @@ import {
REQUIRED_UNIFORM_ENV_VARIABLES,
PACKAGE_VERSION,
EXCLUDE_TEMPLATE_SPECIFIC_RECIPES,
REPO,
ORGANIZATION,
} from '../../constants';
import { runCmdCommand, spawnCmdCommand } from '../../utils';
import { runCmdCommand } from '../../utils';

/**
* Downloads a GitHub branch as ZIP and extracts it into destDir.
* Works on Windows, Linux and macOS the same way.
* No .git folder is created – only sources.
*/
export async function downloadAndExtractGithubBranch({
owner,
repo,
branch,
destDir,
}: {
owner: string;
repo: string;
branch: string;
destDir: string;
}): Promise<void> {
const url = `https://github.com/${owner}/${repo}/archive/refs/heads/${branch}.zip`;

await mkdir(destDir, { recursive: true });

await new Promise<void>((resolve, reject) => {
https
.get(url, res => {
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
https
.get(res.headers.location, redirectRes => {
if (redirectRes.statusCode !== 200) {
reject(new Error(`Failed to download ZIP after redirect: HTTP ${redirectRes.statusCode}`));
return;
}
redirectRes
.pipe(Extract({ path: destDir }))
.on('close', () => resolve())
.on('error', reject);
})
.on('error', reject);
return;
}

if (res.statusCode !== 200) {
reject(new Error(`Failed to download ZIP: HTTP ${res.statusCode}`));
return;
}
res
.pipe(Extract({ path: destDir }))
.on('close', () => resolve())
.on('error', reject);
})
.on('error', reject);
});

const entries = fsSync.readdirSync(destDir, { withFileTypes: true });
const extractedRootDir = entries.find(entry => entry.isDirectory() && entry.name.startsWith(`${repo}-`));

if (!extractedRootDir) {
return;
}

const extractedRootPath = path.join(destDir, extractedRootDir.name);

const moveRecursive = (src: string, dst: string) => {
const items = fsSync.readdirSync(src, { withFileTypes: true });

for (const item of items) {
const srcPath = path.join(src, item.name);
const dstPath = path.join(dst, item.name);

if (item.isDirectory()) {
if (!fsSync.existsSync(dstPath)) {
fsSync.mkdirSync(dstPath, { recursive: true });
}
moveRecursive(srcPath, dstPath);
} else {
fsSync.copyFileSync(srcPath, dstPath);
}
}
};

moveRecursive(extractedRootPath, destDir);
fsSync.rmSync(extractedRootPath, { recursive: true, force: true });
}

export const verifyGitProject = async (
spinner: ora.Ora
Expand Down Expand Up @@ -349,12 +436,17 @@ export const alignWithExternalBranch = async (branchName: string): Promise<void>
fsSync.rmSync(pathToClonedRepo, { recursive: true, force: true });
}

await spawnCmdCommand(GIT_COMMANDS.ALIGN_WITH_EXTERNAL_BRANCH(branchName));
await downloadAndExtractGithubBranch({
owner: ORGANIZATION,
repo: REPO,
branch: branchName,
destDir: pathToClonedRepo,
});

const appPath = fsSync.existsSync(newPath) ? newPath : oldPath;

// Remove files that are not needed before copying the new app
['content', 'node_modules', '.next'].forEach(file => {
['content', '.next'].forEach(file => {
const filePath = path.join(process.cwd(), file);
if (fsSync.existsSync(filePath)) {
fsSync.rmSync(filePath, { recursive: true, force: true });
Expand Down
5 changes: 3 additions & 2 deletions packages/csk-recipes/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ export const EXCLUDE_TEMPLATE_SPECIFIC_RECIPES: Partial<{
'coffee-shop-localized': ['localization'],
};

export const ORGANIZATION = 'uniformdev';
export const REPO = 'csk-packages';

export const GIT_COMMANDS = {
CHECK_IF_GIT: 'git status >/dev/null 2>&1',
ALIGN_WITH_EXTERNAL_BRANCH: (branchName: string) =>
`git clone https://github.com/uniformdev/csk-packages.git --branch ${branchName}`,
GET_CHANGED_FILES: 'git ls-files --modified --others --exclude-standard',
};

Expand Down
2 changes: 1 addition & 1 deletion packages/design-extensions-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uniformdev/design-extensions-tools",
"version": "6.1.52",
"version": "6.1.53",
"description": "Command-line interface (CLI) tool and a set of utilities for working with design extension integrations",
"license": "SEE LICENSE IN LICENSE.txt",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@repo/eslint-config",
"version": "6.1.52",
"version": "6.1.53",
"type": "module",
"private": true,
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/internal-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@repo/internal-scripts",
"version": "6.1.52",
"version": "6.1.53",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@repo/typescript-config",
"version": "6.1.52",
"version": "6.1.53",
"private": true,
"license": "MIT",
"publishConfig": {
Expand Down