@mikeyt23/node-cli-utils 1.2.5 → 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.
Files changed (2) hide show
  1. package/index.js +67 -3
  2. 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')
@@ -177,7 +176,7 @@ async function createTarball(directoryToTarball, outputDirectory, tarballName, c
177
176
  console.log('output will be: ' + tarballPath)
178
177
 
179
178
  let normalizedDirectoryToTarball = !!cwd ? path.join(cwd, directoryToTarball) : directoryToTarball
180
-
179
+
181
180
  if (!fs.existsSync(normalizedDirectoryToTarball)) {
182
181
  throw new Error('error: dirToTarball directory does not exist: ' + normalizedDirectoryToTarball)
183
182
  }
@@ -189,7 +188,7 @@ async function createTarball(directoryToTarball, outputDirectory, tarballName, c
189
188
  fs.unlinkSync(tarballPath)
190
189
  }
191
190
  }
192
-
191
+
193
192
  let options = { gzip: true, file: tarballPath }
194
193
  if (!!cwd) {
195
194
  options.cwd = cwd
@@ -238,6 +237,68 @@ async function dockerDepsStop(projectName, dockerRelativeDirectory) {
238
237
  return dockerCompose('stop', projectName, dockerRelativeDirectory)
239
238
  }
240
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
+
241
302
  exports.defaultSpawnOptions = defaultSpawnOptions
242
303
  exports.waitForProcess = waitForProcess
243
304
  exports.copyNewEnvValues = copyNewEnvValues
@@ -250,3 +311,6 @@ exports.dockerDepsUp = dockerDepsUp
250
311
  exports.dockerDepsUpDetached = dockerDepsUpDetached
251
312
  exports.dockerDepsDown = dockerDepsDown
252
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.5",
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
  }