@mikeyt23/node-cli-utils 1.2.3 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +76 -7
- package/package.json +1 -2
package/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
|
-
const fse = require('fs-extra')
|
|
3
2
|
const fsp = require('fs').promises
|
|
4
3
|
const which = require('which')
|
|
5
4
|
const { spawn, spawnSync } = require('child_process')
|
|
@@ -160,7 +159,7 @@ exports.defaultSpawnOptions = {
|
|
|
160
159
|
stdio: ['ignore', 'inherit', 'inherit']
|
|
161
160
|
}
|
|
162
161
|
|
|
163
|
-
async function createTarball(directoryToTarball, outputDirectory, tarballName,
|
|
162
|
+
async function createTarball(directoryToTarball, outputDirectory, tarballName, cwd = '') {
|
|
164
163
|
if (!directoryToTarball || directoryToTarball.length === 0) {
|
|
165
164
|
throw new Error('directoryToTarball is required')
|
|
166
165
|
}
|
|
@@ -176,8 +175,10 @@ async function createTarball(directoryToTarball, outputDirectory, tarballName, s
|
|
|
176
175
|
console.log('directory to create tarball from: ' + directoryToTarball)
|
|
177
176
|
console.log('output will be: ' + tarballPath)
|
|
178
177
|
|
|
179
|
-
|
|
180
|
-
|
|
178
|
+
let normalizedDirectoryToTarball = !!cwd ? path.join(cwd, directoryToTarball) : directoryToTarball
|
|
179
|
+
|
|
180
|
+
if (!fs.existsSync(normalizedDirectoryToTarball)) {
|
|
181
|
+
throw new Error('error: dirToTarball directory does not exist: ' + normalizedDirectoryToTarball)
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
if (!fs.existsSync(outputDirectory)) {
|
|
@@ -187,9 +188,12 @@ async function createTarball(directoryToTarball, outputDirectory, tarballName, s
|
|
|
187
188
|
fs.unlinkSync(tarballPath)
|
|
188
189
|
}
|
|
189
190
|
}
|
|
190
|
-
|
|
191
|
-
let options = { gzip: true, file: tarballPath
|
|
192
|
-
|
|
191
|
+
|
|
192
|
+
let options = { gzip: true, file: tarballPath }
|
|
193
|
+
if (!!cwd) {
|
|
194
|
+
options.cwd = cwd
|
|
195
|
+
}
|
|
196
|
+
|
|
193
197
|
await tar.c(options, [directoryToTarball])
|
|
194
198
|
}
|
|
195
199
|
|
|
@@ -233,6 +237,68 @@ async function dockerDepsStop(projectName, dockerRelativeDirectory) {
|
|
|
233
237
|
return dockerCompose('stop', projectName, dockerRelativeDirectory)
|
|
234
238
|
}
|
|
235
239
|
|
|
240
|
+
async function dotnetBuild(release = true) {
|
|
241
|
+
let args = ['build']
|
|
242
|
+
if (release) {
|
|
243
|
+
args.push('-c', 'Release')
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return waitForProcess(spawn('dotnet', args, defaultSpawnOptions))
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async function dotnetPack(projectDirectoryPath, release = true) {
|
|
250
|
+
if (!projectDirectoryPath) {
|
|
251
|
+
throw Error('projectDirectoryPath param is required')
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
let args = ['pack']
|
|
255
|
+
if (release === true) {
|
|
256
|
+
args.push('-c', 'Release')
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const spawnOptions = { ...defaultSpawnOptions, cwd: projectDirectoryPath }
|
|
260
|
+
logCommand('dotnet', args, spawnOptions)
|
|
261
|
+
await waitForProcess(spawn('dotnet', args, spawnOptions))
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
async function dotnetNugetPublish(projectDirectoryPath, csprojFilename, release = true, nugetSource = 'https://api.nuget.org/v3/index.json') {
|
|
265
|
+
const apiKey = process.env.NUGET_API_KEY
|
|
266
|
+
if (!apiKey) {
|
|
267
|
+
throw Error('env var NUGET_API_KEY is required')
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const packageDir = path.join(projectDirectoryPath, release ? 'bin/Release' : 'bin/Debug')
|
|
271
|
+
|
|
272
|
+
const packageName = await getPackageName(projectDirectoryPath, csprojFilename)
|
|
273
|
+
console.log('publishing package ' + packageName)
|
|
274
|
+
const spawnOptions = { ...defaultSpawnOptions, cwd: packageDir }
|
|
275
|
+
await waitForProcess(spawn('dotnet', [
|
|
276
|
+
'nuget',
|
|
277
|
+
'push',
|
|
278
|
+
packageName,
|
|
279
|
+
'--api-key',
|
|
280
|
+
apiKey,
|
|
281
|
+
'--source',
|
|
282
|
+
nugetSource], spawnOptions))
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async function getPackageName(projectPath, csprojFilename) {
|
|
286
|
+
const namespace = csprojFilename.substring(0, csprojFilename.indexOf('.csproj'))
|
|
287
|
+
const csprojPath = path.join(projectPath, csprojFilename)
|
|
288
|
+
const csproj = fs.readFileSync(csprojPath, 'utf-8')
|
|
289
|
+
const versionTag = '<PackageVersion>'
|
|
290
|
+
const xmlVersionTagIndex = csproj.indexOf(versionTag)
|
|
291
|
+
const versionStartIndex = xmlVersionTagIndex + versionTag.length
|
|
292
|
+
const versionStopIndex = csproj.indexOf('<', versionStartIndex)
|
|
293
|
+
const version = csproj.substring(versionStartIndex, versionStopIndex)
|
|
294
|
+
return `${namespace}.${version}.nupkg`
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async function logCommand(command, args, spawnOptions) {
|
|
298
|
+
console.log('running command: ' + `${command} ${args.join(' ')}`)
|
|
299
|
+
console.log('with spawn options: ' + JSON.stringify(spawnOptions))
|
|
300
|
+
}
|
|
301
|
+
|
|
236
302
|
exports.defaultSpawnOptions = defaultSpawnOptions
|
|
237
303
|
exports.waitForProcess = waitForProcess
|
|
238
304
|
exports.copyNewEnvValues = copyNewEnvValues
|
|
@@ -245,3 +311,6 @@ exports.dockerDepsUp = dockerDepsUp
|
|
|
245
311
|
exports.dockerDepsUpDetached = dockerDepsUpDetached
|
|
246
312
|
exports.dockerDepsDown = dockerDepsDown
|
|
247
313
|
exports.dockerDepsStop = dockerDepsStop
|
|
314
|
+
exports.dotnetBuild = dotnetBuild
|
|
315
|
+
exports.dotnetPack = dotnetPack
|
|
316
|
+
exports.dotnetNugetPublish = dotnetNugetPublish
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikeyt23/node-cli-utils",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "Some node cli utility functions",
|
|
5
5
|
"author": "Mike Thompson",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
},
|
|
16
16
|
"main": "index.js",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"fs-extra": "^10.0.0",
|
|
19
18
|
"tar": "^6.1.11",
|
|
20
19
|
"which": "^2.0.2"
|
|
21
20
|
}
|