-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathPluginRelease.js
More file actions
172 lines (157 loc) · 6 KB
/
Copy pathPluginRelease.js
File metadata and controls
172 lines (157 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* eslint-disable */
const { colors, helpers, print, strings, system, prompt, filesystem, path } = require('@codedungeon/gunner')
const Messenger = require('@codedungeon/messenger')
const appUtils = require('../utils/app')
const security = require('../utils/security.lib')
const pluginUtils = require('./support/plugin-utils')
const pluginRelease = require('./support/plugin-release')
const releasePrompts = require('./support/plugin-release/release-prompts')
const github = require('./support/github')
module.exports = {
name: 'plugin:release',
description: `Create Plugin Release ${colors.red('** Release Permissions Required **')}`,
disabled: false,
hidden: false,
usage: `plugin:release ${colors.magenta('<plugin>')} ${colors.blue('[options]')}`,
usePrompts: false,
arguments: {
plugin: {
type: 'string',
aliases: ['p'],
description: 'Plugin Name',
required: false,
prompt: {
type: 'input',
description: 'Plugin Name',
hint: 'e.g., codedungeon.Toolbox',
disabled: false,
},
},
},
flags: {
draft: {
aliases: ['d'],
type: 'boolean',
description: `Create Draft Github Release`,
},
force: {
aliases: ['f'],
type: 'boolean',
description: `Force Plugin Publish ${colors.gray('(will ignore all non required validations)')}`,
required: false,
},
noBuild: {
aliases: ['b'],
type: 'boolean',
description: `Skip Build Process ${colors.gray('(will use current build)')}`,
required: false,
},
noDelete: {
aliases: ['d'],
type: 'boolean',
description: `Skip Delete Process ${colors.gray('(do not delete existing releases for plugin)')}`,
required: false,
},
noTests: {
aliases: ['t'],
type: 'boolean',
description: `Skip Tests`,
required: false,
},
preview: {
aliases: ['p'],
type: 'boolean',
description: `Show tasks without actually executing them`,
},
},
async execute(toolbox) {
// make sure gh is installed, otherwise abort
if (!github.ghInstalled()) {
print.error('"plugin:release" requires github to be installed.', 'ERROR')
process.exit()
}
// const answers = await prompt.password('Enter Password')
// if (typeof answers !== 'object') {
// console.log('')
// print.warn('Release Aborted', 'ABORT')
// process.exit()
// }
// if (!security.validate(answers.password)) {
// console.log('')
// print.error('Invalid Password', 'ABORT')
// process.exit()
// }
if (toolbox.plugin.length === 0) {
// no plugin supplied, use `plugin.prompt` interface
this.arguments.plugin.prompt.disabled = false
this.arguments.plugin.prompt.type = 'select'
this.arguments.plugin.prompt.choices = pluginUtils.getPluginList()
const answers = await toolbox.prompts.run(toolbox, this)
toolbox.arguments.plugin = answers.commandName
}
console.log('')
const args = helpers.getArguments(toolbox.arguments, this, { initializeNullValues: true })
const pluginId = args.plugin || toolbox.arguments.plugin || toolbox.commandName || null
const result = filesystem.directoryList().filter((dirItem) => {
const filename = filesystem.filename(dirItem)
return filename.indexOf(pluginId) !== -1
})
const draft = args.draft || false
const preview = args.preview || false
const force = args.force || false
const noTests = args.noTests || false
const noDelete = args.noDelete || false
const noBuild = args.noBuild || false
if (result.length === 0) {
toolbox.print.error(`Unable to locate plugin ${pluginId}, make sure you are at the project root directory`, 'ERROR')
process.exit()
}
const configData = pluginUtils.getPluginConfig(pluginId)
const pluginVersion = configData['plugin.version']
const pluginName = configData['plugin.name']
let nextVersion = configData['plugin.version']
// if (configData['plugin.releaseStatus'] && configData['plugin.releaseStatus'] !== 'full') {
// nextVersion += `-${configData['plugin.releaseStatus']}`
// }
if (!(await pluginUtils.checkVersion(pluginId, nextVersion))) {
const existingReleaseName = `${pluginId} v${configData['plugin.version']}`
print.warn(`Release matching ${colors.cyan(existingReleaseName)} has already been published.`, 'HALT')
print.info(` https://github.com/NotePlan/plugins/releases/tag/${pluginId}-v${nextVersion}`)
console.log('')
const version = await releasePrompts.versionPrompt(configData['plugin.version'])
if (!version) {
print.warn('Release Cancelled', 'ABORT')
process.exit()
} else {
nextVersion = strings.raw(version)
if (version === 'Abort') {
print.warn('Release Cancelled', 'ABORT')
process.exit()
}
}
}
if (!args.force && !(await pluginUtils.checkChangelogNotes(pluginId, nextVersion))) {
print.warn(`Your ${colors.cyan('CHANGELOG.md')} does not contain information for v${nextVersion}`, 'WARN')
console.log('')
const changelogPrompt = await prompt.toggle('Would you like to continue without updating CHANGELOG.md?')
if (!changelogPrompt || !changelogPrompt.answer) {
console.log('')
print.warn('Release Cancelled', 'ABORT')
process.exit()
}
}
// Check if this is a pre-release and ask for confirmation
const releaseStatus = configData['plugin.releaseStatus']
if (releaseStatus !== undefined && releaseStatus !== '' && releaseStatus !== 'full') {
console.log('')
const preReleasePrompt = await prompt.toggle(`${pluginName} version ${nextVersion} is marked "${releaseStatus}", continue with pre-release?`)
if (!preReleasePrompt || !preReleasePrompt.answer) {
console.log('')
print.warn('Release Cancelled', 'ABORT')
process.exit()
}
console.log('')
}
const runner = pluginRelease.run(pluginId, pluginName, nextVersion, args)
},
}