Skip to content

Commit

Permalink
chore(sdk): add -d flag for create command, add version command for c…
Browse files Browse the repository at this point in the history
…li, bug fix (stephenh#120)
  • Loading branch information
zfy0701 committed Sep 27, 2022
1 parent 3c02442 commit 2b4de5b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 3 deletions.
1 change: 1 addition & 0 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@types/node": "^18.0.4",
"chai": "^4.3.6",
"clean-publish": "^4.0.1",
"conventional-changelog-conventionalcommits": "^5.0.0",
"jest": "^29.0.0",
"semantic-release": "^19.0.5",
"ts-jest": "^29.0.0",
Expand Down
11 changes: 10 additions & 1 deletion sdk/release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ module.exports = {
["@semantic-release/npm", {
// "pkgRoot": "dist"
}],
'@semantic-release/release-notes-generator',
['@semantic-release/release-notes-generator', {
preset: 'conventionalcommits',
presetConfig: {
types: [
{ type: 'feat', section: 'Features' },
{ type: 'fix', section: 'Bug Fixes' },
{ type: 'chore', section: 'Internal', hidden: false },
{ type: 'refactor', section: 'Internal', hidden: false },
]},
}],
[
'@semantic-release/github',
{
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import chalk from 'chalk'
import { buildProcessor } from './build'
import { runLogin } from './commands/run-login'
import { runCreate } from './commands/run-create'
import { runVersion } from './commands/run-version'

const mainDefinitions = [{ name: 'command', defaultOption: true }]
const mainOptions = commandLineArgs(mainDefinitions, {
Expand All @@ -27,6 +28,8 @@ if (mainOptions.command === 'login') {
runLogin(argv)
} else if (mainOptions.command === 'create') {
runCreate(argv)
} else if (mainOptions.command === 'version') {
runVersion(argv)
} else {
// For all the commands that need read project configs
// TODO move them to their own modules
Expand Down Expand Up @@ -161,6 +164,7 @@ function usage() {
'sentio upload\t\t\t\tbuild and upload processor to sentio',
'sentio gen\t\t\t\tgenerate abi',
'sentio build\t\t\t\tgenerate abi and build',
'sentio version\t\t\t\tcurrent cli version',
],
},
])
Expand Down
11 changes: 9 additions & 2 deletions sdk/src/cli/commands/run-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export function runCreate(argv: string[]) {
type: String,
description: 'Project name',
},
{
name: 'directory',
alias: 'd',
description: '(Optional) The root direct new project will be created, default current working dir',
type: String,
},
]

const options = commandLineArgs(optionDefinitions, { argv })
Expand All @@ -39,7 +45,8 @@ export function runCreate(argv: string[]) {
const templateFolder = path.resolve(__dirname, '../../../template')
const projectName = options.name || 'default'

const dstFolder = path.resolve(projectName)
const rootDir = options.directory || process.cwd()
const dstFolder = path.resolve(rootDir, projectName)
if (fs.existsSync(dstFolder)) {
console.error(chalk.red("can't create project '" + projectName + "', directory already existed"))
process.exit(1)
Expand Down Expand Up @@ -73,7 +80,7 @@ export function runCreate(argv: string[]) {
cliVersion = '^' + cliVersion
}

packageJson.version = cliVersion
packageJson.dependencies['@sentio/sdk'] = cliVersion
packageJson.name = projectName

// Don't add directly to avoid deps issue
Expand Down
32 changes: 32 additions & 0 deletions sdk/src/cli/commands/run-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import commandLineArgs from 'command-line-args'
import commandLineUsage from 'command-line-usage'
import { getCliVersion } from '../utils'

export function runVersion(argv: string[]) {
const optionDefinitions = [
{
name: 'help',
alias: 'h',
type: Boolean,
description: 'Display this usage guide.',
},
]
const options = commandLineArgs(optionDefinitions, { argv })

if (options.help) {
const usage = commandLineUsage([
{
header: 'Show current version',
content: 'sentio version',
},
{
header: 'Options',
optionList: optionDefinitions,
},
])
console.log(usage)
} else {
console.log('CLI Version: ', getCliVersion())
// TODO show SDK version for current package
}
}
9 changes: 9 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2861,6 +2861,15 @@ conventional-changelog-angular@^5.0.0:
compare-func "^2.0.0"
q "^1.5.1"

conventional-changelog-conventionalcommits@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-5.0.0.tgz#41bdce54eb65a848a4a3ffdca93e92fa22b64a86"
integrity sha512-lCDbA+ZqVFQGUj7h9QBKoIpLhl8iihkO0nCTyRNzuXtcd7ubODpYB04IFy31JloiJgG0Uovu8ot8oxRzn7Nwtw==
dependencies:
compare-func "^2.0.0"
lodash "^4.17.15"
q "^1.5.1"

conventional-changelog-writer@^5.0.0:
version "5.0.1"
resolved "https://registry.yarnpkg.com/conventional-changelog-writer/-/conventional-changelog-writer-5.0.1.tgz#e0757072f045fe03d91da6343c843029e702f359"
Expand Down

0 comments on commit 2b4de5b

Please sign in to comment.