diff --git a/.gitignore b/.gitignore index 70970a1d..e5c3bee9 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,4 @@ templates/**/package-lock.json /playwright/.cache/ # We generate this on publish -boilerplate \ No newline at end of file +boilerplate/functions \ No newline at end of file diff --git a/src/templates/github-actions.ts b/boilerplate/github/deploy.yml similarity index 80% rename from src/templates/github-actions.ts rename to boilerplate/github/deploy.yml index 828f9c16..f82921d0 100644 --- a/src/templates/github-actions.ts +++ b/boilerplate/github/deploy.yml @@ -1,4 +1,4 @@ -export const GITHUB_ACTION_DEPLOY = `name: Deploy to Juno +name: Deploy to Juno on: workflow_dispatch: @@ -6,7 +6,7 @@ on: branches: [main] jobs: - build: + publish: runs-on: ubuntu-latest steps: - name: Check out the repo @@ -25,4 +25,4 @@ jobs: with: args: deploy env: - JUNO_TOKEN: $\{{ secrets.JUNO_TOKEN }}` \ No newline at end of file + JUNO_TOKEN: ${{ secrets.JUNO_TOKEN }} diff --git a/scripts/cli-to-boilerplate.sh b/scripts/cli-to-boilerplate.sh index e299e447..5079a27b 100755 --- a/scripts/cli-to-boilerplate.sh +++ b/scripts/cli-to-boilerplate.sh @@ -5,15 +5,14 @@ set -e NPM_ROOT=$(npm root -g) SRC="$NPM_ROOT/@junobuild/cli/templates/eject" -DEST="./boilerplate" -DEST_FUNCTIONS="$DEST/functions" +DEST="./boilerplate/functions" if [ -d "$DEST" ]; then rm -rf "$DEST" fi -mkdir -p "$DEST_FUNCTIONS" +mkdir -p "$DEST" -cp -r "$SRC/"* "$DEST_FUNCTIONS/" +cp -r "$SRC/"* "$DEST/" echo "✅ Boilerplate copied to $DEST" \ No newline at end of file diff --git a/src/services/generate.services.ts b/src/services/generate.services.ts index bac4b5d7..0d0cdb62 100644 --- a/src/services/generate.services.ts +++ b/src/services/generate.services.ts @@ -6,11 +6,11 @@ import {writeFile} from 'node:fs/promises'; import {basename, join, parse} from 'node:path'; import ora from 'ora'; import {BOILERPLATE_PATH, JUNO_CDN_URL} from '../constants/constants'; -import {GITHUB_ACTION_DEPLOY} from '../templates/github-actions'; import type {PopulateInput, ServerlessFunctions} from '../types/generator'; import {untarFile, type UntarOutputFile} from '../utils/compress.utils'; import { copyFiles, + createFolders, createParentFolders, getLocalTemplatePath, getRelativeTemplatePath @@ -125,11 +125,13 @@ const populateFromLocal = async ({where, template, localDevelopment}: PopulateIn }; const populateGitHubAction = async ({where}: PopulateInputFn) => { - const target = join(where ?? '', '.github', 'workflows', 'deploy.yaml'); + const target = join(where ?? '', '.github', 'workflows'); - createParentFolders(target); + createFolders(target); - await writeFile(target, GITHUB_ACTION_DEPLOY); + const source = join(BOILERPLATE_PATH, 'github'); + + await copyFiles({source, target}); }; const updatePackageJson = async ({ diff --git a/src/utils/fs.utils.ts b/src/utils/fs.utils.ts index 9dc27de0..fb6fd8c4 100644 --- a/src/utils/fs.utils.ts +++ b/src/utils/fs.utils.ts @@ -17,9 +17,15 @@ export const getLocalTemplatePath = ({key}: {key: TemplateKey}) => export const createParentFolders = (target: string) => { const folder = dirname(target); - if (!existsSync(folder)) { - mkdirSync(folder, {recursive: true}); + createFolders(folder); +}; + +export const createFolders = (folder: string) => { + if (existsSync(folder)) { + return; } + + mkdirSync(folder, {recursive: true}); }; export const copyFiles = async ({source, target}: {source: string; target: string}) => {