Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ If you'd like to use roku-deploy to copy files to a staging folder, you can do t
```typescript
rokuDeploy.prepublishToStaging({
rootDir: "folder/with/your/source/code",
stagingFolderPath: 'path/to/staging/folder',
stagingDir: 'path/to/staging/folder',
files: [
"source/**/*",
"components/**/*",
Expand All @@ -93,7 +93,7 @@ Use this logic if you'd like to create a zip from your application folder.
/create a signed package of your project
rokuDeploy.zipPackage({
outDir: 'folder/to/put/zip',
stagingFolderPath: 'path/to/files/to/zip',
stagingDir: 'path/to/files/to/zip',
outFile: 'filename-of-your-app.zip'
//...other options if necessary
}).then(function(){
Expand Down Expand Up @@ -135,7 +135,7 @@ From an npm script in `package.json`. (Requires `rokudeploy.json` to exist at th
You can provide a callback in any of the higher level methods, which allows you to modify the copied contents before the package is zipped. An info object is passed in with the following attributes
- **manifestData:** [key: string]: string
Contains all the parsed values from the manifest file
- **stagingFolderPath:** string
- **stagingDir:** string
Path to staging folder to make it so you only need to know the relative path to what you're trying to modify

```javascript
Expand All @@ -148,7 +148,7 @@ You can provide a callback in any of the higher level methods, which allows you
rokuDeploy.deploy(options, (info) => {
//modify staging dir before it's zipped.
//At this point, all files have been copied to the staging directory.
manipulateFilesInStagingFolder(info.stagingFolderPath)
manipulateFilesInStagingFolder(info.stagingDir)
//this function can also return a promise,
//which will be awaited before roku-deploy starts deploying.
}).then(function(){
Expand Down Expand Up @@ -361,7 +361,7 @@ Here are the available options. The defaults are shown to the right of the optio
- **retainStagingFolder?:** boolean = `false`
Set this to true to prevent the staging folder from being deleted after creating the package. This is helpful for troubleshooting why your package isn't being created the way you expected.

- **stagingFolderPath?:** string = `` `${options.outDir}/.roku-deploy-staging` ``
- **stagingDir?:** string = `` `${options.outDir}/.roku-deploy-staging` ``
The path to the staging folder (where roku-deploy places all of the files right before zipping them up).

- **convertToSquashfs?:** boolean = `false`
Expand Down
86 changes: 58 additions & 28 deletions src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('index', () => {
rootDir: rootDir,
outDir: outDir,
devId: 'abcde',
stagingFolderPath: stagingDir,
stagingDir: stagingDir,
signingPassword: '12345',
host: 'localhost',
rekeySignedPackage: `../../testSignedPackage.pkg`
Expand Down Expand Up @@ -388,8 +388,8 @@ describe('index', () => {
it('should throw error when manifest is missing', async () => {
let err;
try {
options.stagingFolderPath = s`${tempDir}/path/to/nowhere`;
fsExtra.ensureDirSync(options.stagingFolderPath);
options.stagingDir = s`${tempDir}/path/to/nowhere`;
fsExtra.ensureDirSync(options.stagingDir);
await rokuDeploy.zipPackage(options);
} catch (e) {
err = (e as Error);
Expand All @@ -400,7 +400,7 @@ describe('index', () => {
it('should throw error when manifest is missing and stagingDir does not exist', async () => {
let err;
try {
options.stagingFolderPath = s`${tempDir}/path/to/nowhere`;
options.stagingDir = s`${tempDir}/path/to/nowhere`;
await rokuDeploy.zipPackage(options);
} catch (e) {
err = (e as Error);
Expand All @@ -412,13 +412,13 @@ describe('index', () => {
});

describe('createPackage', () => {
it('works with custom stagingFolderPath', async () => {
it('works with custom stagingDir', async () => {
let opts = {
...options,
files: [
'manifest'
],
stagingFolderPath: '.tmp/dist'
stagingDir: '.tmp/dist'
};
await rokuDeploy.createPackage(opts);
expectPathExists(rokuDeploy.getOutputZipFilePath(opts));
Expand Down Expand Up @@ -481,23 +481,23 @@ describe('index', () => {
});

it('should retain the staging directory when told to', async () => {
let stagingFolderPath = await rokuDeploy.prepublishToStaging({
let stagingDirValue = await rokuDeploy.prepublishToStaging({
...options,
files: [
'manifest'
]
});
expectPathExists(stagingFolderPath);
options.retainStagingFolder = true;
expectPathExists(stagingDirValue);
options.retainStagingDir = true;
await rokuDeploy.zipPackage(options);
expectPathExists(stagingFolderPath);
expectPathExists(stagingDirValue);
});

it('should call our callback with correct information', async () => {
fsExtra.outputFileSync(`${rootDir}/manifest`, 'major_version=1');

let spy = sinon.spy((info: BeforeZipCallbackInfo) => {
expectPathExists(info.stagingFolderPath);
expectPathExists(info.stagingDir);
expect(info.manifestData.major_version).to.equal('1');
});

Expand Down Expand Up @@ -1111,7 +1111,7 @@ describe('index', () => {
await rokuDeploy.prepublishToStaging({
...options,
files: ['manifest'],
stagingFolderPath: `${tempDir}/custom-out-dir`
stagingDir: `${tempDir}/custom-out-dir`
});
expectPathExists(`${tempDir}/custom-out-dir`);
});
Expand Down Expand Up @@ -1369,15 +1369,15 @@ describe('index', () => {
]
};

let stagingFolderPath = rokuDeploy.getOptions(opts).stagingFolderPath;
let stagingDirValue = rokuDeploy.getOptions(opts).stagingDir;
//getFilePaths detects the file
expect(await rokuDeploy.getFilePaths(['renamed_test.md'], opts.rootDir)).to.eql([{
src: s`${opts.rootDir}/renamed_test.md`,
dest: s`renamed_test.md`
}]);

await rokuDeploy.prepublishToStaging(opts);
let stagedFilePath = s`${stagingFolderPath}/renamed_test.md`;
let stagedFilePath = s`${stagingDirValue}/renamed_test.md`;
expectPathExists(stagedFilePath);
let fileContents = await fsExtra.readFile(stagedFilePath);
expect(fileContents.toString()).to.equal('hello symlink');
Expand Down Expand Up @@ -1406,7 +1406,7 @@ describe('index', () => {
]
};

let stagingPath = rokuDeploy.getOptions(opts).stagingFolderPath;
let stagingPath = rokuDeploy.getOptions(opts).stagingDir;
//getFilePaths detects the file
expect(
(await rokuDeploy.getFilePaths(opts.files, opts.rootDir)).sort((a, b) => a.src.localeCompare(b.src))
Expand Down Expand Up @@ -2865,7 +2865,7 @@ describe('index', () => {
await expectThrowsAsync(
rokuDeploy.prepublishToStaging({
rootDir: rootDir,
stagingFolderPath: stagingDir,
stagingDir: stagingDir,
files: [
'source/main.brs'
]
Expand Down Expand Up @@ -2894,43 +2894,73 @@ describe('index', () => {
});

describe('getOptions', () => {
it('supports deprecated stagingFolderPath option', () => {
sinon.stub(fsExtra, 'existsSync').callsFake((filePath) => {
return false;
});
expect(
rokuDeploy.getOptions({ stagingFolderPath: 'staging-folder-path' }).stagingDir
).to.eql(s`${cwd}/staging-folder-path`);
expect(
rokuDeploy.getOptions({ stagingFolderPath: 'staging-folder-path', stagingDir: 'staging-dir' }).stagingDir
).to.eql(s`${cwd}/staging-dir`);
expect(
rokuDeploy.getOptions({ stagingFolderPath: 'staging-folder-path' }).stagingFolderPath
).to.be.undefined;
});

it('supports deprecated retainStagingFolder option', () => {
sinon.stub(fsExtra, 'existsSync').callsFake((filePath) => {
return false;
});
expect(
rokuDeploy.getOptions({ retainStagingFolder: true }).retainStagingDir
).to.be.true;
expect(
rokuDeploy.getOptions({ retainStagingFolder: true, retainStagingDir: false }).retainStagingDir
).to.be.false;
expect(
rokuDeploy.getOptions({ retainStagingFolder: true, retainStagingDir: false }).retainStagingFolder
).to.be.undefined;
});

it('calling with no parameters works', () => {
sinon.stub(fsExtra, 'existsSync').callsFake((filePath) => {
return false;
});
options = rokuDeploy.getOptions(undefined);
expect(options.stagingFolderPath).to.exist;
expect(options.stagingDir).to.exist;
});

it('calling with empty param object', () => {
sinon.stub(fsExtra, 'existsSync').callsFake((filePath) => {
return false;
});
options = rokuDeploy.getOptions({});
expect(options.stagingFolderPath).to.exist;
expect(options.stagingDir).to.exist;
});

it('works when passing in stagingFolderPath', () => {
it('works when passing in stagingDir', () => {
sinon.stub(fsExtra, 'existsSync').callsFake((filePath) => {
return false;
});
options = rokuDeploy.getOptions({
stagingFolderPath: './staging-dir'
stagingDir: './staging-dir'
});
expect(options.stagingFolderPath.endsWith('staging-dir')).to.be.true;
expect(options.stagingDir.endsWith('staging-dir')).to.be.true;
});

it('works when loading stagingFolderPath from rokudeploy.json', () => {
it('works when loading stagingDir from rokudeploy.json', () => {
sinon.stub(fsExtra, 'existsSync').callsFake((filePath) => {
return true;
});
sinon.stub(fsExtra, 'readFileSync').returns(`
{
"stagingFolderPath": "./staging-dir"
"stagingDir": "./staging-dir"
}
`);
options = rokuDeploy.getOptions();
expect(options.stagingFolderPath.endsWith('staging-dir')).to.be.true;
expect(options.stagingDir.endsWith('staging-dir')).to.be.true;
});

it('supports jsonc for roku-deploy.json', () => {
Expand Down Expand Up @@ -3080,7 +3110,7 @@ describe('index', () => {

//this should not fail
let pkgFilePath = await rokuDeploy.deployAndSignPackage({
retainStagingFolder: false
retainStagingDir: false
});

//the return value should equal what retrieveSignedPackage returned.
Expand All @@ -3089,14 +3119,14 @@ describe('index', () => {
//fsExtra.remove should have been called
expect(stub.getCalls()).to.be.lengthOf(1);

//call it again, but specify true for retainStagingFolder
//call it again, but specify true for retainStagingDir
await rokuDeploy.deployAndSignPackage({
retainStagingFolder: true
retainStagingDir: true
});
//call count should NOT increase
expect(stub.getCalls()).to.be.lengthOf(1);

//call it again, but don't specify retainStagingFolder at all (it should default to FALSE)
//call it again, but don't specify retainStagingDir at all (it should default to FALSE)
await rokuDeploy.deployAndSignPackage({});
//call count should NOT increase
expect(stub.getCalls()).to.be.lengthOf(2);
Expand Down
Loading