Skip to content

Instantly share code, notes, and snippets.

@TylerBarnes
Created February 29, 2020 05:31
Show Gist options
  • Save TylerBarnes/41a193092373c2c548283cfcaf3a2271 to your computer and use it in GitHub Desktop.
Save TylerBarnes/41a193092373c2c548283cfcaf3a2271 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const inGatsbyDir = {
initial: "unsureIfSourcePluginIsInstalled",
states: {
unsureIfSourcePluginIsInstalled: {
onEntry: "determineIfSourcePluginIsInstalled",
on: {
SOURCE_PLUGIN_IS_INSTALLED: "sourcePluginIsInstalled",
SOURCE_PLUGIN_IS_NOT_INSTALLED: "sourcePluginIsNotInstalled",
},
},
sourcePluginIsInstalled: {
initial: "unsureIfPluginIsConfigured",
states: {
unsureIfPluginIsConfigured: {
onEntry: "determineIfSourcePluginIsConfigured",
on: {
SOURCE_PLUGIN_IS_CONFIGURED: "sourcePluginIsConfigured",
SOURCE_PLUGIN_IS_NOT_CONFIGURED: "sourcePluginIsNotConfigured",
},
},
sourcePluginIsConfigured: {
onEntry: "determineIfWPIsConfiguredUsingWPSv4Util",
on: {
WP_IS_CONFIGURED: "#cli.celebrate",
WP_IS_NOT_CONFIGURED: "wordPressIsNotConfigured",
},
},
wordPressIsNotConfigured: {
initial: "notSureIfWeShouldConfigureWordPress",
onEntry: "askIfWeShouldConfigureWordPress",
states: {
notSureIfWeShouldConfigureWordPress: {
on: {
CONFIGURE_WORDPRESS: "configuringWordPress",
DONT_CONFIGURE_WORDPRESS: "#cli.exit",
},
},
configuringWordPress: {
onEntry: "useSourcePluginCredentialsToInstallWordPressPlugins",
on: {
WORDPRESS_CONFIGURED: "configurationCompleted",
// CONFIGURATION_FAILED: ""
},
},
configurationCompleted: {
onEntry: "letTheUserKnowWordPressIsConfigured",
on: {
CELEBRATE_GOOD_TIMES: "#cli.celebrate",
},
},
},
},
sourcePluginIsNotConfigured: {
initial: "unsureIfWeShouldConfigureSourcePlugin",
states: {
unsureIfWeShouldConfigureSourcePlugin: {
onEntry: "askIfWeShouldConfigureTheSourcePlugin",
on: {
CONFIGURE: "configuringPlugin",
EXIT: "#cli.exit",
},
},
configuringPlugin: {
initial: "collectingCredentials",
states: {
collectingCredentials: {
onEntry: "promptForWpUrlAndCredentials",
on: {
CREDENTIALS_COLLECTED: "testingCredentials",
},
},
testingCredentials: {
onEntry: "tryCredentials",
on: {
CREDENTIALS_WORK:
"#cli.inGatsbyDir.sourcePluginIsInstalled.sourcePluginIsConfigured",
CREDENTIALS_FAIL: "credentialsFailed",
},
},
credentialsFailed: {
onEntry: "letTheUserKnowTheCredentialsAreWrong",
on: {
TRY_AGAIN: "collectingCredentials",
EXIT: "#cli.exit",
},
},
},
},
},
},
},
},
sourcePluginIsNotInstalled: {
on: {
INSTALL_PLUGIN: "sourcePluginIsNotInstalled.installingPlugin",
EXIT: "#cli.exit",
},
initial: "unsureIfWeShouldInstall",
states: {
unsureIfWeShouldInstall: {
onEntry: "askIfWeShouldInstallSourcePlugin",
on: {
INSTALL: "installingPlugin",
EXIT: "#cli.exit",
},
},
installingPlugin: {
onEntry: "installSourcePlugin",
on: {
PLUGIN_INSTALLED: "#cli.inGatsbyDir.sourcePluginIsInstalled",
},
},
},
},
},
}
const inNonGatsbyDir = {
initial: "notSureIfWeShouldCreateAGatsbySite",
states: {
notSureIfWeShouldCreateAGatsbySite: {
onEntry: "askIfWeShouldCreateAGatsbySite",
on: {
CREATE: "creatingGatsbySite",
EXIT: "#cli.exit",
},
},
creatingGatsbySite: {
initial: "siteNotYetCreated",
onEntry: "createNewGatsbySite",
on: {
GATSBY_SITE_CREATED: "creatingGatsbySite.siteCreated",
},
states: {
siteNotYetCreated: {
onEntry: "createNewGatsbySite",
on: {
SITE_CREATED: "siteCreated",
},
},
siteCreated: {
onEntry: "cdToNewGatsbySite",
on: {
CHANGED_DIR: "#cli.inUnknownDir",
},
},
},
},
},
}
const cliMachine = Machine({
id: "cli",
initial: "inUnknownDir",
states: {
inUnknownDir: {
on: {
IS_GATSBY: "inGatsbyDir",
ISNT_GATSBY: "inNonGatsbyDir",
},
onEntry: "checkIfIsGatsbyDir",
},
inGatsbyDir,
inNonGatsbyDir,
celebrate: {
onEntry: "celebrateThatAllIsGood",
on: {
FIN: "exit",
},
},
exit: {
onEntry: "exitCli",
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment