From ce48d9969fa08344b12eee171aa1c9e3eff7ae5a Mon Sep 17 00:00:00 2001 From: Taylor Beseda Date: Mon, 8 Apr 2024 21:53:56 -0600 Subject: [PATCH] copy folder with pkg compat --- .github/workflows/binary-build.yml | 9 ++++----- src/commands/new/action.js | 29 +++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/.github/workflows/binary-build.yml b/.github/workflows/binary-build.yml index de1596c..5d6b501 100644 --- a/.github/workflows/binary-build.yml +++ b/.github/workflows/binary-build.yml @@ -12,11 +12,10 @@ jobs: # Test the build build: # Setup - runs-on: ubuntu-latest - # runs-on: ${{ matrix.os }} - # strategy: - # matrix: - # os: [ windows-latest, ubuntu-latest, macOS-latest, self-hosted ] + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ windows-latest, ubuntu-latest, macOS-latest, self-hosted ] # Go steps: diff --git a/src/commands/new/action.js b/src/commands/new/action.js index 0657abc..991afed 100644 --- a/src/commands/new/action.js +++ b/src/commands/new/action.js @@ -1,5 +1,5 @@ module.exports = async function (params) { - let { cpSync, existsSync, mkdirSync, readFileSync } = require('fs') + let { lstatSync, copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync } = require('fs') let { isAbsolute, join, normalize } = require('path') let { args } = params @@ -31,7 +31,7 @@ module.exports = async function (params) { } // App name (optional) - let appName = args.name || args.n ? args.name || args.n : 'begin-app' + let appName = args.name || args.n ? args.name || args.n : 'begin-app' if (!looseName.test(appName)) { return error('invalid_appname') } @@ -62,9 +62,30 @@ module.exports = async function (params) { // Starter project files let appPath = join(nodeModules, '@enhance', 'starter-project', 'app') let publicPath = join(nodeModules, '@enhance', 'starter-project', 'public') + + /* pkg workaround */ + function copyFolderSync (from, to) { + mkdirSync(to) + readdirSync(from).forEach(element => { + const sourcePath = join(from, element) + const destinationPath = join(to, element) + if (lstatSync(sourcePath).isFile()) { + copyFileSync(sourcePath, destinationPath) + } + else { + copyFolderSync(sourcePath, destinationPath) + } + }) + } + // Copy app dirs - cpSync(appPath, p('app'), { recursive: true }) - cpSync(publicPath, p('public'), { recursive: true }) + copyFolderSync(appPath, p('app')) + copyFolderSync(publicPath, p('public')) + /* end pkg workaround */ + + // Use this when pkg is no longer used: + // fs.cpSync(appPath, p('app'), { recursive: true }) + // fs.cpSync(publicPath, p('public'), { recursive: true }) // Write .gitignore let gitIgnoreTemplate = join(nodeModules, '@enhance', 'starter-project', 'template.gitignore')