Skip to content

Commit

Permalink
ask for npm/yarn when creating new project
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jul 24, 2023
1 parent 40dc3d7 commit b0e34d6
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions cli/src/init.ts
Expand Up @@ -313,11 +313,11 @@ src/main.ts default DeviceScript entry point
## Local/container development
- install [Node.js LTS 16+](https://nodejs.org/en/download)
- install [Node.js LTS](https://nodejs.org/en/download)
\`\`\`bash
nvm install 16
nvm use 16
nvm install --lts
nvm use --lts
\`\`\`
- install DeviceScript compiler and tools
Expand Down Expand Up @@ -450,8 +450,11 @@ function finishAdd(message: string, files: string[] = []) {
export async function init(dir: string | undefined, options: InitOptions) {
log(`Configuring DeviceScript project`)

const files = { ...optionalFiles }
if (options.yarn) patchYarnFiles(files)

// write template files
const cwd = writeFiles(dir, options, optionalFiles)
const cwd = writeFiles(dir, options, files)

// patch .gitignore
const gids = ["node_modules", GENDIR, ".env.local", ".env.*.local"]
Expand Down Expand Up @@ -599,6 +602,21 @@ function sortPkgJson(pkg: any) {
return p2
}

function patchYarnCommands(content: string) {
return content
.replace("npm ci", "yarn install --frozen-lockfile")
.replace("npm install", "yarn install")
.replace("npm run build", "yarn build")
.replace("npm run watch", "yarn watch")
.replace("npm test", "yarn test")
}

function patchYarnFiles(files: FileSet) {
;[".github/workflows/build.yml", "README.md"].forEach(fn => {
files[fn] = patchYarnCommands(files[fn] as string)
})
}

export async function addNpm(options: AddNpmOptions) {
const files = clone(npmFiles)
let pkg = files["package.json"] as any
Expand Down Expand Up @@ -633,11 +651,7 @@ export async function addNpm(options: AddNpmOptions) {
}

if (isYarn(".", options)) {
const fn = ".github/workflows/build.yml"
files[fn] = (files[fn] as string)
.replace("npm ci", "yarn install --frozen-lockfile")
.replace("npm run build", "yarn build")
.replace("npm test", "yarn test")
patchYarnFiles(files)
}

const cwd = writeFiles(".", options, files)
Expand Down

0 comments on commit b0e34d6

Please sign in to comment.