-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathcreatemgitjsoncontent.js
45 lines (37 loc) · 1.15 KB
/
createmgitjsoncontent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
/**
* Creates content for the `mgit.json` file based on the `package.json` dependencies.
*
* @param {Object} packageJson Parsed package.json.
*/
module.exports = function createMgitJsonContent( packageJson ) {
const mgitJson = {
dependencies: {}
};
const dependencies = Object.assign( {}, packageJson.dependencies, packageJson.devDependencies );
for ( const dependencyName in dependencies ) {
const dependencyVersion = dependencies[ dependencyName ];
if (
!dependencyName.startsWith( '@ckeditor/ckeditor5' ) &&
!dependencyVersion.includes( 'cksource/ckeditor' )
) {
continue;
}
if ( dependencyName.includes( '/ckeditor5-dev' ) ) {
continue;
}
if ( isHashedDependency( dependencyVersion ) ) {
mgitJson.dependencies[ dependencyName ] = dependencyVersion;
} else {
// Removes '@' from the scoped npm package name.
mgitJson.dependencies[ dependencyName ] = dependencyName.slice( 1 );
}
}
return mgitJson;
};
function isHashedDependency( dependency ) {
return dependency.match( /#[0-9a-f]+$/ );
}