maestro-cli-roku
Version:
command line tools for maestro-roku projects
639 lines (638 loc) • 33.2 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
var chai = require("chai");
var chai_1 = require("chai");
var fs = require("fs-extra");
// tslint:disable-next-line:origin-ordered-imports
var _ = require("lodash");
var Feedback_1 = require("../utils/Feedback");
var FileType_1 = require("./FileType");
var ProjectFileMap_1 = require("./ProjectFileMap");
var ProjectProcessor_1 = require("./ProjectProcessor");
var chaiSubset = require('chai-subset');
var dircompare = require('dir-compare');
chai.use(chaiSubset);
var config = require('../../test/testProcessorConfig.json');
var processor;
describe('Project Processor', function () {
beforeEach(function () {
Feedback_1.resetFeedback();
config = _.clone(config);
processor = new ProjectProcessor_1.ProjectProcessor(config);
fs.removeSync(config.outputPath);
});
describe('Initialization', function () {
it('correctly sets source paths and config', function () {
chai_1.expect(processor.config).to.equal(config);
chai_1.expect(processor.fileMap).to.not.be.null;
//TODO look into correct babel compatible way to do this
//expect(processor.fileMap instanceof ProjectFileMap).is.true; // this fails, and so does every other instance checking
});
it('allows overriding of filemap', function () {
var filemap = new ProjectFileMap_1.ProjectFileMap();
processor = new ProjectProcessor_1.ProjectProcessor(config, filemap);
chai_1.expect(processor.config).to.equal(config);
chai_1.expect(processor.fileMap).to.equal(filemap);
});
});
describe('processFiles', function () {
beforeEach(function () {
config = _.clone(config);
processor = new ProjectProcessor_1.ProjectProcessor(config);
fs.removeSync(config.outputPath);
});
it('Processes whole project', function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.timeout(5000);
return [4 /*yield*/, processor.processFiles()];
case 1:
_a.sent();
chai_1.expect(Feedback_1.getFeedbackErrors()).to.be.empty;
return [2 /*return*/];
}
});
});
});
});
describe('Copy files', function () {
var _this = this;
it('correctly copies files to target folder', function () { return __awaiter(_this, void 0, void 0, function () {
var options, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
console.debug('copying files');
return [4 /*yield*/, processor.copyFiles()];
case 1:
_a.sent();
options = { compareSize: true };
res = dircompare.compareSync(config.sourcePaths[0], config.outputPath, options);
chai_1.expect(res.same).to.be.true;
return [2 /*return*/];
}
});
}); });
});
describe('Clear files', function () {
var _this = this;
it('correctly clears target folder', function () { return __awaiter(_this, void 0, void 0, function () {
var options, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
console.debug('copying files');
return [4 /*yield*/, processor.copyFiles()];
case 1:
_a.sent();
options = { compareSize: true };
res = dircompare.compareSync(config.sourcePaths[0], config.outputPath, options);
chai_1.expect(res.same).to.be.true;
processor.clearFiles();
chai_1.expect(fs.pathExistsSync(config.outputPath)).to.be.false;
return [2 /*return*/];
}
});
}); });
});
describe('createFiles', function () {
var _this = this;
beforeEach(function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
processor.clearFiles();
return [4 /*yield*/, processor.copyFiles()];
case 1:
_a.sent();
return [4 /*yield*/, processor.createFiles()];
case 2:
_a.sent();
return [2 /*return*/];
}
});
}); });
it('populates files', function () {
//TODO test warnings and errors!
console.debug('finished processing map');
console.debug('warnings');
console.debug(Feedback_1.getFeedbackWarnings());
console.debug('errors');
console.debug(Feedback_1.getFeedbackErrors());
processor.fileMap.allFiles.forEach(function (v) { return console.debug(v.toString()); });
});
it('does not include excluded folders', function () {
chai_1.expect(processor.fileMap.allFiles).not.contain.keys([
'test2.xml',
'test2importsExcluded.xml',
'test2importsExcluded.brs',
'testExcluded.brs'
]);
console.debug('finished processing map - it contains');
_.forOwn(processor.fileMap.allFiles, function (v, k) { return console.debug(v.toString()); });
});
it('does not include other filetypes', function () {
chai_1.expect(_.some(processor.fileMap.allFiles, { fileType: FileType_1.FileType.Other })).to.be.false;
});
it('correctly identifies brs files', function () {
chai_1.expect(processor.fileMap.getAllFiles().map(function (file) {
return { filename: file.filename, fileType: file.fileType };
})).containSubset([
{ filename: 'Utils.brs', fileType: FileType_1.FileType.Brs },
{ filename: 'BadImport.brs', fileType: FileType_1.FileType.Brs },
{ filename: 'FocusMixin.brs', fileType: FileType_1.FileType.Brs },
{ filename: 'LogMixin.brs', fileType: FileType_1.FileType.Brs },
{ filename: 'MultipleMixin.brs', fileType: FileType_1.FileType.Brs },
{ filename: 'NetMixin.brs', fileType: FileType_1.FileType.Brs },
{ filename: 'TextMixin.brs', fileType: FileType_1.FileType.Brs },
]);
});
it('correctly identifies xml files', function () {
chai_1.expect(processor.fileMap.getAllFiles().map(function (file) {
return { filename: file.filename, fileType: file.fileType };
})).containSubset([
{ filename: 'testXMLOnly.xml', fileType: FileType_1.FileType.Xml },
]);
});
it('correctly identifies ViewXml files', function () {
chai_1.expect(processor.fileMap.getAllFiles().map(function (file) {
return { filename: file.filename, fileType: file.fileType };
})).containSubset([
{ filename: 'test.xml', fileType: FileType_1.FileType.ViewXml },
{ filename: 'test2imports.xml', fileType: FileType_1.FileType.ViewXml },
{ filename: 'testCascadingImports.xml', fileType: FileType_1.FileType.ViewXml },
]);
});
it('correctly identifies CodeBehind files', function () {
chai_1.expect(processor.fileMap.getAllFiles().map(function (file) {
return { filename: file.filename, fileType: file.fileType };
}).filter(function (f) { return f.fileType === FileType_1.FileType.CodeBehind; })).containSubset([
{ filename: 'test.brs', fileType: FileType_1.FileType.CodeBehind },
{ filename: 'test2imports.brs', fileType: FileType_1.FileType.CodeBehind },
{ filename: 'testCascadingImports.brs', fileType: FileType_1.FileType.CodeBehind },
]);
});
it('correctly sets namespaces', function () {
chai_1.expect(__spread(processor.fileMap.allNamespaces.values())).to.have.length(29);
var file = processor.fileMap.getFileByNamespaceName('Utils');
chai_1.expect(file).to.not.be.null;
chai_1.expect(file.filename).to.equal('Utils.brs');
chai_1.expect(file.namespace.name).to.equal('Utils');
file = processor.fileMap.getFileByNamespaceName('FocusMixin');
chai_1.expect(file).to.not.be.null;
chai_1.expect(file.filename).to.equal('FocusMixin.brs');
chai_1.expect(file.namespace.name).to.equal('FocusMixin');
file = processor.fileMap.getFileByNamespaceName('MRuntime');
chai_1.expect(file).to.not.be.null;
chai_1.expect(file.filename).to.equal('MRuntime.brs');
chai_1.expect(file.namespace.name).to.equal('MRuntime');
file = processor.fileMap.getFileByNamespaceName('MultipleMixin');
chai_1.expect(file).to.not.be.null;
chai_1.expect(file.filename).to.equal('MultipleMixin.brs');
chai_1.expect(file.namespace.name).to.equal('MultipleMixin');
file = processor.fileMap.getFileByNamespaceName('TextMixin');
chai_1.expect(file).to.not.be.null;
chai_1.expect(file.filename).to.equal('TextMixin.brs');
chai_1.expect(file.namespace.name).to.equal('TextMixin');
file = processor.fileMap.getFileByNamespaceName('LogMixin');
chai_1.expect(file).to.not.be.null;
chai_1.expect(file.filename).to.equal('LogMixin.brs');
chai_1.expect(file.namespace.name).to.equal('LogMixin');
file = processor.fileMap.getFileByNamespaceName('NetMixin');
chai_1.expect(file).to.not.be.null;
chai_1.expect(file.filename).to.equal('NetMixin.brs');
chai_1.expect(file.namespace.name).to.equal('NetMixin');
file = processor.fileMap.getFileByNamespaceName('AuthMixin');
chai_1.expect(file).to.not.be.null;
chai_1.expect(file.filename).to.equal('AuthMixin.brs');
chai_1.expect(file.namespace.name).to.equal('AuthMixin');
file = processor.fileMap.getFileByNamespaceName('BindingTestVM');
chai_1.expect(file).to.not.be.null;
chai_1.expect(file.filename).to.equal('BindingTestVM.brs');
chai_1.expect(file.namespace.name).to.equal('BindingTestVM');
file = processor.fileMap.getFileByNamespaceName('NameSpace1');
chai_1.expect(file).to.not.be.null;
chai_1.expect(file.filename).to.equal('NameSpaced1.brs');
chai_1.expect(file.namespace.name).to.equal('NameSpace1');
});
});
describe.skip('process some local projects - skip this on CI!', function () {
beforeEach(function () {
config = _.clone(config);
processor = new ProjectProcessor_1.ProjectProcessor(config);
fs.removeSync(config.outputPath);
});
it('Processes applicaster project', function () {
return __awaiter(this, void 0, void 0, function () {
var config;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.timeout(10000);
config = {
filePattern: [
'**/*.bs',
'**/*.brs',
'**/*.xml',
],
processingExcludedPaths: [
'csfake/**/*.*',
'components/rLogComponents/**/*.*',
'source/rLog/**/*.*',
'source/tests/rooibosDist.brs',
'source/tests/rooibosFunctionMap.brs',
'source/AdobeAccessEnabler/adobeAuthorizationTemplate.xml'
],
sourcePaths: [
'/home/george/hope/applicaster/zapp-roku-app/src',
'/home/george/hope/applicaster/zapp-roku-app/external/plugins-core-src',
'/home/george/hope/applicaster/zapp-roku-app/external/plugins-src',
'/home/george/hope/applicaster/zapp-roku-app/external/private-oc-src',
'/home/george/hope/applicaster/zapp-roku-app/external/private-emmys-src',
],
outputPath: 'build',
logLevel: 4,
nonCheckedImports: ['source/rLog/rLogMixin.brs',
'source/tests/rooibosDist.brs',
'source/rooibosFunctionMap.brs',
'source/zapp.brs',
'source/AdobeAccessEnabler/adobeAuthorizationTemplate.xml'
],
buildTimeImports: {
IAuthProvider: [],
IEntitlementsProvider: [],
IBookmarksProvider: [],
IPlayerAnalytics: [],
IAnalytics: []
}
};
processor = new ProjectProcessor_1.ProjectProcessor(config);
return [4 /*yield*/, processor.processFiles()];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
});
it('Processes MList project', function () {
return __awaiter(this, void 0, void 0, function () {
var config;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.timeout(10000);
config = {
filePattern: [
'**/*.bs',
'**/*.brs',
'**/*.xml',
],
processingExcludedPaths: [
'csfake/**/*.*',
'components/rLogComponents/**/*.*',
'source/rLog/**/*.*',
'source/tests/rooibosDist.brs',
'source/tests/rooibosFunctionMap.brs',
'source/AdobeAccessEnabler/adobeAuthorizationTemplate.xml'
],
sourcePaths: [
'/home/george/hope/open-source/MList/src'
],
outputPath: 'build',
logLevel: 4,
nonCheckedImports: ['source/rLog/rLogMixin.brs',
'source/tests/rooibosDist.brs',
'source/rooibosFunctionMap.brs',
'source/zapp.brs',
'source/AdobeAccessEnabler/adobeAuthorizationTemplate.xml'
],
buildTimeImports: {
IAuthProvider: [],
IEntitlementsProvider: [],
IBookmarksProvider: [],
IPlayerAnalytics: [],
IAnalytics: []
}
};
processor = new ProjectProcessor_1.ProjectProcessor(config);
return [4 /*yield*/, processor.processFiles()];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
});
it('Processes applicaster project test config', function () {
return __awaiter(this, void 0, void 0, function () {
var config;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.timeout(10000);
config = {
filePattern: [
'**/*.bs',
'**/*.brs',
'**/*.xml',
],
processingExcludedPaths: [
'csfake/**/*.*',
'components/rLogComponents/**/*.*',
'source/rLog/**/*.*',
'source/tests/rooibosDist.brs',
'source/tests/rooibosFunctionMap.brs',
'source/AdobeAccessEnabler/adobeAuthorizationTemplate.xml'
],
sourcePaths: [
'/home/george/hope/applicaster/zapp-roku-app/src',
'/home/george/hope/applicaster/zapp-roku-app/external/plugins-core-src',
'/home/george/hope/applicaster/zapp-roku-app/external/plugins-src',
'/home/george/hope/applicaster/zapp-roku-app/external/private-oc-src',
'/home/george/hope/applicaster/zapp-roku-app/external/private-emmys-src',
],
outputPath: 'build',
logLevel: 4,
nonCheckedImports: ['source/rLog/rLogMixin.brs',
'source/tests/rooibosDist.brs',
'source/rooibosFunctionMap.brs',
'source/zapp.brs',
'source/AdobeAccessEnabler/adobeAuthorizationTemplate.xml'
],
buildTimeImports: {
IAuthProvider: [
'pkg:/source/aws_cognito_auth_plugin/AwsCognitoAuthPlugin.bs',
],
IEntitlementsProvider: [],
IBookmarksProvider: [],
IPlayerAnalytics: [],
IAnalytics: [],
}
};
processor = new ProjectProcessor_1.ProjectProcessor(config);
return [4 /*yield*/, processor.processFiles()];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
});
it('Processes maestro project', function () {
return __awaiter(this, void 0, void 0, function () {
var config;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
config = {
filePattern: [
'**/*.bs',
'**/*.brs',
'**/*.xml',
],
processingExcludedPaths: [
'components/rLogComponents/**/*.*',
'source/rLog/**/*.*',
'source/tests/rooibosDist.brs',
'source/tests/rooibosFunctionMap.brs',
'source/rooibosFunctionMap.brs'
],
sourcePaths: ['/home/george/hope/open-source/maestro/framework'],
outputPath: 'build',
logLevel: 4,
nonCheckedImports: ['source/rLog/rLogMixin.brs',
'source/tests/rooibosDist.brs',
'source/tests/rooibosFunctionMap.brs',
'source/rooibosFunctionMap.brs'
]
};
processor = new ProjectProcessor_1.ProjectProcessor(config);
return [4 /*yield*/, processor.processFiles()];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
});
it('Processes maestro sample todo', function () {
return __awaiter(this, void 0, void 0, function () {
var config;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
config = {
filePattern: [
'**/*.bs',
'**/*.brs',
'**/*.xml',
],
processingExcludedPaths: [
'components/rLogComponents/**/*.*',
'source/rLog/**/*.*',
'source/tests/rooibosDist.brs',
'source/tests/rooibosFunctionMap.brs'
],
sourcePaths: ['/home/george/hope/open-source/maestro/samples/todo/src'],
outputPath: 'build',
logLevel: 4,
nonCheckedImports: ['source/rLog/rLogMixin.brs',
'source/tests/rooibosDist.brs',
'source/tests/rooibosFunctionMap.brs'
]
};
processor = new ProjectProcessor_1.ProjectProcessor(config);
return [4 /*yield*/, processor.processFiles()];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
});
it('Processes maestro sample todoXML', function () {
return __awaiter(this, void 0, void 0, function () {
var config;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
config = {
filePattern: [
'**/*.bs',
'**/*.brs',
'**/*.xml',
],
processingExcludedPaths: [
'components/rLogComponents/**/*.*',
'source/rLog/**/*.*',
'source/tests/rooibosDist.brs',
'source/tests/rooibosFunctionMap.brs'
],
sourcePaths: ['/Users/georgecook/Documents/h7ci/hope/maestro/samples]/todoXMLBindings/src'],
outputPath: 'build',
logLevel: 4,
nonCheckedImports: ['source/rLog/rLogMixin.brs',
'source/tests/rooibosDist.brs',
'source/tests/rooibosFunctionMap.brs'
]
};
processor = new ProjectProcessor_1.ProjectProcessor(config);
return [4 /*yield*/, processor.processFiles()];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
});
it('Processes rooibos src', function () {
return __awaiter(this, void 0, void 0, function () {
var config;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
config = {
filePattern: [
'**/*.bs',
'**/*.brs',
'**/*.xml',
],
processingExcludedPaths: [],
sourcePaths: ['/home/george/hope/open-source/rooibos/src'],
outputPath: 'build',
logLevel: 4,
nonCheckedImports: []
};
processor = new ProjectProcessor_1.ProjectProcessor(config);
return [4 /*yield*/, processor.processFiles()];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
});
it('Processes rooibos tests', function () {
return __awaiter(this, void 0, void 0, function () {
var config;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
config = {
filePattern: [
'**/*.bs',
'**/*.brs',
'**/*.xml',
],
processingExcludedPaths: [],
sourcePaths: ['/home/george/hope/open-source/rooibos/frameworkTests'],
outputPath: 'build',
logLevel: 4,
createRuntimeFiles: false,
nonCheckedImports: []
};
processor = new ProjectProcessor_1.ProjectProcessor(config);
return [4 /*yield*/, processor.processFiles()];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
});
it('Processes corko-roku', function () {
return __awaiter(this, void 0, void 0, function () {
var config;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
config = {
filePattern: [
'**/*.bs',
'**/*.brs',
'**/*.xml',
],
processingExcludedPaths: [
'components/rLogComponents/**/*.*',
'source/rLog/**/*.*',
'source/tests/rooibosDist.brs',
'source/tests/rooibosFunctionMap.brs'
],
sourcePaths: ['/Users/georgecook/Documents/h7ci/hope/miracle-channel]/corco-roku/src'],
outputPath: 'build',
logLevel: 4,
nonCheckedImports: ['source/rLog/rLogMixin.brs',
'source/tests/rooibosDist.brs',
'source/tests/rooibosFunctionMap.brs'
]
};
processor = new ProjectProcessor_1.ProjectProcessor(config);
return [4 /*yield*/, processor.processFiles()];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
});
});
});