Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to stagingDir away from stagingFolder #706

Merged
merged 1 commit into from
Sep 30, 2022
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ These are the options available in the `bsconfig.json` file.

- **rootDir**: `string` - The root directory of your roku project. Defaults to current directory

- **stagingFolderPath**: `string` - the folder where the transpiled files are placed. Defaults to `./out/.roku-deploy-staging`
- **stagingDir**: `string` - the folder where the transpiled files are placed. Defaults to `./out/.roku-deploy-staging`

- **retainStagingDir**: `boolean` - Prevent the staging folder from being deleted after creating the package. Defaults to `false` meaning the dir is deleted every time.

- **files**: ` (string | string[] | { src: string | string[]; dest?: string })[]` - The list file globs used to find all files for the project. If using the {src;dest;} format, you can specify a different destination directory for the matched files in src.

Expand Down
11 changes: 11 additions & 0 deletions bsconfig.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,24 @@
"description": " The password to use when deploying to a Roku device",
"type": "string"
},
"retainStagingDir": {
"type": "boolean",
"description": "Prevent the staging folder from being deleted after the deployment package is created. This is helpful for troubleshooting why your package isn't being created the way you expected.",
"default": false
},
"retainStagingFolder": {
"type": "boolean",
"deprecated": true,
"description": "Prevent the staging folder from being deleted after the deployment package is created. This is helpful for troubleshooting why your package isn't being created the way you expected.",
"default": false
},
"stagingDir": {
"type": "string",
"description": "The path to the staging folder (where all files are copied before creating the zip package)"
},
"stagingFolderPath": {
"type": "string",
"deprecated": true,
"description": "The path to the staging folder (where all files are copied before creating the zip package)"
},
"ignoreErrorCodes": {
Expand Down
13 changes: 13 additions & 0 deletions src/BsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,23 @@ export interface BsConfig {
* Prevent the staging folder from being deleted after creating the package
* @default false
*/
retainStagingDir?: boolean;

/**
* Prevent the staging folder from being deleted after creating the package
* @default false
* @deprecated use `retainStagingDir` instead
*/
retainStagingFolder?: boolean;

/**
* The path to the staging directory (wehre the output files are copied immediately before creating the zip)
*/
stagingDir?: string;

/**
* The path to the staging folder (where all files are copied to right before creating the zip package)
* @deprecated use `stagingDir` instead
*/
stagingFolderPath?: string;

Expand Down
24 changes: 12 additions & 12 deletions src/Program.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Program', () => {
fsExtra.emptyDirSync(tempDir);
program = new Program({
rootDir: rootDir,
stagingFolderPath: stagingDir
stagingDir: stagingDir
});
program.createSourceScope(); //ensure source scope is created
});
Expand Down Expand Up @@ -1710,19 +1710,19 @@ describe('Program', () => {
});

it('does not create map by default', async () => {
fsExtra.ensureDirSync(program.options.stagingFolderPath);
fsExtra.ensureDirSync(program.options.stagingDir);
program.setFile('source/main.brs', `
sub main()
end sub
`);
program.validate();
await program.transpile([], program.options.stagingFolderPath);
await program.transpile([], program.options.stagingDir);
expect(fsExtra.pathExistsSync(s`${stagingDir}/source/main.brs`)).is.true;
expect(fsExtra.pathExistsSync(s`${stagingDir}/source/main.brs.map`)).is.false;
});

it('creates sourcemap for brs and xml files', async () => {
fsExtra.ensureDirSync(program.options.stagingFolderPath);
fsExtra.ensureDirSync(program.options.stagingDir);
program.setFile('source/main.brs', `
sub main()
end sub
Expand All @@ -1745,17 +1745,17 @@ describe('Program', () => {
dest: s`components/comp1.xml`
}];
program.options.sourceMap = true;
await program.transpile(filePaths, program.options.stagingFolderPath);
await program.transpile(filePaths, program.options.stagingDir);

expect(fsExtra.pathExistsSync(s`${stagingDir}/source/main.brs.map`)).is.true;
expect(fsExtra.pathExistsSync(s`${stagingDir}/components/comp1.xml.map`)).is.true;
});

it('copies the bslib.brs file', async () => {
fsExtra.ensureDirSync(program.options.stagingFolderPath);
fsExtra.ensureDirSync(program.options.stagingDir);
program.validate();

await program.transpile([], program.options.stagingFolderPath);
await program.transpile([], program.options.stagingDir);

expect(fsExtra.pathExistsSync(s`${stagingDir}/source/bslib.brs`)).is.true;
});
Expand Down Expand Up @@ -1981,7 +1981,7 @@ describe('Program', () => {
print SOURCE_LINE_NUM
end sub
`);
await program.transpile([], program.options.stagingFolderPath);
await program.transpile([], program.options.stagingDir);
expect(trimMap(
fsExtra.readFileSync(s`${stagingDir}/source/logger.brs`).toString()
)).to.eql(trim`
Expand All @@ -1997,7 +1997,7 @@ describe('Program', () => {
print "logInfo"
end sub
`);
await program.transpile([], program.options.stagingFolderPath);
await program.transpile([], program.options.stagingDir);
expect(trimMap(
fsExtra.readFileSync(s`${stagingDir}/source/logger.brs`).toString()
)).to.eql(trim`
Expand All @@ -2013,7 +2013,7 @@ describe('Program', () => {
<component name="Component1" extends="Scene">
</component>
`);
await program.transpile([], program.options.stagingFolderPath);
await program.transpile([], program.options.stagingDir);
expect(trimMap(
fsExtra.readFileSync(s`${stagingDir}/components/Component1.xml`).toString()
)).to.eql(trim`
Expand All @@ -2028,7 +2028,7 @@ describe('Program', () => {
let sourceRoot = s`${tempDir}/sourceRootFolder`;
program = new Program({
rootDir: rootDir,
stagingFolderPath: stagingDir,
stagingDir: stagingDir,
sourceRoot: sourceRoot,
sourceMap: true
});
Expand All @@ -2054,7 +2054,7 @@ describe('Program', () => {
let sourceRoot = s`${tempDir}/sourceRootFolder`;
program = new Program({
rootDir: rootDir,
stagingFolderPath: stagingDir,
stagingDir: stagingDir,
sourceRoot: sourceRoot,
sourceMap: true
});
Expand Down
12 changes: 6 additions & 6 deletions src/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ export class Program {
filteredFileMap.push(fileEntry);
}
}
const { entries, astEditor } = this.beforeProgramTranspile(fileMap, this.options.stagingFolderPath);
const { entries, astEditor } = this.beforeProgramTranspile(fileMap, this.options.stagingDir);
const result = this._getTranspiledFileContents(
this.getFile(filePath)
);
Expand Down Expand Up @@ -1397,7 +1397,7 @@ export class Program {
};
}

private beforeProgramTranspile(fileEntries: FileObj[], stagingFolderPath: string) {
private beforeProgramTranspile(fileEntries: FileObj[], stagingDir: string) {
// map fileEntries using their path as key, to avoid excessive "find()" operations
const mappedFileEntries = fileEntries.reduce<Record<string, FileObj>>((collection, entry) => {
collection[s`${entry.src}`] = entry;
Expand All @@ -1417,7 +1417,7 @@ export class Program {
//replace the file extension
let outputPath = filePathObj.dest.replace(/\.bs$/gi, '.brs');
//prepend the staging folder path
outputPath = s`${stagingFolderPath}/${outputPath}`;
outputPath = s`${stagingDir}/${outputPath}`;
return outputPath;
};

Expand All @@ -1438,8 +1438,8 @@ export class Program {
};
}

public async transpile(fileEntries: FileObj[], stagingFolderPath: string) {
const { entries, getOutputPath, astEditor } = this.beforeProgramTranspile(fileEntries, stagingFolderPath);
public async transpile(fileEntries: FileObj[], stagingDir: string) {
const { entries, getOutputPath, astEditor } = this.beforeProgramTranspile(fileEntries, stagingDir);

const processedFiles = new Set<string>();

Expand Down Expand Up @@ -1480,7 +1480,7 @@ export class Program {

//if there's no bslib file already loaded into the program, copy it to the staging directory
if (!this.getFile(bslibAliasedRokuModulesPkgPath) && !this.getFile(s`source/bslib.brs`)) {
promises.push(util.copyBslibToStaging(stagingFolderPath));
promises.push(util.copyBslibToStaging(stagingDir));
}
await Promise.all(promises);

Expand Down
8 changes: 4 additions & 4 deletions src/ProgramBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ describe('ProgramBuilder', () => {
builder1.run({
logLevel: LogLevel.info,
rootDir: rootDir,
stagingFolderPath: stagingDir,
stagingDir: stagingDir,
watch: false
}),
builder2.run({
logLevel: LogLevel.error,
rootDir: rootDir,
stagingFolderPath: stagingDir,
stagingDir: stagingDir,
watch: false
})
]);
Expand All @@ -180,10 +180,10 @@ describe('ProgramBuilder', () => {
expect(builder2.logger.logLevel).to.equal(LogLevel.error);
});

it('does not error when loading stagingFolderPath from bsconfig.json', async () => {
it('does not error when loading stagingDir from bsconfig.json', async () => {
fsExtra.ensureDirSync(rootDir);
fsExtra.writeFileSync(`${rootDir}/bsconfig.json`, `{
"stagingFolderPath": "./out"
"stagingDir": "./out"
}`);
let builder = new ProgramBuilder();
await builder.run({
Expand Down
2 changes: 1 addition & 1 deletion src/ProgramBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ export class ProgramBuilder {

await this.logger.time(LogLevel.log, ['Transpiling'], async () => {
//transpile any brighterscript files
await this.program.transpile(fileMap, options.stagingFolderPath);
await this.program.transpile(fileMap, options.stagingDir);
});

this.plugins.emit('afterPublish', this, fileMap);
Expand Down
2 changes: 1 addition & 1 deletion src/files/BrsFile.Class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('BrsFile BrighterScript classes', () => {
beforeEach(() => {
fsExtra.ensureDirSync(rootDir);
fsExtra.emptyDirSync(tempDir);
program = new Program({ rootDir: rootDir, stagingFolderPath: stagingDir });
program = new Program({ rootDir: rootDir, stagingDir: stagingDir });
});
afterEach(() => {
sinon.restore();
Expand Down
4 changes: 2 additions & 2 deletions src/files/XmlFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,8 @@ describe('XmlFile', () => {
const builder = new ProgramBuilder();
await builder.run({
cwd: rootDir,
retainStagingFolder: true,
stagingFolderPath: stagingDir,
retainStagingDir: true,
stagingDir: stagingDir,
logLevel: LogLevel.off
});
expect(
Expand Down
2 changes: 1 addition & 1 deletion src/files/tests/imports.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('import statements', () => {
fsExtra.emptyDirSync(tempDir);
program = new Program({
rootDir: rootDir,
stagingFolderPath: stagingDir
stagingDir: stagingDir
});
});
afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/files/tests/optionalChaning.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('optional chaining', () => {
fsExtra.emptyDirSync(tempDir);
program = new Program({
rootDir: rootDir,
stagingFolderPath: stagingDir
stagingDir: stagingDir
});
});
afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/globalCallables.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('globalCallables', () => {
beforeEach(() => {
program = new Program({
rootDir: rootDir,
stagingFolderPath: stagingDir
stagingDir: stagingDir
});
});
afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/AstNode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Program', () => {
fsExtra.emptyDirSync(tempDir);
program = new Program({
rootDir: rootDir,
stagingFolderPath: stagingDir
stagingDir: stagingDir
});
program.createSourceScope(); //ensure source scope is created
});
Expand Down
3 changes: 2 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ export class Util {
config.username = config.username ?? 'rokudev';
config.watch = config.watch === true ? true : false;
config.emitFullPaths = config.emitFullPaths === true ? true : false;
config.retainStagingFolder = config.retainStagingFolder === true ? true : false;
config.retainStagingDir = (config.retainStagingDir ?? config.retainStagingFolder) === true ? true : false;
config.retainStagingFolder = config.retainStagingDir;
config.copyToStaging = config.copyToStaging === false ? false : true;
config.ignoreErrorCodes = config.ignoreErrorCodes ?? [];
config.diagnosticFilters = config.diagnosticFilters ?? [];
Expand Down