scriptwriter
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -1,6 +0,53 @@ | ||
- [x] check if https://github.com/sindresorhus/terminal-link works in the repl and what it opens | ||
- [ ] ansi-escape image | ||
- [ ] ansi-escape clear buffer | ||
- [ ] readme explain the _ variable | ||
- [x] give playbill descriptions (link to docs?) | ||
- [x] expose `prettier.format(code, { parser: 'babel' });` | ||
- [x] ansi-escape clear buffer command (.clearTerminal .clearScreen) | ||
- [x] slurp up commands | ||
- [x] check that the device string matches playwright | ||
- [ ] readme explain the \_ variable | ||
- [ ] custom scan command app can | ||
- scan using axe | ||
- post to github/jira issue (https://github.com/pksunkara/octonode) | ||
- create html report (or markdown?) | ||
## Questions | ||
- [ ] maybe add custom command to /examples folder | ||
- [ ] can https://github.com/sindresorhus/copy-text-to-clipboard put stuff in copy/paste buffer from inside browser? | ||
- [ ] see if https://github.com/miguelmota/terminal-tab can launch other terms (mac only) | ||
- similar cli https://github.com/mklement0/ttab | ||
- [x] can an axe run reporter send back enough data to grab screenshots of the target nodes? | ||
- YES: but axe-style selector for shadow and iframe will need to be parsed | ||
- [ ] solve for shadow | ||
- [ ] solve for iframe | ||
## Features | ||
- [ ] try https://github.com/bahmutov/term-to-html for "reports" | ||
- dep https://www.npmjs.com/package/ansi-to-html | ||
- [ ] https://www.npmjs.com/package/tempy for temp files | ||
- [ ] parse args to the repl commands | ||
- https://www.npmjs.com/package/yargs-parser | ||
- https://www.npmjs.com/package/minimist-options | ||
- [ ] put command results on context variable | ||
- [ ] schema stuff | ||
- https://github.com/quicktype/quicktype | ||
- https://www.npmjs.com/package/ajv | ||
- http://schemastore.org/json/ | ||
- [ ] query language for json/pojo | ||
- https://www.npmjs.com/package/cssauron requires wrapping everything (not homogenous but limited) to get child/parent | ||
- https://www.npmjs.com/package/jsonpath | ||
- https://www.npmjs.com/package/ld-query for json-ld data | ||
- https://github.com/FGRibreau/jq.node lodash + jq | ||
- https://github.com/sanack/node-jq jq wrapper (may need https://remysharp.com/drafts/jq-recipes) | ||
- https://github.com/Siderite/LInQer chaining syntax | ||
- https://github.com/npm/treeverse walk any tree | ||
- https://github.com/anywhichway/doxl graphQL-like query | ||
- https://github.com/jwadhams/json-logic-js/ matchers with operators | ||
- [ ] diffing | ||
- https://github.com/zerkalica/modern-diff | ||
- https://github.com/automerge/automerge (also persistance?) | ||
- https://github.com/Starcounter-Jack/JSON-Patch | ||
- https://github.com/intelie/immutable-js-patch | ||
- https://github.com/typicode/lowdb (also persistance) | ||
- [ ] persistance | ||
- https://github.com/typicode/lowdb | ||
- https://github.com/automerge/automerge (?) | ||
- https://github.com/lukechilds/keyv |
@@ -1,1 +0,1 @@ | ||
{"processes":{"41f28406-bb6f-49c3-8a44-7ef6c8df48e5":{"parent":null,"children":["794327b9-f044-40e4-9563-01f395ee4ff4"]},"794327b9-f044-40e4-9563-01f395ee4ff4":{"parent":"41f28406-bb6f-49c3-8a44-7ef6c8df48e5","children":[]}},"files":{"/Users/paul.grenier/Git/scriptwriter/lib/scriptwriter.js":["794327b9-f044-40e4-9563-01f395ee4ff4"],"/Users/paul.grenier/Git/scriptwriter/lib/events/director.enter.js":["794327b9-f044-40e4-9563-01f395ee4ff4"],"/Users/paul.grenier/Git/scriptwriter/lib/events/director.exit.js":["794327b9-f044-40e4-9563-01f395ee4ff4"],"/Users/paul.grenier/Git/scriptwriter/lib/events/director.reset.js":["794327b9-f044-40e4-9563-01f395ee4ff4"],"/Users/paul.grenier/Git/scriptwriter/lib/events/browser.enter.js":["794327b9-f044-40e4-9563-01f395ee4ff4"],"/Users/paul.grenier/Git/scriptwriter/lib/events/context.enter.js":["794327b9-f044-40e4-9563-01f395ee4ff4"],"/Users/paul.grenier/Git/scriptwriter/lib/events/page.load.js":["794327b9-f044-40e4-9563-01f395ee4ff4"],"/Users/paul.grenier/Git/scriptwriter/lib/events/client.enter.js":["794327b9-f044-40e4-9563-01f395ee4ff4"]},"externalIds":{}} | ||
{"processes":{"0f17c331-1ea3-40cf-bf69-c5ee513afc01":{"parent":null,"children":["12b50094-4c09-4e74-a16f-94a7e709c62c","ae524720-4447-4ef2-bbe5-00239c48b266","f3a01a24-4dba-4161-b373-4363addd19d9"]},"12b50094-4c09-4e74-a16f-94a7e709c62c":{"parent":"0f17c331-1ea3-40cf-bf69-c5ee513afc01","children":[]},"ae524720-4447-4ef2-bbe5-00239c48b266":{"parent":"0f17c331-1ea3-40cf-bf69-c5ee513afc01","children":[]},"f3a01a24-4dba-4161-b373-4363addd19d9":{"parent":"0f17c331-1ea3-40cf-bf69-c5ee513afc01","children":[]}},"files":{"/Users/paul.grenier/Git/scriptwriter/lib/scriptwriter.js":["12b50094-4c09-4e74-a16f-94a7e709c62c","ae524720-4447-4ef2-bbe5-00239c48b266","f3a01a24-4dba-4161-b373-4363addd19d9"],"/Users/paul.grenier/Git/scriptwriter/lib/events/director.enter.js":["12b50094-4c09-4e74-a16f-94a7e709c62c"],"/Users/paul.grenier/Git/scriptwriter/lib/events/director.exit.js":["12b50094-4c09-4e74-a16f-94a7e709c62c"],"/Users/paul.grenier/Git/scriptwriter/lib/events/director.reset.js":["12b50094-4c09-4e74-a16f-94a7e709c62c"],"/Users/paul.grenier/Git/scriptwriter/lib/commands/clear-screen.js":["12b50094-4c09-4e74-a16f-94a7e709c62c","f3a01a24-4dba-4161-b373-4363addd19d9"],"/Users/paul.grenier/Git/scriptwriter/lib/commands/clear-terminal.js":["12b50094-4c09-4e74-a16f-94a7e709c62c","ae524720-4447-4ef2-bbe5-00239c48b266"],"/Users/paul.grenier/Git/scriptwriter/lib/commands/playbill.js":["12b50094-4c09-4e74-a16f-94a7e709c62c"],"/Users/paul.grenier/Git/scriptwriter/lib/events/browser.enter.js":["12b50094-4c09-4e74-a16f-94a7e709c62c"],"/Users/paul.grenier/Git/scriptwriter/lib/events/context.enter.js":["12b50094-4c09-4e74-a16f-94a7e709c62c"],"/Users/paul.grenier/Git/scriptwriter/lib/events/page.load.js":["12b50094-4c09-4e74-a16f-94a7e709c62c"],"/Users/paul.grenier/Git/scriptwriter/lib/events/client.enter.js":["12b50094-4c09-4e74-a16f-94a7e709c62c"]},"externalIds":{}} |
@@ -8,2 +8,3 @@ module.exports = async function (scriptwriter) { | ||
]); | ||
scriptwriter.emit('ready', 'client'); | ||
}; |
module.exports = async function (scriptwriter) { | ||
const { context } = scriptwriter.company; | ||
try { | ||
const page = await context.newPage(); | ||
scriptwriter.assign({ page }); | ||
if (context.newCDPSession) { | ||
const client = await context.newCDPSession(page); | ||
scriptwriter.assign({ client }); | ||
} | ||
} catch (err) { | ||
scriptwriter.log(err); | ||
const page = await context.newPage(); | ||
await scriptwriter.assign({ page }); | ||
/* istanbul ignore next */ | ||
if (context.newCDPSession) { | ||
const client = await context.newCDPSession(page); | ||
await scriptwriter.assign({ client }); | ||
} | ||
scriptwriter.emit('ready', 'context'); | ||
}; |
@@ -1,78 +0,9 @@ | ||
const dlv = require('dlv'); | ||
const link = require('terminal-link'); | ||
const PLAYBILL = 'playbill'; | ||
const COMMAND_PLAYBILL = `.${PLAYBILL}`; | ||
module.exports = function (scriptwriter) { | ||
module.exports = async function (scriptwriter) { | ||
const { director } = scriptwriter.company; | ||
const { magenta } = scriptwriter.color; | ||
scriptwriter.assign({ scriptwriter }); | ||
if (!director.commands.playbill) { | ||
scriptwriter.log(magenta('.help for help. Tab twice for hints.')); | ||
} | ||
await scriptwriter.defineCommands(); | ||
director.displayPrompt(); | ||
/* istanbul ignore if */ | ||
if (dlv(scriptwriter, `director.commands.${PLAYBILL}`)) return; | ||
scriptwriter.log(magenta('.help for help. Tab twice for hints.')); | ||
scriptwriter.completion = COMMAND_PLAYBILL; | ||
director.defineCommand(PLAYBILL, { | ||
help: `List the scriptwriter's ${PLAYBILL}`, | ||
action() { | ||
const credits = Object.keys(scriptwriter.company).sort(); | ||
const maxLength = Math.max(...credits.map((c) => c.length)) + 2; | ||
scriptwriter.log( | ||
credits | ||
.map((c) => | ||
[ | ||
getLink(c), | ||
' '.repeat(maxLength - c.length), | ||
getDescription(c), | ||
].join('') | ||
) | ||
.join('\n') | ||
); | ||
director.displayPrompt(); | ||
}, | ||
}); | ||
function getLink(name) { | ||
const PLAYWRIGHT_API = | ||
'https://github.com/microsoft/playwright/blob/v0.12.1/docs/api.md'; | ||
switch (name) { | ||
case 'page': | ||
case 'browser': | ||
return link(name, `${PLAYWRIGHT_API}#class-${name}`); | ||
case 'client': | ||
return link( | ||
name, | ||
'https://chromedevtools.github.io/devtools-protocol/' | ||
); | ||
case 'context': | ||
return link(name, `${PLAYWRIGHT_API}#class-browser${name}`); | ||
case 'director': | ||
return link(name, 'https://nodejs.org/api/repl.html'); | ||
case 'playwright': | ||
return link(name, PLAYWRIGHT_API); | ||
case 'scriptwriter': | ||
return link(name, 'https://github.com/AutoSponge/scriptwriter#readme'); | ||
default: | ||
} | ||
} | ||
function getDescription(name) { | ||
switch (name) { | ||
case 'page': | ||
return `Playwright's Page instance for the browser's context.`; | ||
case 'browser': | ||
return `Playwright's Browser instance.`; | ||
case 'client': | ||
return `Playwritght's CDPSession instance (Chrome only).`; | ||
case 'context': | ||
return `Playwright's BrowserContext instance for the browser.`; | ||
case 'director': | ||
return `Node's repl instance.`; | ||
case 'playwright': | ||
return `Playwright object.`; | ||
case 'scriptwriter': | ||
return `The instance object that controls the director.`; | ||
default: | ||
} | ||
} | ||
}; |
@@ -15,3 +15,3 @@ const EventEmitter = require('events'); | ||
const EVENTS_PATH = resolve(__dirname, 'events'); | ||
const EVENTS_DIR = readdir(EVENTS_PATH); | ||
const COMMANDS_PATH = resolve(__dirname, 'commands'); | ||
const EVENT_ASSIGN = 'assign'; | ||
@@ -51,2 +51,5 @@ const EVENT_ENTER = 'enter'; | ||
super(); | ||
console.log(); | ||
const { device } = initialConfig; | ||
device && assert(playwright.devices[device], `unknown device "${device}".`); | ||
Object.entries(initialConfig).map(([k, v]) => config.set(k, v)); | ||
@@ -112,3 +115,3 @@ this.log = this.log.bind(this); | ||
if (!assigned.emit) return; | ||
const listings = await EVENTS_DIR; | ||
const listings = await readdir(EVENTS_PATH); | ||
for (const list of listings) { | ||
@@ -120,2 +123,3 @@ /* istanbul ignore if */ | ||
const file = resolve(EVENTS_PATH, list); | ||
delete require.cache[file]; | ||
const handler = require(file); | ||
@@ -128,2 +132,17 @@ const handle = handler.bind(null, this); | ||
/** | ||
* loads commands from folder | ||
*/ | ||
async defineCommands() { | ||
const listings = await readdir(COMMANDS_PATH); | ||
for (const list of listings) { | ||
/* istanbul ignore if */ | ||
if (list.endsWith('.test.js')) continue; | ||
const file = resolve(COMMANDS_PATH, list); | ||
delete require.cache[file]; | ||
const { command, name } = require(file); | ||
this.completion = `.${name}`; | ||
this.replServer.defineCommand(name, command); | ||
} | ||
} | ||
/** | ||
* Resets company and completions. | ||
@@ -151,5 +170,7 @@ * Recycles the replServer. | ||
await this.assign({ director }); | ||
await this.assign({ scriptwriter: this }); | ||
const { browserType, launch } = this.config; | ||
const browser = await playwright[browserType].launch(launch); | ||
await this.assign({ playwright, browser }); | ||
await this.assign({ playwright }); | ||
await this.assign({ browser }); | ||
director.displayPrompt(); | ||
@@ -156,0 +177,0 @@ } |
@@ -27,14 +27,9 @@ const test = require('ava'); | ||
t.is(scriptwriter.replServer, null); | ||
let directorReady = waitFor(scriptwriter, 'assign', ['director']); | ||
let allReady = waitFor(scriptwriter, 'ready', ['client']); | ||
await scriptwriter.init(); | ||
await directorReady; | ||
await allReady; | ||
const replServer = scriptwriter.company.director; | ||
replServer.close(); | ||
directorReady = waitFor(scriptwriter, 'assign', ['director']); | ||
await scriptwriter.init(); | ||
await directorReady; | ||
t.is(replServer, scriptwriter.company.director); | ||
directorReady = waitFor(scriptwriter, 'assign', ['director']); | ||
allReady = waitFor(scriptwriter, 'ready', ['client']); | ||
replServer.resetContext(); | ||
await directorReady; | ||
await allReady; | ||
t.is(replServer, scriptwriter.company.director); | ||
@@ -47,6 +42,6 @@ scriptwriter.company.director.close(); | ||
await scriptwriter.init(); | ||
const pageReady = waitFor(scriptwriter, 'assign', ['page']); | ||
let allReady = waitFor(scriptwriter, 'ready', ['client']); | ||
const initalPrompt = scriptwriter.company.director._prompt; | ||
t.is(initalPrompt, '> '); | ||
await pageReady; | ||
await allReady; | ||
const { page } = scriptwriter.company; | ||
@@ -62,5 +57,5 @@ const loaded = waitFor(page, 'load'); | ||
const scriptwriter = new Scriptwriter(); | ||
const clientReady = waitFor(scriptwriter, 'assign', ['client']); | ||
let allReady = waitFor(scriptwriter, 'ready', ['client']); | ||
await scriptwriter.init(); | ||
await clientReady; | ||
await allReady; | ||
t.truthy(scriptwriter.company.client); | ||
@@ -72,5 +67,5 @@ scriptwriter.company.director.close(); | ||
const scriptwriter = new Scriptwriter(); | ||
const clientReady = waitFor(scriptwriter, 'assign', ['client']); | ||
let allReady = waitFor(scriptwriter, 'ready', ['client']); | ||
await scriptwriter.init(); | ||
await clientReady; | ||
await allReady; | ||
const { commands } = scriptwriter.company.director; | ||
@@ -80,3 +75,3 @@ t.truthy(commands.playbill); | ||
const log = waitFor(scriptwriter, 'log'); | ||
director.commands.playbill.action(); | ||
director.commands.playbill.action.call(director); | ||
const [args] = await log; | ||
@@ -100,5 +95,5 @@ const [msg] = args; | ||
const scriptwriter = new Scriptwriter(); | ||
const clientReady = waitFor(scriptwriter, 'assign', ['client']); | ||
let allReady = waitFor(scriptwriter, 'ready', ['client']); | ||
await scriptwriter.init(); | ||
await clientReady; | ||
await allReady; | ||
t.deepEqual( | ||
@@ -146,15 +141,4 @@ scriptwriter.completer('client.o'), | ||
t.deepEqual( | ||
scriptwriter.completer('director.commands.'), | ||
[ | ||
[ | ||
'director.commands.break', | ||
'director.commands.clear', | ||
'director.commands.exit', | ||
'director.commands.help', | ||
'director.commands.load', | ||
'director.commands.playbill', | ||
'director.commands.save', | ||
], | ||
'director.commands.', | ||
], | ||
scriptwriter.completer('director.commands.play'), | ||
[['director.commands.playbill'], 'director.commands.play'], | ||
'handles null prototype objects' | ||
@@ -161,0 +145,0 @@ ); |
{ | ||
"name": "scriptwriter", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "✍️ An authoring tool for playwrights.", | ||
@@ -26,2 +26,3 @@ "keywords": [ | ||
"start": "$npm_package_bin_scriptwriter", | ||
"test:dev": "cross-env NODE_ENV=test ava", | ||
"test": "cross-env NODE_ENV=test nyc ava", | ||
@@ -28,0 +29,0 @@ "cover": "nyc report --reporter=html" |
1787013
76
3961
7