0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-12 00:08:59 +01:00
Bootstrap/grunt/shrinkwrap.js

42 lines
1.5 KiB
JavaScript
Raw Normal View History

/*!
* Bootstrap Grunt task for generating npm-shrinkwrap.canonical.json
* http://getbootstrap.com
* Copyright 2014 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
2014-01-20 22:06:13 +01:00
/*
This Grunt task updates the npm-shrinkwrap.canonical.json file that's used as the key for Bootstrap's npm packages cache.
This task should be run and the updated file should be committed whenever Bootstrap's dependencies change.
*/
'use strict';
2014-01-20 22:06:13 +01:00
var canonicallyJsonStringify = require('canonical-json');
var NON_CANONICAL_FILE = 'npm-shrinkwrap.json';
var DEST_FILE = 'test-infra/npm-shrinkwrap.canonical.json';
2014-03-08 01:05:46 +01:00
function cleanup(shrinkwrap) {
// Remove `resolved` property to avoid irrelevant changes
// See https://github.com/npm/npm/issues/3581
2014-03-08 10:44:24 +01:00
if (typeof shrinkwrap === 'string') {
2014-03-08 01:05:46 +01:00
return shrinkwrap;
}
delete shrinkwrap.resolved;
for (var key in shrinkwrap) {
shrinkwrap[key] = cleanup(shrinkwrap[key]);
}
return shrinkwrap;
}
2014-01-20 22:06:13 +01:00
function updateShrinkwrap(grunt) {
// Assumption: Non-canonical shrinkwrap already generated by prerequisite Grunt task
var shrinkwrapData = grunt.file.readJSON(NON_CANONICAL_FILE);
grunt.log.writeln('Deleting ' + NON_CANONICAL_FILE.cyan + '...');
grunt.file.delete(NON_CANONICAL_FILE);
// Output as Canonical JSON in correct location
2014-03-08 01:05:46 +01:00
grunt.file.write(DEST_FILE, canonicallyJsonStringify(cleanup(shrinkwrapData)));
2014-01-20 22:06:13 +01:00
grunt.log.writeln('File ' + DEST_FILE.cyan + ' updated.');
}
module.exports = updateShrinkwrap;