项目作者: s-KaiNet

项目描述 :
Check the consistency of your localization files inside SharePoint Framework projects.
高级语言: TypeScript
项目地址: git://github.com/s-KaiNet/spfx-check-locale.git
创建时间: 2021-04-03T22:38:10Z
项目社区:https://github.com/s-KaiNet/spfx-check-locale

开源协议:MIT License

下载


Checks that your localization files match the schema inside mystrings.d.ts

npm version

spfx-check-locale is a Node.js module which allows you to check the consistency of your localization files inside SharePoint Framework projects, i.e. localization files match the schema inside mystrings.d.ts.

Also available as a VSCode extension to support nice real-time error reporting.

How to use

Install

npm install spfx-check-locale --save-dev

Update gulpfile.js

  1. const checkLocales = require('spfx-check-locale').checkForErrors;
  2. const argv = build.rig.getYargs().argv;
  3. if (argv.production) {
  4. const check = build.subTask('check-locales', function (gulp, buildOptions, done) {
  5. checkLocales({
  6. projectPath: buildOptions.rootPath,
  7. printErrors: true
  8. })
  9. .then(result => {
  10. if (result.diagnosticData.length === 0) {
  11. done();
  12. } else {
  13. done('Found errors in localization files');
  14. }
  15. }).catch(done);
  16. });
  17. build.rig.addPostBuildTask(build.task('check-locales', check));
  18. }

Now every time you build your SPFx solution for the production spfx-check-locale will check the consistency of all localization files, will print errors report and will fail a build if there are any errors.

Why on production build only? Because the checking takes from 1 to 3 seconds, thus no reason to make your serve process slower. Also, with VSCode extension you have nice real-time error highlights without hurting performance.

API

checkForErrors(options)

Asynchronously checks your SPFx project for inconsistencies in localization files

params

  • options - required, options object with below properties:
    • projectPath - required string, an absolute path to your SPFx solution
    • printErrors - optional boolean, whether to print errors in console

returns

A promise, which resolves to a CheckResults object