sp-dev-fx-webparts/samples/react-versiondisplay/gulpfile.js

61 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-04-10 15:27:14 -04:00
'use strict';
const build = require('@microsoft/sp-build-web');
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
2022-02-08 01:03:23 -05:00
var getTasks = build.rig.getTasks;
build.rig.getTasks = function () {
var result = getTasks.call(build.rig);
result.set('serve', result.get('serve-deprecated'));
return result;
};
2020-04-10 15:27:14 -04:00
// BEGIN: Add custom version sync task
2022-02-08 01:03:23 -05:00
let syncVersionsSubtask = build.subTask('version-sync', function (_gulp, _buildOptions, done) {
2020-04-10 15:27:14 -04:00
this.log('Synching versions');
// import file system utilities form nodeJS
const fs = require('fs');
// read package.json
var pkgConfig = require('./package.json');
// read configuration of web part solution file
var pkgSolution = require('./config/package-solution.json');
// log old version
this.log('package-solution.json version:\t' + pkgSolution.solution.version);
// Generate new MS compliant version number
var newVersionNumber = pkgConfig.version.split('-')[0] + '.0';
if (pkgSolution.solution.version !== newVersionNumber) {
// assign newly generated version number to web part version
pkgSolution.solution.version = newVersionNumber;
// log new version
this.log('New package-solution.json version:\t' + pkgSolution.solution.version);
// write changed package-solution file
2022-02-08 01:03:23 -05:00
fs.writeFileSync('./config/package-solution.json', JSON.stringify(pkgSolution, null, 4));
2020-04-10 15:27:14 -04:00
}
else {
this.log('package-solution.json version is up-to-date');
}
done();
});
2022-02-08 01:03:23 -05:00
// Register the task with gulp command line
let versionSyncTask = build.task('version-sync', syncVersionsSubtask);
2020-04-10 15:27:14 -04:00
2022-02-08 01:03:23 -05:00
// execute before the TypeScript subtask
build.rig.addPreBuildTask(versionSyncTask);
2020-04-10 15:27:14 -04:00
// END: Add custom version sync task
build.initialize(require('gulp'));