Skip to content

Commit

Permalink
src: expand '~' in project root path
Browse files Browse the repository at this point in the history
  • Loading branch information
jhenstridge committed Jun 18, 2020
1 parent f75e0da commit 8298c61
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
12 changes: 11 additions & 1 deletion __tests__/build.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// -*- mode: javascript; js-indent-level: 2 -*-

import fs = require('fs')
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import * as process from 'process'
import * as exec from '@actions/exec'
import * as build from '../src/build'
Expand All @@ -10,6 +12,14 @@ afterEach(() => {
jest.restoreAllMocks()
})

test('SnapcraftBuilder expands tilde in project root', () => {
let builder = new build.SnapcraftBuilder('~', true)
expect(builder.projectRoot).toBe(os.homedir())

builder = new build.SnapcraftBuilder('~/foo/bar', true)
expect(builder.projectRoot).toBe(path.join(os.homedir(), 'foo/bar'))
})

test('SnapcraftBuilder.build runs a snap build', async () => {
expect.assertions(4)

Expand Down
4 changes: 2 additions & 2 deletions __tests__/tools.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// -*- mode: javascript; js-indent-level: 2 -*-

import * as exec from '@actions/exec'
import fs = require('fs')
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import * as exec from '@actions/exec'
import * as tools from '../src/tools'

afterEach(() => {
Expand Down
15 changes: 11 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,9 @@ var core = __webpack_require__(470);
// EXTERNAL MODULE: external "fs"
var external_fs_ = __webpack_require__(747);

// EXTERNAL MODULE: external "os"
var external_os_ = __webpack_require__(87);

// EXTERNAL MODULE: external "path"
var external_path_ = __webpack_require__(622);

Expand All @@ -1325,9 +1328,6 @@ var external_process_ = __webpack_require__(765);
// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js
var exec = __webpack_require__(986);

// EXTERNAL MODULE: external "os"
var external_os_ = __webpack_require__(87);

// CONCATENATED MODULE: ./lib/tools.js
// -*- mode: javascript; js-indent-level: 2 -*-
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
Expand Down Expand Up @@ -1423,9 +1423,16 @@ var build_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _ar




function expandHome(p) {
if (p === '~' || p.startsWith('~/')) {
p = Object(external_os_.homedir)() + p.slice(1);
}
return p;
}
class build_SnapcraftBuilder {
constructor(projectRoot, includeBuildInfo) {
this.projectRoot = projectRoot;
this.projectRoot = expandHome(projectRoot);
this.includeBuildInfo = includeBuildInfo;
}
build() {
Expand Down
10 changes: 9 additions & 1 deletion src/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// -*- mode: javascript; js-indent-level: 2 -*-

import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import * as process from 'process'
import * as core from '@actions/core'
Expand All @@ -14,12 +15,19 @@ interface ImageInfo {
build_url?: string
}

function expandHome(p: string): string {
if (p === '~' || p.startsWith('~/')) {
p = os.homedir() + p.slice(1)
}
return p
}

export class SnapcraftBuilder {
projectRoot: string
includeBuildInfo: boolean

constructor(projectRoot: string, includeBuildInfo: boolean) {
this.projectRoot = projectRoot
this.projectRoot = expandHome(projectRoot)
this.includeBuildInfo = includeBuildInfo
}

Expand Down

0 comments on commit 8298c61

Please sign in to comment.