Skip to content

Commit b9c61ea

Browse files
romanrostislavovichxferra
authored andcommitted
feat: add a command to update license.spdx and language.linguist schemas
added next gulp commands: - `import-licenses` - import licenses of spdx to `license.spdx` schema - `import-languages` - import languages of linguist to `language.linguist` schema - `pull-submodules` - update git submodules `spdx` and `linguist` added gulp series commands: - `import` - included: `pull-submodules`, `import-licenses` and `import-languages` added npm command: - `import` - it's command `gulp import` Closes #11
1 parent e6b451d commit b9c61ea

File tree

9 files changed

+181
-9
lines changed

9 files changed

+181
-9
lines changed

gulpfile.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Set global shared core
2+
const lhcore = require('./script/gulp/index.js');
3+
global.lhcore = lhcore;
4+
5+
// External modules as aliases
6+
const gulp = lhcore.amd.gulp;
7+
const hubRegistry = lhcore.amd.hubRegistry;
8+
9+
// Load tasks into the registry of gulp
10+
hubRegistry([
11+
'script/gulp/**/task.*.js',
12+
]);
13+
14+
gulp.task('default', gulp.series('import'));
15+
gulp.task('import', gulp.series('pull-submodules', 'import'));

package.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
{
2-
"name": "linterhub.schema",
2+
"name": "schema",
33
"version": "1.0.0",
44
"description": "JSON schemas for linterhub",
5+
"scripts": {
6+
"gulp": "./node_modules/gulp/bin/gulp.js",
7+
"import": "gulp import"
8+
},
59
"repository": {
610
"type": "git",
711
"url": "https://github.com/linterhub/schema.git"
812
},
913
"author": "linterhub",
1014
"license": "MIT",
1115
"homepage": "https://schema.linterhub.com",
16+
"devDependencies": {
17+
"gulp": "github:gulpjs/gulp#4.0",
18+
"gulp-data": "^1.3.1",
19+
"gulp-git": "^2.7.0",
20+
"gulp-hub": "^0.8.0",
21+
"gulp-json-format": "^2.0.0",
22+
"gulp-json-schema": "^1.0.0",
23+
"js-yaml": "^3.12.0"
24+
},
1225
"bugs": {
1326
"url": "https://github.com/linterhub/schema/issues"
1427
}

script/gulp/config.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"template": {
3+
"linguist": "src/template/language.linguist.json",
4+
"spdx": "src/template/license.spdx.json"
5+
},
6+
"collection": {
7+
"dir": "src/collection/",
8+
"licenses": {
9+
"spdx": "src/collection/license.spdx.json"
10+
},
11+
"languages": {
12+
"linguist": "src/collection/language.linguist.json"
13+
}
14+
},
15+
"ext": {
16+
"linguist": "ext/github/linguist/lib/linguist/languages.yml",
17+
"spdx": "ext/spdx/license-list-data/json/licenses.json"
18+
}
19+
}

script/gulp/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Shared conffguration
2+
const cfg = require('./config.json');
3+
4+
// Shared node modules
5+
const amd = {
6+
fs: require('fs'),
7+
git: require('gulp-git'),
8+
yaml: require('js-yaml'),
9+
gulp: require('gulp'),
10+
hubRegistry: require('gulp-hub'),
11+
jsonData: require('gulp-data'),
12+
jsonFormat: require('gulp-json-format'),
13+
jsonSchema: require('gulp-json-schema'),
14+
};
15+
16+
// Shared functions
17+
const fnc = {
18+
readJson: (path) => JSON.parse(amd.fs.readFileSync(path)),
19+
readYaml: (path) => amd.yaml.safeLoad(amd.fs.readFileSync(path)),
20+
jsonToBuffer: (json) => Buffer.from(JSON.stringify(json), 'utf8'),
21+
};
22+
23+
// Exported shared config, modules and functons
24+
exports = module.exports = {
25+
cfg: cfg,
26+
amd: amd,
27+
fnc: fnc,
28+
};

script/gulp/task.git.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
// Get shared core
4+
const core = global.lhcore;
5+
6+
// External modules as aliases
7+
const gulp = core.amd.gulp;
8+
const git = core.amd.git;
9+
10+
// Update gt submodules
11+
const pullSubmodules = () => git.updateSubmodule({args: '--init'});
12+
13+
// Tasks
14+
gulp.task('pull-submodules', pullSubmodules);

script/gulp/task.import.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'use strict';
2+
3+
// Get shared core
4+
const core = global.lhcore;
5+
6+
// External modules as aliases
7+
const gulp = core.amd.gulp;
8+
const jsonData = core.amd.jsonData;
9+
const jsonFormat = core.amd.jsonFormat;
10+
const config = core.cfg;
11+
12+
// Externall functions as aliases
13+
const readJson = core.fnc.readJson;
14+
const readYaml = core.fnc.readYaml;
15+
const toBuffer = core.fnc.jsonToBuffer;
16+
17+
// Import licenses from spdx
18+
const importLicenses = () => gulp
19+
.src(config.template.spdx)
20+
.pipe(jsonData((file) => {
21+
const list = readJson(config.ext.spdx);
22+
const template = readJson(file.path);
23+
template.enum = list.licenses.map((l) => l.licenseId);
24+
file.contents = toBuffer(template);
25+
return file;
26+
}))
27+
.pipe(jsonFormat(4))
28+
.pipe(gulp.dest(config.collection.dir));
29+
30+
// Import languages from linguist
31+
const importLanguages = () => gulp
32+
.src(config.template.linguist)
33+
.pipe(jsonData((file) => {
34+
const list = readYaml(config.ext.linguist);
35+
const template = readJson(file.path);
36+
const names = Object.keys(list);
37+
template.definitions.language.oneOf = names.map((name) => {
38+
const item = list[name];
39+
const language = {
40+
enum: [name],
41+
};
42+
if (item.extensions && item.extensions.length) {
43+
language.extensions = item.extensions;
44+
}
45+
if (item.filenames && item.filenames.length) {
46+
language.filenames = item.filenames;
47+
}
48+
return language;
49+
});
50+
file.contents = toBuffer(template);
51+
return file;
52+
}))
53+
.pipe(jsonFormat(4))
54+
.pipe(gulp.dest(config.collection.dir));
55+
56+
// Tasks
57+
gulp.task('import-licenses', importLicenses);
58+
gulp.task('import-languages', importLanguages);
59+
gulp.task('import', gulp.parallel('import-licenses', 'import-languages'));

src/collection/language.linguist.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3072,14 +3072,6 @@
30723072
".pod"
30733073
]
30743074
},
3075-
{
3076-
"enum": [
3077-
"Pod 6"
3078-
],
3079-
"extensions": [
3080-
".pod"
3081-
]
3082-
},
30833075
{
30843076
"enum": [
30853077
"PogoScript"

src/template/language.linguist.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-06/schema#",
3+
"title": "Collection: programming language and extension",
4+
"description": "The set of programming languages and associated file extensions imported from linguist project",
5+
"type": "string",
6+
"oneOf": [
7+
{
8+
"$ref": "#/definitions/language"
9+
}
10+
],
11+
"additionalItems": false,
12+
"definitions": {
13+
"language": {
14+
"title": "Language",
15+
"description": "The programming language name",
16+
"type": "string",
17+
"oneOf": [
18+
{}
19+
]
20+
}
21+
}
22+
}

src/template/license.spdx.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-06/schema#",
3+
"title": "Collection: software license",
4+
"description": "The set of identifiers of software licenses imported from SPDX catalog",
5+
"type": "string",
6+
"enum": [
7+
""
8+
],
9+
"additionalItems": false
10+
}

0 commit comments

Comments
 (0)