Skip to content

Commit

Permalink
Merge 2995740 into 7d35d6d
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeyer2115 authored Aug 18, 2021
2 parents 7d35d6d + 2995740 commit ca4f3f2
Show file tree
Hide file tree
Showing 19 changed files with 814 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .circleci/testcafe.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"src": "tests/acceptance/acceptancesuites/*.js",
"src": ["tests/acceptance/acceptancesuites/*.js", "!tests/acceptance/acceptancesuites/searchbaronlysuite.js"],
"appCommand": "npx serve -l tcp://0.0.0.0:9999",
"appInitDelay": 4000
}
28 changes: 22 additions & 6 deletions conf/gulp-tasks/bundle/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ const {
const TranslateCallParser = require('../../i18n/translatecallparser');

/**
* The Gulp task for producing the modern version of the SDK bundle.
* The Gulp task for producing the modern bundle of an SDK asset.
*
* @param {Function} callback
* @param {string} entryPoint The entry point for the asset.
* @param {Object<string, ?>} outputConfig Any variant-specific configuration
* for the modern bundle.
* @param {string} bundleName The name of the created bundle.
Expand All @@ -28,9 +29,16 @@ const TranslateCallParser = require('../../i18n/translatecallparser');
* @returns {stream.Writable} A {@link Writable} stream containing the modern
* SDK bundle.
*/
exports.modernBundle = function (callback, outputConfig, bundleName, locale, libVersion, translationResolver) {
exports.modernBundle = function (
callback,
entryPoint,
outputConfig,
bundleName,
locale,
libVersion,
translationResolver) {
const rollupConfig = {
input: './src/answers-umd.js',
input: entryPoint,
output: outputConfig,
plugins: [
resolve({ browser: true }),
Expand All @@ -49,9 +57,10 @@ exports.modernBundle = function (callback, outputConfig, bundleName, locale, lib
};

/**
* The Gulp task for producing either variant of the legacy SDK bundle.
* The Gulp task for producing any variant of a legacy SDK asset.
*
* @param {Function} callback
* @param {string} entryPoint The entry point for the asset.
* @param {Object<string, ?>} outputConfig Any variant-specific configuration
* for the legacy bundle.
* @param {string} bundleName The name of the created bundle.
Expand All @@ -61,9 +70,16 @@ exports.modernBundle = function (callback, outputConfig, bundleName, locale, lib
* @returns {stream.Writable} A {@link Writable} stream containing the legacy
* SDK bundle.
*/
exports.legacyBundle = function (callback, outputConfig, bundleName, locale, libVersion, translationResolver) {
exports.legacyBundle = function (
callback,
entryPoint,
outputConfig,
bundleName,
locale,
libVersion,
translationResolver) {
const rollupConfig = {
input: './src/answers-umd.js',
input: entryPoint,
output: outputConfig,
plugins: [
resolve({ browser: true }),
Expand Down
29 changes: 18 additions & 11 deletions conf/gulp-tasks/bundle/bundletaskfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const BundleType = {
Object.freeze(BundleType);

/**
* A factory class that provides Gulp tasks for the different kinds of SDK bundle.
* A factory class that provides Gulp tasks for the different kinds of SDK bundles.
*/
class BundleTaskFactory {
constructor (libVersion, translationResolver, locale) {
Expand All @@ -24,19 +24,20 @@ class BundleTaskFactory {
* Provides a Gulp task to create an SDK bundle of the specified type.
*
* @param {BundleType} bundleType The type of SDK bundle to build.
* @param {string} entryPoint The SDK asset's entry point.
* @returns {Function} Gulp task for producing the requested SDK bundle.
*/
create (bundleType) {
create (bundleType, entryPoint = './src/answers-umd.js') {
let bundleFunction;
switch (bundleType) {
case BundleType.MODERN:
bundleFunction = (callback) => this._modernBundle(callback);
bundleFunction = (callback) => this._modernBundle(callback, entryPoint);
break;
case BundleType.LEGACY_IIFE:
bundleFunction = (callback) => this._legacyBundleIIFE(callback);
bundleFunction = (callback) => this._legacyBundleIIFE(callback, entryPoint);
break;
case BundleType.LEGACY_UMD:
bundleFunction = (callback) => this._legacyBundleUMD(callback);
bundleFunction = (callback) => this._legacyBundleUMD(callback, entryPoint);
break;
default:
throw new Error('Unrecognized BundleType');
Expand All @@ -48,13 +49,14 @@ class BundleTaskFactory {
}

/**
* The Gulp task for producing the modern version of the SDK bundle.
* The Gulp task for producing the modern version of an SDK bundle.
*
* @param {function} callback function that will run after the Gulp task
* @param {string} entryPoint The bundle's entry point.
* @returns {stream.Writable} A {@link Writable} stream containing the modern
* SDK bundle.
*/
_modernBundle (callback) {
_modernBundle (callback, entryPoint) {
const modernBundleConfig = {
format: 'umd',
name: this._namespace,
Expand All @@ -63,6 +65,7 @@ class BundleTaskFactory {
};
return modernBundle(
callback,
entryPoint,
modernBundleConfig,
getBundleName(BundleType.MODERN, this._locale),
this._locale,
Expand All @@ -72,20 +75,22 @@ class BundleTaskFactory {
}

/**
* The Gulp task for producing the legacy, IIFE-style SDK bundle.
* The Gulp task for producing a legacy, IIFE-style SDK bundle.
*
* @param {function} callback function that will run after the Gulp task
* @param {string} entryPoint The bundle's entry point.
* @returns {stream.Writable} A {@link Writable} stream containing the legacy,
* IIFE-style SDK bundle.
*/
_legacyBundleIIFE (callback) {
_legacyBundleIIFE (callback, entryPoint) {
const legacyBundleConfig = {
format: 'iife',
name: this._namespace,
sourcemap: true
};
return legacyBundle(
callback,
entryPoint,
legacyBundleConfig,
getBundleName(BundleType.LEGACY_IIFE, this._locale),
this._locale,
Expand All @@ -95,13 +100,14 @@ class BundleTaskFactory {
}

/**
* The Gulp task for producing the legacy, UMD-style SDK bundle.
* The Gulp task for producing a legacy, UMD-style SDK bundle.
*
* @param {function} callback function that will run after the Gulp task
* @param {string} entryPoint The bundle's entry point.
* @returns {stream.Writable} A {@link Writable} stream containing the legacy,
* UMD-style SDK bundle.
*/
_legacyBundleUMD (callback) {
_legacyBundleUMD (callback, entryPoint) {
const legacyBundleConfig = {
format: 'umd',
name: this._namespace,
Expand All @@ -110,6 +116,7 @@ class BundleTaskFactory {
};
return legacyBundle(
callback,
entryPoint,
legacyBundleConfig,
getBundleName(BundleType.LEGACY_UMD, this._locale),
this._locale,
Expand Down
50 changes: 34 additions & 16 deletions conf/gulp-tasks/library.gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,29 @@ exports.dev = function devJSBundle () {
* Creates a build task for each provided language and combines them into a series task.
* This function also supports locales, but it is named to reflect the current use case
* of creating bundles for just languages.
*
* @param {Array<string>} languages
* @param {boolean} isSearchBarOnly If the build task is for the SearchBar-only assets.
* @returns {Promise<Function>}
*/
function createJSBundlesForLanguages (languages) {
function createJSBundlesForLanguages (languages, isSearchBarOnly = false) {
const localizedTaskPromises = languages.map(language => {
const minifyTaskFactory = new MinifyTaskFactory(language);
return createBundleTaskFactory(language)
.then(bundleTaskFactory => createBundles(bundleTaskFactory, minifyTaskFactory));
.then(bundleTaskFactory => createBundles(bundleTaskFactory, minifyTaskFactory, isSearchBarOnly));
});
return Promise.all(localizedTaskPromises).then(localizedTasks => {
return new Promise(resolve => series(compileCSS, ...localizedTasks)(resolve));
});
}

exports.default = function defaultLanguageJSBundles () {
return createJSBundlesForLanguages([DEFAULT_LOCALE]);
};

exports.buildLanguages = function allLanguageJSBundles () {
return createJSBundlesForLanguages(ALL_LANGUAGES);
};

exports.buildLocales = function allLocaleJSBundles () {
/**
* Creates a task for building all of the localized SDK assets.
*
* @param {boolean} isSearchBarOnly If the task is for the SearchBar-only assets.
* @returns {Promise<Function>}
*/
function allLocaleJSBundles (isSearchBarOnly = false) {
const assetNames = [
'answers.js',
'answers.min.js',
Expand All @@ -66,29 +66,47 @@ exports.buildLocales = function allLocaleJSBundles () {
'answers-umd.js',
'answers-umd.min.js'];

return createJSBundlesForLanguages(ALL_LANGUAGES).then(() => {
return createJSBundlesForLanguages(ALL_LANGUAGES, isSearchBarOnly).then(() => {
copyAssetsForLocales(assetNames);
});
}

exports.default = function defaultLanguageJSBundles () {
return createJSBundlesForLanguages([DEFAULT_LOCALE]);
};

exports.buildLanguages = function allLanguageJSBundles () {
return createJSBundlesForLanguages(ALL_LANGUAGES);
};

exports.buildLocales = function () {
return allLocaleJSBundles();
};

exports.buildSearchBarOnlyAssets = function () {
return allLocaleJSBundles(true);
};

/**
* Creates modern, legacy and legacyUMD bundles in parallel.
*
* @param {BundleTaskFactory} bundleTaskFactory
* @param {MinifyTaskFactory} minifyTaskFactory
* @param {boolean} isSearchBarOnly If the bundles are for the SearchBar-only integration.
*/
function createBundles (bundleTaskFactory, minifyTaskFactory) {
function createBundles (bundleTaskFactory, minifyTaskFactory, isSearchBarOnly) {
const entryPoint = isSearchBarOnly ? './src/answers-search-bar.js' : './src/answers-umd.js';
return parallel(
series(
bundleTaskFactory.create(BundleType.MODERN),
bundleTaskFactory.create(BundleType.MODERN, entryPoint),
minifyTaskFactory.minify(BundleType.MODERN)
),
series(
bundleTaskFactory.create(BundleType.LEGACY_IIFE),
bundleTaskFactory.create(BundleType.LEGACY_IIFE, entryPoint),
minifyTaskFactory.minify(BundleType.LEGACY_IIFE)
),
series(
bundleTaskFactory.create(BundleType.LEGACY_UMD),
bundleTaskFactory.create(BundleType.LEGACY_UMD, entryPoint),
minifyTaskFactory.minify(BundleType.LEGACY_UMD)
)
);
Expand Down
46 changes: 38 additions & 8 deletions conf/gulp-tasks/template/createprecompiletemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const handlebars = require('gulp-handlebars');
const concat = require('gulp-concat');
const declare = require('gulp-declare');
const wrap = require('gulp-wrap');
const filter = require('gulp-filter');

const TranslateHelperVisitor = require('../../i18n/translatehelpervisitor');
const { addLocalePrefix, getPrecompiledFileName } = require('./filenameutils');
Expand All @@ -12,10 +13,13 @@ const { addLocalePrefix, getPrecompiledFileName } = require('./filenameutils');
*
* @param {string} locale
* @param {Translator} translator
* @param {boolean} isSearchBarOnly If only templates related to the SearchBar
* should be included.
* @returns {Function}
*/
function createPrecompileTemplatesTask (locale, translator) {
const precompileTask = callback => _precompileTemplates(callback, locale, translator);
function createPrecompileTemplatesTask (locale, translator, isSearchBarOnly = false) {
const precompileTask = callback =>
_precompileTemplates(callback, locale, isSearchBarOnly, translator);
const taskName = addLocalePrefix('precompileTemplates', locale);
Object.defineProperty(precompileTask, 'name', {
value: taskName
Expand All @@ -28,25 +32,48 @@ function createPrecompileTemplatesTask (locale, translator) {
*
* @param {Function} callback called when the task is finished
* @param {string} locale
* @param {boolean} isSearchBarOnly If only the templates related to the SearchBar
* should be included.
* @param {Translator} translator
* @returns {stream.Readable}
*/
function _precompileTemplates (callback, locale, translator) {
function _precompileTemplates (callback, locale, isSearchBarOnly, translator) {
const precompiledFileName = getPrecompiledFileName(locale);
const processAST = ast => new TranslateHelperVisitor(translator).accept(ast);
return precompileTemplates(callback, precompiledFileName, processAST);

return precompileTemplates(callback, isSearchBarOnly, precompiledFileName, processAST);
}

/**
* Precopmiles SDK templates to the given output file.
* Precopmiles the requested templates to the given output file.
*
* @param {Function} callback called when the task is finished
* @param {boolean} isSearchBarOnly A boolean indicating if only those templates for
* the search-bar integration should be included.
* @param {string} outputFile
* @param {Function} processAST a function that takes in and mutates a handlebars AST
* @returns {stream.Readable}
*/
function precompileTemplates (callback, outputFile, processAST) {
return src('./src/ui/templates/**/*.hbs')
function precompileTemplates (callback, isSearchBarOnly, outputFile, processAST) {
let templatesStream = src('./src/ui/templates/**/*.hbs');
let handlebarsWrapperData;

if (isSearchBarOnly) {
templatesStream =
templatesStream.pipe(filter(['**/search/**/*.hbs', '**/icons/**/*.hbs']));
handlebarsWrapperData = {
importStatements: 'import Handlebars from \'handlebars/dist/handlebars.runtime.min.js\';'
};
} else {
handlebarsWrapperData = {
importStatements: 'import Handlebars from \'handlebars/dist/handlebars.min.js\';\n' +
'import templateHelpers from \'template-helpers\';',
handlebarsHelpers: 'let handlebarsHelpers = templateHelpers();\n' +
'parseHelper(handlebarsHelpers);'
};
}

return templatesStream
.pipe(handlebars({ processAST: processAST }))
.pipe(wrap(`Handlebars.template(<%= contents %>);
Handlebars.registerPartial(<%= processPartialName(file.relative) %>, <%= customContext(file.relative) %> )`, {}, {
Expand Down Expand Up @@ -83,7 +110,10 @@ function precompileTemplates (callback, outputFile, processAST) {
}
}))
.pipe(concat(outputFile))
.pipe(wrap({ src: './conf/templates/handlebarswrapper.txt' }))
.pipe(wrap(
{ src: './conf/templates/handlebarswrapper.txt' },
handlebarsWrapperData,
{ variable: 'data' }))
.pipe(dest('dist'))
.on('end', callback);
}
Expand Down
Loading

0 comments on commit ca4f3f2

Please sign in to comment.