|
| 1 | +/// <reference path="../node_modules/zarro/types.d.ts" /> |
| 2 | +(function () { |
| 3 | + const path = require("path"), |
| 4 | + gulp = requireModule<Gulp>("gulp"), |
| 5 | + { |
| 6 | + lsSync, |
| 7 | + FsEntities |
| 8 | + } = require("yafs"), |
| 9 | + throwIfNoFiles = requireModule<ThrowIfNoFiles>("throw-if-no-files"), |
| 10 | + opts = { |
| 11 | + parserOptions: {}, |
| 12 | + builderOptions: { |
| 13 | + headless: true, |
| 14 | + renderOpts: { |
| 15 | + pretty: true |
| 16 | + } |
| 17 | + } |
| 18 | + }, |
| 19 | + editXml = require("gulp-edit-xml"); |
| 20 | + |
| 21 | + gulp.task( |
| 22 | + "update-tempdb-runner-files", |
| 23 | + "Updates the files section of PeanutButter.TempDb.Runner/Package.nuspec to include all Release binaries", |
| 24 | + () => { |
| 25 | + const project = "source/TempDb/PeanutButter.TempDb.Runner", |
| 26 | + nuspec = `${ project }/Package.nuspec`; |
| 27 | + return gulp |
| 28 | + .src(nuspec) |
| 29 | + .pipe(throwIfNoFiles(`Nuspec not found at: ${ nuspec }`)) |
| 30 | + .pipe( |
| 31 | + editXml(xml => { |
| 32 | + const releaseFolder = `${ project }/bin/Release`, |
| 33 | + projectFullPath = path.resolve(project), |
| 34 | + files = lsSync( |
| 35 | + releaseFolder, |
| 36 | + { |
| 37 | + recurse: true, |
| 38 | + entities: FsEntities.files, |
| 39 | + fullPaths: true |
| 40 | + } |
| 41 | + ) |
| 42 | + .map(p => p.replace(projectFullPath, "")) |
| 43 | + .map(p => p.replace(/^\\/, "")); |
| 44 | + if (files.filter(p => p.match(/\.dll$/)).length === 0) { |
| 45 | + throw new Error(`No assemblies found under ${ releaseFolder }`); |
| 46 | + } |
| 47 | + |
| 48 | + xml.package.files = [ { file: [] } ]; |
| 49 | + const fileNode = xml.package.files[0].file; |
| 50 | + fileNode.push({ |
| 51 | + $: { |
| 52 | + src: "icon.png", |
| 53 | + target: "" |
| 54 | + } |
| 55 | + }) |
| 56 | + files |
| 57 | + .filter(filterTempDbRunnerFile) |
| 58 | + .forEach(relPath => { |
| 59 | + fileNode.push({ |
| 60 | + $: { |
| 61 | + src: relPath, |
| 62 | + target: targetFor(relPath) |
| 63 | + } |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + return xml; |
| 68 | + }, opts) |
| 69 | + ) |
| 70 | + .pipe(gulp.dest(project)); |
| 71 | + } |
| 72 | + ); |
| 73 | + |
| 74 | + function filterTempDbRunnerFile(filepath) { |
| 75 | + if ((filepath || "").match(/netcoreapp.*\\PeanutButter.TempDb.Runner.exe$/)) { |
| 76 | + console.log(`-- ignoring: ${ filepath }`); |
| 77 | + return false; |
| 78 | + } |
| 79 | + return true; |
| 80 | + } |
| 81 | + |
| 82 | + function targetFor(relPath) { |
| 83 | + let next = false; |
| 84 | + const parts = relPath.split(path.sep), |
| 85 | + targetFramework = parts.reduce((acc, cur) => { |
| 86 | + if (cur === "Release") { |
| 87 | + next = true; |
| 88 | + return acc; |
| 89 | + } |
| 90 | + if (next) { |
| 91 | + next = false; |
| 92 | + return cur; |
| 93 | + } else { |
| 94 | + return acc; |
| 95 | + } |
| 96 | + }, null); |
| 97 | + if (!targetFramework) { |
| 98 | + console.log({ |
| 99 | + parts |
| 100 | + }); |
| 101 | + throw new Error( |
| 102 | + `Can't determine target framework for path: ${ relPath } (should be after 'Release')` |
| 103 | + ); |
| 104 | + } |
| 105 | + const |
| 106 | + pathParts = relPath.split(/[\/|\\]/), |
| 107 | + start = pathParts.indexOf("Release") + 2, |
| 108 | + subPath = pathParts.slice(start).join("/"), |
| 109 | + subFolder = path.dirname(subPath); |
| 110 | + return subFolder === "." |
| 111 | + ? `lib/${ targetFramework }` |
| 112 | + : `lib/${ targetFramework }/${ subFolder }`; |
| 113 | + } |
| 114 | +})(); |
0 commit comments