Skip to content

Commit

Permalink
Fix windows issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Dec 4, 2023
1 parent 2160545 commit 8673e63
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
30 changes: 15 additions & 15 deletions src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as glob from 'glob';
import type { BeforeZipCallbackInfo } from './RokuDeploy';
import { RokuDeploy } from './RokuDeploy';
import * as errors from './Errors';
import { util, standardizePath as s } from './util';
import { util, standardizePath as s, standardizePathPosix as sp } from './util';
import type { FileEntry, RokuDeployOptions } from './RokuDeployOptions';
import { cwd, expectPathExists, expectPathNotExists, expectThrowsAsync, outDir, rootDir, stagingDir, tempDir, writeFiles } from './testUtils.spec';
import { createSandbox } from 'sinon';
Expand Down Expand Up @@ -1722,7 +1722,7 @@ describe('index', () => {
await rokuDeploy.prepublishToStaging({
files: [
{
src: `${rootDir}/manifest`,
src: sp`${rootDir}/manifest`,
dest: ''
},
{
Expand Down Expand Up @@ -2093,7 +2093,7 @@ describe('index', () => {
src: `long/source/path`,
dest: `long/dest/path`
}])).to.eql([{
src: s`long/source/path`,
src: sp`long/source/path`,
dest: s`long/dest/path`
}]);
});
Expand Down Expand Up @@ -2151,7 +2151,7 @@ describe('index', () => {
src: 'manifest',
dest: undefined
}, {
src: s`source/main.brs`,
src: sp`source/main.brs`,
dest: undefined
}]);
});
Expand All @@ -2163,7 +2163,7 @@ describe('index', () => {
dest: 'source/config.brs'
}
])).to.eql([{
src: s`source/config.dev.brs`,
src: sp`source/config.dev.brs`,
dest: s`source/config.brs`
}]);
});
Expand Down Expand Up @@ -2651,7 +2651,7 @@ describe('index', () => {

describe('getFilePaths', () => {
const otherProjectName = 'otherProject';
const otherProjectDir = s`${rootDir}/../${otherProjectName}`;
const otherProjectDir = sp`${rootDir}/../${otherProjectName}`;
//create baseline project structure
beforeEach(() => {
fsExtra.ensureDirSync(`${rootDir}/components/emptyFolder`);
Expand Down Expand Up @@ -3139,15 +3139,15 @@ describe('index', () => {

//dest not specified
expect(await rokuDeploy.getFilePaths([{
src: s`${cwd}/README.md`
src: sp`${cwd}/README.md`
}], options.rootDir)).to.eql([{
src: s`${cwd}/README.md`,
dest: s`README.md`
}]);

//dest specified
expect(await rokuDeploy.getFilePaths([{
src: path.join(cwd, 'README.md'),
src: sp`${cwd}/README.md`,
dest: 'docs/README.md'
}], options.rootDir)).to.eql([{
src: s`${cwd}/README.md`,
Expand All @@ -3157,7 +3157,7 @@ describe('index', () => {
let paths: any[];

paths = await rokuDeploy.getFilePaths([{
src: s`${cwd}/README.md`,
src: sp`${cwd}/README.md`,
dest: s`docs/README.md`
}], outDir);

Expand All @@ -3169,7 +3169,7 @@ describe('index', () => {
//top-level string paths pointing to files outside the root should thrown an exception
await expectThrowsAsync(async () => {
paths = await rokuDeploy.getFilePaths([
s`${cwd}/README.md`
sp`${cwd}/README.md`
], outDir);
});
});
Expand All @@ -3180,7 +3180,7 @@ describe('index', () => {
]);
expect(
await rokuDeploy.getFilePaths([{
src: path.join('..', 'README.md')
src: sp`../README.md`
}], rootDir)
).to.eql([{
src: s`${rootDir}/../README.md`,
Expand All @@ -3189,7 +3189,7 @@ describe('index', () => {

expect(
await rokuDeploy.getFilePaths([{
src: path.join('..', 'README.md'),
src: sp`../README.md`,
dest: 'docs/README.md'
}], rootDir)
).to.eql([{
Expand All @@ -3204,17 +3204,17 @@ describe('index', () => {
]);
await expectThrowsAsync(
rokuDeploy.getFilePaths([
path.join('..', 'README.md')
path.posix.join('..', 'README.md')
], outDir)
);
});

it('supports overriding paths', async () => {
let paths = await rokuDeploy.getFilePaths([{
src: s`${rootDir}/components/component1.brs`,
src: sp`${rootDir}/components/component1.brs`,
dest: 'comp1.brs'
}, {
src: s`${rootDir}/components/screen1/screen1.brs`,
src: sp`${rootDir}/components/screen1/screen1.brs`,
dest: 'comp1.brs'
}], rootDir);
expect(paths).to.be.lengthOf(1);
Expand Down
4 changes: 2 additions & 2 deletions src/RokuDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class RokuDeploy {
//objects with src: string
if (typeof entry.src === 'string') {
result.push({
src: util.standardizePath(entry.src),
src: entry.src,
dest: util.standardizePath(entry.dest)
});

Expand All @@ -86,7 +86,7 @@ export class RokuDeploy {
//create a distinct entry for each item in the src array
for (let srcEntry of entry.src) {
result.push({
src: util.standardizePath(srcEntry),
src: srcEntry,
dest: util.standardizePath(entry.dest)
});
}
Expand Down
29 changes: 26 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,21 @@ export class Util {
if (!thePath) {
return thePath;
}
return path.normalize(
thePath.replace(/[\/\\]+/g, path.sep)
);
return path.normalize(thePath).replace(/[\/\\]+/g, path.sep);
}

/**
* Normalize path and replace all directory separators with current OS separators
* @param thePath
*/
public standardizePathPosix(thePath: string) {
if (!thePath) {
return thePath;
}
return path.normalize(thePath).replace(/[\/\\]+/g, '/');
}


/**
* Do a case-insensitive string replacement
* @param subject the string that will have its contents replaced
Expand Down Expand Up @@ -232,3 +242,16 @@ export function standardizePath(stringParts, ...expressions: any[]) {
result.join('')
);
}

/**
* A tagged template literal function for standardizing the path and making all path separators forward slashes
*/
export function standardizePathPosix(stringParts, ...expressions: any[]) {
let result = [];
for (let i = 0; i < stringParts.length; i++) {
result.push(stringParts[i], expressions[i]);
}
return util.standardizePathPosix(
result.join('')
);
}

0 comments on commit 8673e63

Please sign in to comment.