UNPKG

3.95 kBSource Map (JSON)View Raw
1{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../../src/lib/output/utils/resources/helpers.ts"],"names":[],"mappings":";;AAAA,6BAA6B;AAC7B,yCAAyC;AAEzC,mCAAkD;AAElD,MAAa,MAAO,SAAQ,gBAAQ;IAGhC,UAAU;QACN,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACf,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAEpC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;gBAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;aACvB;iBAAM,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;gBACnC,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,CAAC;aACzB;iBAAM;gBACH,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;aACtC;SACJ;QAED,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;CACJ;AAlBD,wBAkBC;AAED,MAAa,WAAY,SAAQ,qBAAqB;IAGlD;QAII,KAAK,CAAC,MAAM,EAAE,kCAAkC,CAAC,CAAC;QAN9C,oBAAe,GAAa,EAAE,CAAC;QAOnC,IAAI,CAAC,cAAc,EAAE,CAAC;IAC1B,CAAC;IAED,QAAQ;QACJ,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE;YACnB,OAAO,KAAK,CAAC;SAChB;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAEzC,KAAK,IAAI,YAAY,IAAI,SAAS,EAAE;YAChC,MAAM,OAAO,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC,UAAU,EAAE,CAAC;YAErD,KAAK,IAAI,IAAI,IAAI,OAAO,EAAE;gBACtB,IAAI,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;oBACrC,SAAS;iBACZ;gBACD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAEhC,UAAU,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;aAClD;SACJ;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,UAAU;QACN,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE;YACrB,OAAO,KAAK,CAAC;SAChB;QAED,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,eAAe,EAAE;YACnC,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;SACrC;QAED,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,cAAc;QACV,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,gBAAgB;QACZ,KAAK,CAAC,gBAAgB,EAAE,CAAC;QACzB,IAAI,CAAC,cAAc,EAAE,CAAC;IAC1B,CAAC;CACJ;AAtDD,kCAsDC","sourcesContent":["import * as Path from 'path';\nimport * as Handlebars from 'handlebars';\n\nimport { ResourceStack, Resource } from './stack';\n\nexport class Helper extends Resource {\n private helpers: any;\n\n getHelpers(): any {\n if (!this.helpers) {\n const file = require(this.fileName);\n\n if (typeof file === 'object') {\n this.helpers = file;\n } else if (typeof file === 'function') {\n this.helpers = file();\n } else {\n throw new Error('Invalid helper.');\n }\n }\n\n return this.helpers;\n }\n}\n\nexport class HelperStack extends ResourceStack<Helper> {\n private registeredNames: string[] = [];\n\n constructor() {\n // Include .ts files so that tests run with ts-node work.\n // Exclude .d.ts files so that declaration files are not included after compilation.\n // Once lookbehind assertions are supported by all supported Node versions replace with /(?<!\\.d)\\.ts$|\\.js$/\n super(Helper, /((?!\\.d).{2}|^.{0,1})\\.ts$|\\.js$/);\n this.addCoreHelpers();\n }\n\n activate(): boolean {\n if (!super.activate()) {\n return false;\n }\n const resources = this.getAllResources();\n\n for (let resourceName in resources) {\n const helpers = resources[resourceName].getHelpers();\n\n for (let name in helpers) {\n if (this.registeredNames.includes(name)) {\n continue;\n }\n this.registeredNames.push(name);\n\n Handlebars.registerHelper(name, helpers[name]);\n }\n }\n\n return true;\n }\n\n deactivate(): boolean {\n if (!super.deactivate()) {\n return false;\n }\n\n for (let name of this.registeredNames) {\n Handlebars.unregisterHelper(name);\n }\n\n this.registeredNames = [];\n return true;\n }\n\n addCoreHelpers() {\n this.addOrigin('core', Path.join(__dirname, '..', '..', 'helpers'));\n }\n\n removeAllOrigins() {\n super.removeAllOrigins();\n this.addCoreHelpers();\n }\n}\n"]}
\No newline at end of file