22import util from 'util'
33import { program } from 'commander'
44import { fetchEntity } from './fetchEntity'
5+ import { translatePath } from './translatePath'
56
67program
78 . description (
89 'Fetch a resource from the Drupal JSON:API. Useful for grabbing mock data.'
910 )
10- . argument ( '< resource-type> ' , 'The resource type to fetch' )
11+ . argument ( '[ resource-type] ' , 'The resource type to fetch' )
1112 . argument (
1213 '[uuid]' ,
13- 'The ID of the resource to fetch (optional if using --collection)'
14+ 'The ID of the resource to fetch (optional if using --collection or --translate-path)'
15+ )
16+ . option (
17+ '--translate-path <path>' ,
18+ 'Resolve a Drupal path to its resource type and UUID via translatePath'
1419 )
1520 . option (
1621 '--include <includes...>' ,
@@ -28,6 +33,29 @@ program
2833 '1'
2934 )
3035 . action ( async ( resourceType , uuid , options ) => {
36+ if ( options . translatePath ) {
37+ const pathInfo = await translatePath ( options . translatePath )
38+
39+ if ( options . json ) {
40+ console . log ( JSON . stringify ( pathInfo , null , 2 ) )
41+ } else {
42+ console . log (
43+ util . inspect ( pathInfo , {
44+ depth : null ,
45+ colors : process . stdout . isTTY ,
46+ } )
47+ )
48+ }
49+ return
50+ }
51+
52+ if ( ! resourceType || ! uuid ) {
53+ console . error (
54+ 'Error: [resource-type] and [uuid] are required unless --translate-path is provided'
55+ )
56+ process . exit ( 1 )
57+ }
58+
3159 const data = await fetchEntity ( resourceType , uuid , options )
3260 // NOTE: There may be a thing we can do to just _check_ for circular
3361 // references. console.log(util.format('%j', data)) will output just
0 commit comments