diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-05-19 21:39:53 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-05-19 21:47:31 -0300 |
commit | 471de6e5ac73bd6c769a58392e3e49aff6d8f2cb (patch) | |
tree | 48cbdab24e36fa7e33026e8cbc42cd05cde02ada /src/data/composite/wiki-data | |
parent | 9da8aa3ddcca68f3183ac2b1c187ce1b5f98e2d1 (diff) |
data: withDirectory, withDirectoryFromName
Diffstat (limited to 'src/data/composite/wiki-data')
-rw-r--r-- | src/data/composite/wiki-data/index.js | 2 | ||||
-rw-r--r-- | src/data/composite/wiki-data/withDirectory.js | 55 | ||||
-rw-r--r-- | src/data/composite/wiki-data/withDirectoryFromName.js | 42 |
3 files changed, 99 insertions, 0 deletions
diff --git a/src/data/composite/wiki-data/index.js b/src/data/composite/wiki-data/index.js index b4cf6d13..15ebaffa 100644 --- a/src/data/composite/wiki-data/index.js +++ b/src/data/composite/wiki-data/index.js @@ -6,6 +6,8 @@ export {default as exitWithoutContribs} from './exitWithoutContribs.js'; export {default as inputWikiData} from './inputWikiData.js'; +export {default as withDirectory} from './withDirectory.js'; +export {default as withDirectoryFromName} from './withDirectoryFromName.js'; export {default as withParsedCommentaryEntries} from './withParsedCommentaryEntries.js'; export {default as withResolvedContribs} from './withResolvedContribs.js'; export {default as withResolvedReference} from './withResolvedReference.js'; diff --git a/src/data/composite/wiki-data/withDirectory.js b/src/data/composite/wiki-data/withDirectory.js new file mode 100644 index 00000000..b08b6153 --- /dev/null +++ b/src/data/composite/wiki-data/withDirectory.js @@ -0,0 +1,55 @@ +// Select a directory, either using a manually specified directory, or +// computing it from a name. By default these values are the current thing's +// 'directory' and 'name' properties, so it can be used without any options +// to get the current thing's effective directory (assuming no custom rules). + +import {input, templateCompositeFrom} from '#composite'; + +import {isDirectory, isName} from '#validators'; + +import {withResultOfAvailabilityCheck} from '#composite/control-flow'; + +import withDirectoryFromName from './withDirectoryFromName.js'; + +export default templateCompositeFrom({ + annotation: `withDirectory`, + + inputs: { + directory: input({ + validate: isDirectory, + defaultDependency: 'directory', + acceptsNull: true, + }), + + name: input({ + validate: isName, + defaultDependency: 'name', + acceptsNull: true, + }), + }, + + outputs: ['#directory'], + + steps: () => [ + withResultOfAvailabilityCheck({ + from: input('directory'), + }), + + { + dependencies: ['#availability', input('directory')], + compute: (continuation, { + ['#availability']: availability, + [input('directory')]: directory, + }) => + (availability + ? continuation.raiseOutput({ + ['#directory']: directory + }) + : continuation()), + }, + + withDirectoryFromName({ + name: input('name'), + }), + ], +}); diff --git a/src/data/composite/wiki-data/withDirectoryFromName.js b/src/data/composite/wiki-data/withDirectoryFromName.js new file mode 100644 index 00000000..034464e4 --- /dev/null +++ b/src/data/composite/wiki-data/withDirectoryFromName.js @@ -0,0 +1,42 @@ +// Compute a directory from a name - by default the current thing's own name. + +import {input, templateCompositeFrom} from '#composite'; + +import {isName} from '#validators'; +import {getKebabCase} from '#wiki-data'; + +import {raiseOutputWithoutDependency} from '#composite/control-flow'; + +export default templateCompositeFrom({ + annotation: `withDirectoryFromName`, + + inputs: { + name: input({ + validate: isName, + defaultDependency: 'name', + acceptsNull: true, + }), + }, + + outputs: ['#directory'], + + steps: () => [ + raiseOutputWithoutDependency({ + dependency: input('name'), + mode: input.value('falsy'), + output: input.value({ + ['#directory']: null, + }), + }), + + { + dependencies: [input('name')], + compute: (continuation, { + [input('name')]: name, + }) => continuation({ + ['#directory']: + getKebabCase(name), + }), + }, + ], +}); |