Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
Start #129, create a rough lexicon of commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ianb committed Oct 3, 2019
1 parent f91dddc commit 82d4877
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
extension/js/vendor/
extension/css/vendor/
extension/views/CHANGELOG.html
extension/views/lexicon.html
extension/buildSettings.js
node_modules
npm-debug.log
Expand Down
44 changes: 37 additions & 7 deletions bin/substitute-changelog.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
const ejs = require("ejs");
const path = require("path");
const fs = require("fs");
const { markdown } = require("markdown");
const MarkdownIt = require("markdown-it");

const markdown = new MarkdownIt({
html: true,
breaks: true,
typographer: true,
});

const CHANGELOG = path.normalize(path.join(__dirname, "../CHANGELOG.md"));
const OUTPUT = path.normalize(
const CHANGELOG_OUTPUT = path.normalize(
path.join(__dirname, "../extension/views/CHANGELOG.html")
);
const TEMPLATE = OUTPUT + ".ejs";
const CHANGELOG_TEMPLATE = CHANGELOG_OUTPUT + ".ejs";
const CHANGELOG_TEXT = fs.readFileSync(CHANGELOG, { encoding: "UTF-8" });

const context = { content: markdown.toHTML(CHANGELOG_TEXT) };
const context = { content: markdown.render(CHANGELOG_TEXT) };

ejs.renderFile(TEMPLATE, context, {}, function(err, str) {
ejs.renderFile(CHANGELOG_TEMPLATE, context, {}, function(err, str) {
if (err) {
console.error("Error rendering template:", err);
process.exit(1);
return;
}
fs.writeFileSync(OUTPUT, str, { encoding: "UTF-8" });
console.log(`${OUTPUT} written`);
fs.writeFileSync(CHANGELOG_OUTPUT, str, { encoding: "UTF-8" });
console.log(`${CHANGELOG_OUTPUT} written`);
});

const LEXICON = path.normalize(path.join(__dirname, "../docs/lexicon.md"));
const LEXICON_OUTPUT = path.normalize(
path.join(__dirname, "../extension/views/lexicon.html")
);
const LEXICON_TEMPLATE = LEXICON_OUTPUT + ".ejs";
const LEXICON_TEXT = fs.readFileSync(LEXICON, { encoding: "UTF-8" });

const lexiconContext = { content: markdown.render(LEXICON_TEXT) };

ejs.renderFile(
LEXICON_TEMPLATE,
lexiconContext,
{ dialect: "maruku" },
function(err, str) {
if (err) {
console.error("Error rendering template:", err);
process.exit(1);
return;
}
fs.writeFileSync(LEXICON_OUTPUT, str, { encoding: "UTF-8" });
console.log(`${LEXICON_OUTPUT} written`);
}
);
32 changes: 32 additions & 0 deletions docs/lexicon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!-- See the bottom of this page for information on how to update this -->

# Search the web

Returns results from the default search engine.

**Example**

_Search for hiking in Denver_

# Website specific search

Returns results from search feature on a specific website.

> **Example**
>
> _Search my Gmail for tickets to Hamilton_
> _Lookup The Book Of Thief on GoodReads_
> _Find HTML on MDN_
>
> **Supported sites:** Gmail, Google Calendar/Docs, MDN, GoodReads, Spotify, Amazon, Wikipedia, Yelp, Twitter, Reddit.
<!--
Updating this file:
- This is a Markdown file, using Common Mark: https://commonmark.org
- Say "help" to open this file in the browser
- To regenerate the lexicon.html file: `npm run build:markdown`
- You can use `npm run build:markdown` and then reload the page in the extension
-->
12 changes: 0 additions & 12 deletions extension/intents/navigation/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,4 @@ this.intents.navigation = (function() {
});
},
});

this.intentRunner.registerIntent({
name: "navigation.cancelIntent",
match: `
cancel
nevermind
never mind
`,
async run(context) {
context.done(0);
},
});
})();
28 changes: 28 additions & 0 deletions extension/intents/self/self.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
this.intents.read = (function() {
this.intentRunner.registerIntent({
name: "self.cancelIntent",
match: `
cancel
nevermind
never mind
`,
async run(context) {
context.done(0);
},
});

this.intentRunner.registerIntent({
name: "self.openLexicon",
examples: ["Tell me about Firefox Voice", "Help", "What can I do?"],
match: `
tell me about (this | firefox voice | this extension | voice)
help
what can I do
`,
async run(context) {
await browser.tabs.create({
url: browser.runtime.getURL("/views/lexicon.html"),
});
},
});
})();
20 changes: 20 additions & 0 deletions extension/views/lexicon.html.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Firefox Voice Changes and Updates</title>
<!-- <link rel="stylesheet" href="../css/vendor/tailwind.min.css" /> -->
</head>
<body>
<h1>Firefox Voice Commands</h1>

<div id="contents">
<%- content %>
</div>

<footer>
For more information on Firefox Voice see our
<a href="https://github.com/mozilla/firefox-voice">GitHub repository</a>.
</footer>
</body>
</html>
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"eslint-plugin-no-unsanitized": "^3.0.2",
"eslint-plugin-prettier": "^3.1.0",
"htmllint-cli": "0.0.7",
"markdown": "^0.5.0",
"markdown-it": "^10.0.0",
"npm-run-all": "^4.1.3",
"prettier": "1.18.2",
"prettier-linter-helpers": "^1.0.0",
Expand All @@ -45,13 +45,14 @@
"url": "git+https://github.com/mozilla/firefox-voice.git"
},
"scripts": {
"start": "NO_SENTRY=1 npm-run-all maybeinstall build:manifest start-extension",
"start": "NO_SENTRY=1 npm-run-all maybeinstall maybemarkdown build:manifest start-extension",
"start-extension": "mkdir -p ${PROFILE:-Profile} && web-ext run --firefox-profile ${PROFILE:-Profile}/ --keep-profile-changes --firefox \"${FIREFOX:-nightly}\" --source-dir extension/ --browser-console",
"test": "npm-run-all build:manifest lint*",
"build:changelog": "mkdir -p extension/views && node bin/substitute-changelog.js",
"build:markdown": "mkdir -p extension/views && node bin/substitute-changelog.js",
"build:deps": "mkdir -p extension/js/vendor/ extension/css/vendor/ ; for file in lottie-web/build/player/lottie.min.js webextension-polyfill/dist/browser-polyfill.min.js moment/min/moment.min.js fuse.js/dist/fuse.js raven-js/dist/raven.js ; do cp node_modules/$file extension/js/vendor/ ; done ; for file in tailwindcss/dist/tailwind.min.css ; do cp node_modules/$file extension/css/vendor/ ; done ; cp \"node_modules/@sentry/browser/build/bundle.es6.min.js\" extension/js/vendor/sentry.js",
"build:manifest": "node bin/substitute-manifest.js",
"maybeinstall": "if [[ package.json -nt node_modules/last_install.txt ]] ; then npm install && touch node_modules/last_install.txt ; fi",
"maybemarkdown": "if [[ docs/lexicon.md -nt extension/views/lexicon.html ]] ; then npm run build:markdown ; fi",
"format": "prettier 'extension/**/*.{js,css}' --write",
"lint": "npm-run-all lint:*",
"lint:css": "stylelint 'extension/**/*.css'",
Expand Down

0 comments on commit 82d4877

Please sign in to comment.