I'm trying to create a workflow for creating a Create React App template. A new extended version of this question I asked, wasn't sure if I should comment on that one or create a new post, so sorry if this is repetitive!
The process should be:
Create folder inside Codes with the name passed in arguments
Go inside that folder with the terminal, and run this command:
npx create-react-app ./ --template typescrip
Once the nix command finishes, delete the src folder created in the project, and copy the template src folder (my react boilerplate template I have in my workflow folder) to the project.
Open in VS Code
This is my NodeJS code right now, commented out step 3 as I first want to get my npx command to work.
import { spawn } from 'child_process'
import alfy from 'alfy'
import fs from 'fs-extra'
import os from 'os'
async function run() {
const homePath = os.homedir()
const dirName = alfy.input
const fullPath = homePath + '/Codes/' + dirName
if (fs.existsSync(fullPath)) return alfy.output([{ title: 'Folder already exists' }])
await fs.promises.mkdir(fullPath)
const ls = spawn(`cd ${fullPath} && npx create-react-app ./ --template typescript`, {
shell: '/bin/zsh',
})
ls.stdout.on('data', data => {
console.log(`stdout: ${data}`)
})
ls.stderr.on('data', data => {
console.log(`stderr: ${data}`)
})
ls.on('error', error => {
console.log(`error: ${error.message}`)
})
ls.on('close', code => {
console.log(`child process exited with code ${code}`)
})
// fs.rmdirSync(fullPath + '/src', { recursive: true, force: true })
// fs.mkdirSync(fullPath + '/src')
// fs.copySync('src', fullPath + '/src')
}
run()
The error inside the Alfred debugger: stderr: zsh:1: command not found: npx
New to child_process in NodeJS, so I'm sure it's something obvious I'm missing!
Hope that makes sense, any help is appreciated! ☺️