Skip to content

Commit

Permalink
Merge branch 'main' into fix-tarballs-cmd-not-consider-pkgjson
Browse files Browse the repository at this point in the history
  • Loading branch information
rannn505 committed Jan 25, 2022
2 parents 55471a3 + 6a5d9f8 commit 71c3690
Show file tree
Hide file tree
Showing 10 changed files with 1,420 additions and 1,687 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.3.0](https://github.com/oclif/oclif/compare/v2.2.0...v2.3.0) (2022-01-20)


### Features

* use yeoman-generator v5 ([#797](https://github.com/oclif/oclif/issues/797)) ([37827bf](https://github.com/oclif/oclif/commit/37827bf258ff8145c98a9c621b853ac6b1020fdb))

## [2.2.0](https://github.com/oclif/oclif/compare/v2.1.8...v2.2.0) (2022-01-13)


Expand Down
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -146,7 +146,7 @@ DESCRIPTION
This will clone the template repo 'oclif/hello-world' and update package properties
```

_See code: [src/commands/generate.ts](https://github.com/oclif/oclif/blob/v2.1.8/src/commands/generate.ts)_
_See code: [src/commands/generate.ts](https://github.com/oclif/oclif/blob/v2.2.0/src/commands/generate.ts)_

## `oclif generate command NAME`

Expand Down Expand Up @@ -220,7 +220,7 @@ DESCRIPTION
generates plugin manifest json
```

_See code: [src/commands/manifest.ts](https://github.com/oclif/oclif/blob/v2.1.8/src/commands/manifest.ts)_
_See code: [src/commands/manifest.ts](https://github.com/oclif/oclif/blob/v2.2.0/src/commands/manifest.ts)_

## `oclif pack deb`

Expand Down Expand Up @@ -321,7 +321,7 @@ DESCRIPTION
promote CLI builds to a S3 release channel
```

_See code: [src/commands/promote.ts](https://github.com/oclif/oclif/blob/v2.1.8/src/commands/promote.ts)_
_See code: [src/commands/promote.ts](https://github.com/oclif/oclif/blob/v2.2.0/src/commands/promote.ts)_

## `oclif readme`

Expand Down Expand Up @@ -351,7 +351,7 @@ DESCRIPTION
Customize the code URL prefix by setting oclif.repositoryPrefix in package.json.
```

_See code: [src/commands/readme.ts](https://github.com/oclif/oclif/blob/v2.1.8/src/commands/readme.ts)_
_See code: [src/commands/readme.ts](https://github.com/oclif/oclif/blob/v2.2.0/src/commands/readme.ts)_

## `oclif upload deb`

Expand Down
2 changes: 0 additions & 2 deletions bin/run
Expand Up @@ -2,6 +2,4 @@

const oclif = require('@oclif/core')

oclif.settings.disableJsonFlag = true

oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'))
12 changes: 6 additions & 6 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "oclif",
"description": "oclif: create your own CLI",
"version": "2.2.0",
"version": "2.3.0",
"author": "Salesforce",
"bin": {
"oclif": "bin/run"
Expand All @@ -24,8 +24,8 @@
"qqjs": "^0.3.10",
"semver": "^7.3.5",
"tslib": "^2.3.1",
"yeoman-environment": "^2.3.4",
"yeoman-generator": "3",
"yeoman-environment": "^3.5.1",
"yeoman-generator": "^5.5.2",
"yosay": "^2.0.2"
},
"devDependencies": {
Expand All @@ -40,11 +40,11 @@
"@types/node": "^14.18.4",
"@types/read-pkg": "^5.1.0",
"@types/semver": "^7.3.9",
"@types/shelljs": "^0.8.10",
"@types/shelljs": "^0.8.11",
"@types/supports-color": "^7.2.0",
"@types/write-json-file": "^3.2.1",
"@types/yeoman-environment": "^2.10.5",
"@types/yosay": "^0.0.29",
"@types/yeoman-generator": "^5.2.8",
"@types/yosay": "^2.0.1",
"aws-sdk": "^2.1048.0",
"chai": "^4.2.0",
"conventional-changelog-cli": "^2.2.2",
Expand Down
12 changes: 4 additions & 8 deletions src/command-base.ts
Expand Up @@ -2,19 +2,15 @@ import {Command} from '@oclif/core'
import {createEnv} from 'yeoman-environment'

export default abstract class CommandBase extends Command {
protected async generate(type: string, generatorOptions: Record<string, unknown> = {}): Promise<void> {
protected generate(type: string, generatorOptions: Record<string, unknown> = {}): void {
const env = createEnv()

env.register(
require.resolve(`./generators/${type}`),
`oclif:${type}`,
)

await new Promise((resolve, reject) => {
env.run(`oclif:${type}`, generatorOptions, ((err: Error, results: any) => {
if (err) reject(err)
else resolve(results)
}) as (err: Error | null) => void)
})
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
env.run(`oclif:${type}`, generatorOptions)
}
}
2 changes: 1 addition & 1 deletion src/commands/generate.ts
Expand Up @@ -13,7 +13,7 @@ This will clone the template repo 'oclif/hello-world' and update package propert
async run(): Promise<void> {
const {args} = await this.parse(Generate)

await super.generate('cli', {
super.generate('cli', {
name: args.name,
force: true,
})
Expand Down
2 changes: 1 addition & 1 deletion src/commands/generate/command.ts
Expand Up @@ -15,7 +15,7 @@ export default class GenerateCommand extends CommandBase {
async run(): Promise<void> {
const {args, flags} = await this.parse(GenerateCommand)

await super.generate('command', {
super.generate('command', {
name: args.name,
force: flags.force,
})
Expand Down
2 changes: 1 addition & 1 deletion src/commands/generate/hook.ts
Expand Up @@ -16,7 +16,7 @@ export default class GenerateHook extends CommandBase {
async run(): Promise<void> {
const {args, flags} = await this.parse(GenerateHook)

await super.generate('hook', {
super.generate('hook', {
name: args.name,
event: flags.event,
force: flags.force,
Expand Down
33 changes: 10 additions & 23 deletions src/generators/cli.ts
Expand Up @@ -8,8 +8,6 @@ import yosay = require('yosay')
const debug = require('debug')('generator-oclif')
const {version} = require('../../package.json')

const isWindows = process.platform === 'win32'

let hasYarn = false
try {
execSync('yarn -v', {stdio: 'ignore'})
Expand All @@ -19,14 +17,13 @@ try {
export default class CLI extends Generator {
options: {
defaults?: boolean;
force: boolean;
yarn: boolean;
}

args!: {[k: string]: string}

name: string

pjson: any
pjson!: any

githubUser: string | undefined

Expand Down Expand Up @@ -60,6 +57,7 @@ export default class CLI extends Generator {
this.name = opts.name
this.options = {
defaults: opts.defaults,
force: opts.force,
yarn: hasYarn,
}
}
Expand All @@ -73,7 +71,7 @@ export default class CLI extends Generator {
fs.rmSync(`${path.resolve(this.name, '.git')}`, {recursive: true})

this.destinationRoot(path.resolve(this.name))
process.chdir(this.destinationRoot())
this.env.cwd = this.destinationPath()

this.githubUser = await this.user.github.username().catch(debug)
// establish order of properties in the resulting package.json
Expand All @@ -93,7 +91,7 @@ export default class CLI extends Generator {
oclif: {},
scripts: {},
engines: {},
...(this.fs.readJSON('package.json', {}) as Record<string, unknown>),
...(this.fs.readJSON(path.join(this.env.cwd, 'package.json'), {}) as Record<string, unknown>),
}
let repository = this.destinationRoot().split(path.sep).slice(-2).join('/')
if (this.githubUser) repository = `${this.githubUser}/${repository.split('/')[1]}`
Expand Down Expand Up @@ -187,10 +185,12 @@ export default class CLI extends Generator {
this.options = {
...this.answers.ci,
yarn: this.answers.pkg === 'yarn',
force: true,
}
}

this.yarn = this.options.yarn
this.env.options.nodePackageManager = this.yarn ? 'yarn' : 'npm'

this.pjson.name = this.answers.name || defaults.name
this.pjson.description = this.answers.description || defaults.description
Expand All @@ -206,6 +206,7 @@ export default class CLI extends Generator {
this.pjson.bugs = `https://github.com/${this.repository}/issues`

this.pjson.oclif.bin = this.answers.bin
this.pjson.oclif.dirname = this.answers.bin
this.pjson.bin = {}
this.pjson.bin[this.pjson.oclif.bin] = './bin/run'
}
Expand All @@ -222,23 +223,9 @@ export default class CLI extends Generator {
this.fs.write(this.destinationPath('.gitignore'), this._gitignore())
}

async install(): Promise<void> {
const dependencies: string[] = []
const devDependencies: string[] = []
if (isWindows) devDependencies.push('rimraf')
const yarnOpts = {} as any
if (process.env.YARN_MUTEX) yarnOpts.mutex = process.env.YARN_MUTEX
const install = (deps: string[], opts: Record<string, unknown>) => this.yarn ? this.yarnInstall(deps, opts) : this.npmInstall(deps, opts)
const dev = this.yarn ? {dev: true} : {'save-dev': true}
const save = this.yarn ? {} : {save: true}
return Promise.all([
install(devDependencies, {...yarnOpts, ...dev, ignoreScripts: true}),
install(dependencies, {...yarnOpts, ...save}),
]).then(() => {})
}

end(): void {
this.spawnCommandSync(path.join('.', 'node_modules/.bin/oclif'), ['readme'])
this.spawnCommandSync(this.env.options.nodePackageManager, ['run', 'build'])
this.spawnCommandSync(path.join(this.env.cwd, 'node_modules', '.bin', 'oclif'), ['readme'], {cwd: this.env.cwd})
console.log(`\nCreated ${this.pjson.name} in ${this.destinationRoot()}`)
}

Expand Down

0 comments on commit 71c3690

Please sign in to comment.