diff --git a/lib/.eslintrc.js b/lib/.eslintrc.js new file mode 100644 index 000000000..f2ad64d79 --- /dev/null +++ b/lib/.eslintrc.js @@ -0,0 +1,50 @@ +module.exports = { + "env": { + "node": true, + "es6": true + }, + "parserOptions": { + "ecmaVersion": 8 + }, + "extends": ["eslint:recommended", "google"], + "rules": { + "indent": [ + "error", + "tab" + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "double", + { "allowTemplateLiterals": true } + ], + "semi": [ + "error", + "always" + ], + "no-negated-condition": "off", + "require-jsdoc": "off", + "no-mixed-requires": "off", + "max-len": ["warn", 120], + "no-implicit-coercion": [ + 2, + { "allow": ["!!"] } + ], + "comma-dangle": "off", + "no-tabs": "off", + "no-console": "off", // sometimes needed by CLI + 'valid-jsdoc': [ + 2, + { + requireParamDescription: false, + requireReturnDescription: false, + requireReturn: false, + prefer: {return: 'returns'}, + } + ], + }, + "root": true +}; diff --git a/lib/tasks/ponyInserter.js b/lib/tasks/ponyInserter.js new file mode 100644 index 000000000..fa2f18ead --- /dev/null +++ b/lib/tasks/ponyInserter.js @@ -0,0 +1,32 @@ +const stringReplacer = require("@ui5/builder").processors.stringReplacer; + +/** + * Generates "sap-ui-messagebundle-preload.js" file for all found message bundles + * + * @param {Object} parameters Parameters + * @param {DuplexCollection} parameters.workspace DuplexCollection to read and write files + * @param {AbstractReader} parameters.dependencies Reader or Collection to read dependency files + * @param {Object} parameters.options Options + * @param {string} parameters.options.projectName Project name + * @param {string} [parameters.options.configuration] Task configuration if given in ui5.yaml + * @returns {Promise} Promise resolving with undefined once data has been written + */ +module.exports = function({workspace, options}) { + const pattern = options.configuration.pattern || "the"; + + return workspace.byGlob("/**/*.{js,json,html}") + .then((processedResources) => { + return stringReplacer({ + resources: processedResources, + options: { + pattern: new RegExp(pattern), + replacement: "pony" + } + }); + }) + .then((processedResources) => { + return Promise.all(processedResources.map((resource) => { + return workspace.write(resource); + })); + }); +}; diff --git a/package.json b/package.json index e27307359..43842663f 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,10 @@ "@openui5/themelib_sap_belize": "^1.52.5" }, "devDependencies": { + "@ui5/builder": "^0.2.4", "@ui5/cli": "^0.2.1", "eslint": "^4.19.1", + "eslint-config-google": "^0.11.0", "karma": "^2.0.5", "karma-chrome-launcher": "^2.2.0", "karma-coverage": "^1.1.2", diff --git a/ui5.yaml b/ui5.yaml index 4fa7af0d4..753e69709 100644 --- a/ui5.yaml +++ b/ui5.yaml @@ -2,3 +2,17 @@ specVersion: '0.1' metadata: name: openui5-sample-app type: application +builder: + customTasks: + - name: ponyInserter + beforeTask: uglify + configuration: + pattern: the +--- +specVersion: "0.1" +kind: extension +type: task +metadata: + name: ponyInserter +task: + path: lib/tasks/ponyInserter.js