#5 - Updated to the js yaml core schema + indent array support

This commit is contained in:
Elio Struyf
2019-09-17 14:54:23 +02:00
parent 1b9f07ec2d
commit db043cf794
7 changed files with 93 additions and 40 deletions
+53 -17
View File
@@ -41,6 +41,12 @@
"@types/node": "*"
}
},
"@types/js-yaml": {
"version": "3.12.1",
"resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-3.12.1.tgz",
"integrity": "sha512-SGGAhXLHDx+PK4YLNcNGa6goPf9XRWQNAUUbffkwVGGXIxmDKWyGGL4inzq2sPmExu431Ekb9aEMn9BkPqEYFA==",
"dev": true
},
"@types/minimatch": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz",
@@ -344,6 +350,7 @@
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
"dev": true,
"requires": {
"sprintf-js": "~1.0.2"
}
@@ -998,7 +1005,8 @@
"date-fns": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.0.1.tgz",
"integrity": "sha512-C14oTzTZy8DH1Eq8N78owrCWvf3+cnJw88BTK/N3DYWVxDJuJzPaNdplzYxDYuuXXGvqBcO4Vy5SOrwAooXSWw=="
"integrity": "sha512-C14oTzTZy8DH1Eq8N78owrCWvf3+cnJw88BTK/N3DYWVxDJuJzPaNdplzYxDYuuXXGvqBcO4Vy5SOrwAooXSWw==",
"dev": true
},
"date-now": {
"version": "0.1.4",
@@ -1243,7 +1251,8 @@
"esprima": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
"dev": true
},
"esrecurse": {
"version": "4.2.1",
@@ -1351,6 +1360,7 @@
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz",
"integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=",
"dev": true,
"requires": {
"is-extendable": "^0.1.0"
}
@@ -1555,7 +1565,8 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"aproba": {
"version": "1.2.0",
@@ -1576,12 +1587,14 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@@ -1596,17 +1609,20 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"core-util-is": {
"version": "1.0.2",
@@ -1723,7 +1739,8 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"ini": {
"version": "1.3.5",
@@ -1735,6 +1752,7 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@@ -1749,6 +1767,7 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@@ -1756,12 +1775,14 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@@ -1780,6 +1801,7 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@@ -1860,7 +1882,8 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"object-assign": {
"version": "4.1.1",
@@ -1872,6 +1895,7 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@@ -1957,7 +1981,8 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"safer-buffer": {
"version": "2.1.2",
@@ -1993,6 +2018,7 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@@ -2012,6 +2038,7 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@@ -2055,12 +2082,14 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
"dev": true
"dev": true,
"optional": true
}
}
},
@@ -2171,6 +2200,7 @@
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/gray-matter/-/gray-matter-4.0.2.tgz",
"integrity": "sha512-7hB/+LxrOjq/dd8APlK0r24uL/67w7SkYnfwhNFwg/VDIGWGmduTDYf3WNstLW2fbbmRwrDGCVSJ2isuf2+4Hw==",
"dev": true,
"requires": {
"js-yaml": "^3.11.0",
"kind-of": "^6.0.2",
@@ -2501,7 +2531,8 @@
"is-extendable": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-0.1.1.tgz",
"integrity": "sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik="
"integrity": "sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik=",
"dev": true
},
"is-extglob": {
"version": "2.1.1",
@@ -2623,6 +2654,7 @@
"version": "3.13.1",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz",
"integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==",
"dev": true,
"requires": {
"argparse": "^1.0.7",
"esprima": "^4.0.0"
@@ -2660,7 +2692,8 @@
"kind-of": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA=="
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
"dev": true
},
"lcid": {
"version": "2.0.0",
@@ -3711,6 +3744,7 @@
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/section-matter/-/section-matter-1.0.0.tgz",
"integrity": "sha512-vfD3pmTzGpufjScBh50YHKzEu2lxBWhVEHsNGoEXmCmn2hKGfeNLYMzCJpe8cD7gqX7TJluOVpBkAequ6dgMmA==",
"dev": true,
"requires": {
"extend-shallow": "^2.0.1",
"kind-of": "^6.0.0"
@@ -3984,7 +4018,8 @@
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
"dev": true
},
"ssri": {
"version": "6.0.1",
@@ -4086,7 +4121,8 @@
"strip-bom-string": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/strip-bom-string/-/strip-bom-string-1.0.0.tgz",
"integrity": "sha1-5SEekiQ2n7uB1jOi8ABE3IztrZI="
"integrity": "sha1-5SEekiQ2n7uB1jOi8ABE3IztrZI=",
"dev": true
},
"strip-eof": {
"version": "1.0.0",
+9 -3
View File
@@ -71,6 +71,11 @@
"frontMatter.taxonomy.slugSuffix": {
"type": "string",
"markdownDescription": "Specify a suffix for the slug"
},
"frontMatter.taxonomy.indentArrays": {
"type": "boolean",
"default": true,
"markdownDescription": "Specify if arrays in front matter are indented. Default is true."
}
}
},
@@ -117,19 +122,20 @@
},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/js-yaml": "3.12.1",
"@types/mocha": "^5.2.6",
"@types/node": "^10.12.21",
"@types/vscode": "^1.37.0",
"date-fns": "2.0.1",
"glob": "^7.1.4",
"gray-matter": "4.0.2",
"mocha": "^6.1.4",
"ts-loader": "^6.0.4",
"tslint": "^5.12.1",
"typescript": "^3.3.1",
"vscode-test": "^1.0.2",
"webpack": "^4.39.2",
"webpack-cli": "^3.3.7",
"date-fns": "2.0.1",
"gray-matter": "4.0.2"
"webpack-cli": "^3.3.7"
},
"dependencies": {}
}
+5 -5
View File
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import { TaxonomyType } from "../models";
import { CONFIG_KEY, ACTION_TAXONOMY_TAGS, ACTION_TAXONOMY_CATEGORIES, ACTION_DATE_FORMAT, EXTENSION_NAME, ACTION_SLUG_PREFIX, ACTION_SLUG_SUFFIX } from "../constants/settings";
import { CONFIG_KEY, SETTING_DATE_FORMAT, EXTENSION_NAME, SETTING_SLUG_PREFIX, SETTING_SLUG_SUFFIX } from "../constants/settings";
import { format } from "date-fns";
import { ArticleHelper, SettingsHelper } from '../helpers';
@@ -82,7 +82,7 @@ export class Article {
return;
}
const dateFormat = config.get(ACTION_DATE_FORMAT) as string;
const dateFormat = config.get(SETTING_DATE_FORMAT) as string;
try {
if (dateFormat && typeof dateFormat === "string") {
article.data["date"] = format(new Date(), dateFormat);
@@ -92,7 +92,7 @@ export class Article {
ArticleHelper.update(editor, article);
} catch (e) {
vscode.window.showErrorMessage(`${EXTENSION_NAME}: Something failed while parsing the date format. Check your "${CONFIG_KEY}${ACTION_DATE_FORMAT}" setting.`);
vscode.window.showErrorMessage(`${EXTENSION_NAME}: Something failed while parsing the date format. Check your "${CONFIG_KEY}${SETTING_DATE_FORMAT}" setting.`);
console.log(e.message);
}
}
@@ -102,8 +102,8 @@ export class Article {
*/
public static generateSlug() {
const config = vscode.workspace.getConfiguration(CONFIG_KEY);
const prefix = config.get(ACTION_SLUG_PREFIX) as string;
const suffix = config.get(ACTION_SLUG_SUFFIX) as string;
const prefix = config.get(SETTING_SLUG_PREFIX) as string;
const suffix = config.get(SETTING_SLUG_SUFFIX) as string;
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
+6 -6
View File
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
import * as matter from 'gray-matter';
import * as fs from 'fs';
import { TaxonomyType } from "../models";
import { CONFIG_KEY, ACTION_TAXONOMY_TAGS, ACTION_TAXONOMY_CATEGORIES, EXTENSION_NAME } from '../constants';
import { CONFIG_KEY, SETTING_TAXONOMY_TAGS, SETTING_TAXONOMY_CATEGORIES, EXTENSION_NAME } from '../constants';
import { ArticleHelper, SettingsHelper, FilesHelper } from '../helpers';
export class Settings {
@@ -20,7 +20,7 @@ export class Settings {
if (newOption) {
const config = vscode.workspace.getConfiguration(CONFIG_KEY);
const configSetting = type === TaxonomyType.Tag ? ACTION_TAXONOMY_TAGS : ACTION_TAXONOMY_CATEGORIES;
const configSetting = type === TaxonomyType.Tag ? SETTING_TAXONOMY_TAGS : SETTING_TAXONOMY_CATEGORIES;
let options = config.get(configSetting) as string[];
if (!options) {
options = [];
@@ -118,22 +118,22 @@ export class Settings {
}
// Retrieve the currently known tags, and add the new ones
let crntTags: string[] = config.get(ACTION_TAXONOMY_TAGS) as string[];
let crntTags: string[] = config.get(SETTING_TAXONOMY_TAGS) as string[];
if (!crntTags) { crntTags = []; }
crntTags = [...crntTags, ...tags];
// Update the tags and filter out the duplicates
crntTags = [...new Set(crntTags)];
crntTags = crntTags.sort();
await config.update(ACTION_TAXONOMY_TAGS, crntTags);
await config.update(SETTING_TAXONOMY_TAGS, crntTags);
// Retrieve the currently known tags, and add the new ones
let crntCategories: string[] = config.get(ACTION_TAXONOMY_CATEGORIES) as string[];
let crntCategories: string[] = config.get(SETTING_TAXONOMY_CATEGORIES) as string[];
if (!crntCategories) { crntCategories = []; }
crntCategories = [...crntCategories, ...categories];
// Update the categories and filter out the duplicates
crntCategories = [...new Set(crntCategories)];
crntCategories = crntCategories.sort();
await config.update(ACTION_TAXONOMY_CATEGORIES, crntCategories);
await config.update(SETTING_TAXONOMY_CATEGORIES, crntCategories);
// Done
vscode.window.showInformationMessage(`${EXTENSION_NAME}: Export completed. Tags: ${crntTags.length} - Categories: ${crntCategories.length}.`);
+7 -5
View File
@@ -2,9 +2,11 @@ export const EXTENSION_NAME = "Front Matter";
export const CONFIG_KEY = "frontMatter";
export const ACTION_TAXONOMY_TAGS = "taxonomy.tags";
export const ACTION_TAXONOMY_CATEGORIES = "taxonomy.categories";
export const ACTION_DATE_FORMAT = "taxonomy.dateFormat";
export const SETTING_TAXONOMY_TAGS = "taxonomy.tags";
export const SETTING_TAXONOMY_CATEGORIES = "taxonomy.categories";
export const SETTING_DATE_FORMAT = "taxonomy.dateFormat";
export const ACTION_SLUG_PREFIX = "taxonomy.slugPrefix";
export const ACTION_SLUG_SUFFIX = "taxonomy.slugSuffix";
export const SETTING_SLUG_PREFIX = "taxonomy.slugPrefix";
export const SETTING_SLUG_SUFFIX = "taxonomy.slugSuffix";
export const SETTING_INDENT_ARRAY = "taxonomy.indentArrays";
+10 -1
View File
@@ -2,6 +2,8 @@ import * as vscode from 'vscode';
import * as matter from "gray-matter";
import { stopWords } from '../constants/stopwords-en';
import { charMap } from '../constants/charMap';
import { DEFAULT_SAFE_SCHEMA, CORE_SCHEMA, DumpOptions } from 'js-yaml';
import { CONFIG_KEY, SETTING_INDENT_ARRAY, SETTING_DATE_FORMAT } from '../constants';
export class ArticleHelper {
@@ -25,7 +27,14 @@ export class ArticleHelper {
* @param article
*/
public static async update(editor: vscode.TextEditor, article: matter.GrayMatterFile<string>) {
const newMarkdown = matter.stringify(article.content, article.data);
const config = vscode.workspace.getConfiguration(CONFIG_KEY);
const indentArray = config.get(SETTING_INDENT_ARRAY) as boolean;
const dateFormat = config.get(SETTING_DATE_FORMAT) as string;
const newMarkdown = matter.stringify(article.content, article.data, ({
schema: dateFormat ? CORE_SCHEMA : DEFAULT_SAFE_SCHEMA,
noArrayIndent: !indentArray
} as DumpOptions as any));
const nrOfLines = editor.document.lineCount as number;
await editor.edit(builder => builder.replace(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(nrOfLines, 0)), newMarkdown));
}
+3 -3
View File
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import { TaxonomyType } from '../models';
import { ACTION_TAXONOMY_TAGS, ACTION_TAXONOMY_CATEGORIES, CONFIG_KEY } from '../constants';
import { SETTING_TAXONOMY_TAGS, SETTING_TAXONOMY_CATEGORIES, CONFIG_KEY } from '../constants';
export class SettingsHelper {
@@ -12,7 +12,7 @@ export class SettingsHelper {
public static getTaxonomy(type: TaxonomyType): string[] {
const config = vscode.workspace.getConfiguration(CONFIG_KEY);
// Add all the known options to the selection list
const configSetting = type === TaxonomyType.Tag ? ACTION_TAXONOMY_TAGS : ACTION_TAXONOMY_CATEGORIES;
const configSetting = type === TaxonomyType.Tag ? SETTING_TAXONOMY_TAGS : SETTING_TAXONOMY_CATEGORIES;
const crntOptions = config.get(configSetting) as string[];
if (crntOptions && crntOptions.length > 0) {
return crntOptions;
@@ -29,7 +29,7 @@ export class SettingsHelper {
*/
static async update(type: TaxonomyType, options: string[]) {
const config = vscode.workspace.getConfiguration(CONFIG_KEY);
const configSetting = type === TaxonomyType.Tag ? ACTION_TAXONOMY_TAGS : ACTION_TAXONOMY_CATEGORIES;
const configSetting = type === TaxonomyType.Tag ? SETTING_TAXONOMY_TAGS : SETTING_TAXONOMY_CATEGORIES;
options = [...new Set(options)];
options = options.sort();
await config.update(configSetting, options);