import 'dotenv/config'; import { docopt } from 'docopt'; import pkg from '../package.json'; import dump from './dump/command'; import check from './check/command'; import wpImport from './wpImport/command'; import contentfulImport from './contentfulImport/command'; import toggleMaintenanceMode from './toggleMaintenanceMode/command'; import createMigrationScript from './createMigrationScript/command'; import runPendingMigrations from './runPendingMigrations/command'; import forkEnvironment from './forkEnvironment/command'; import getPrimaryEnvironment from './environment/getPrimary/command'; import promoteEnvironment from './environment/promote/command'; import destroyEnvironment from './environment/destroy/command'; const doc = ` DatoCMS CLI tool Usage: dato dump [--watch] [--verbose] [--preview] [--token=] [--environment=] [--config=] [--cmaBaseUrl=] [--pageSize=] dato new migration [--migrationsDir=] [--migrationTemplate=] dato migrate [--source=] [--destination=] [--inPlace] [--dryRun] [--migrationModel=] [--migrationsDir=] [--jsonOutput] [--token=] [--cmaBaseUrl=] dato environment fork [--token=] [--cmaBaseUrl=] dato environment get-primary [--token=] [--cmaBaseUrl=] dato environment promote [--token=] [--cmaBaseUrl=] dato environment destroy [--token=] [--cmaBaseUrl=] dato maintenance (on|off) [--force] [--token=] [--cmaBaseUrl=] dato wp-import --token= [--environment=] --wpUrl= --wpUser= --wpPassword= [--datoCmaBaseUrl=] [--wpApiEndpointUrl=] dato contentful-import --datoCmsToken= --contentfulToken= --contentfulSpaceId= [--contentfulEnvironment=] [--datoCmsEnvironment=] [--skipContent] [--datoCmaBaseUrl=] [(--includeOnly ...)] dato check dato -h | --help dato --version Options: --migrationsDir= Directory containing the migration scripts [default: ./migrations] --migrationModel= API key of the migration model [default: schema_migration] --cmaBaseUrl= DatoCMS CMA base URL [default: https://site-api.datocms.com/] `; module.exports = argv => { const options = docopt(doc, { argv, version: pkg.version }); if (options.dump) { return dump(options); } if (options.check) { return check(options); } if (options.maintenance) { const { on, '--token': token, '--force': force, '--cmaBaseUrl': cmaBaseUrl, } = options; return toggleMaintenanceMode({ activate: on, token, force, cmaBaseUrl }); } if (options.new && options.migration) { const { '': name, '--migrationsDir': relativeMigrationsDir, '--migrationTemplate': relativeMigrationTemplatePath = null, } = options; return createMigrationScript({ name, relativeMigrationsDir, relativeMigrationTemplatePath, }); } if (options.migrate) { const { '--source': sourceEnvId, '--destination': destinationEnvId, '--migrationModel': migrationModelApiKey, '--migrationsDir': relativeMigrationsDir, '--inPlace': inPlace, '--dryRun': dryRun, '--jsonOutput': jsonOutput, '--token': token, '--cmaBaseUrl': cmaBaseUrl, } = options; return runPendingMigrations({ sourceEnvId, destinationEnvId, inPlace, dryRun, jsonOutput, migrationModelApiKey, relativeMigrationsDir, token, cmaBaseUrl, }); } if (options.environment) { if (options['get-primary']) { const { '--token': token, '--cmaBaseUrl': cmaBaseUrl } = options; return getPrimaryEnvironment({ token, cmaBaseUrl }); } if (options.fork) { const { '': sourceEnvId, '': destinationEnvId, '--token': token, '--cmaBaseUrl': cmaBaseUrl, } = options; return forkEnvironment({ sourceEnvId, destinationEnvId, token, cmaBaseUrl, }); } if (options.promote) { const { '': environmentId, '--token': token, '--cmaBaseUrl': cmaBaseUrl, } = options; return promoteEnvironment({ environmentId, token, cmaBaseUrl }); } if (options.destroy) { const { '': environmentId, '--token': token, '--cmaBaseUrl': cmaBaseUrl, } = options; return destroyEnvironment({ environmentId, token, cmaBaseUrl }); } } if (options['wp-import']) { const { '--token': token, '--environment': environment, '--wpUrl': wpUrl, '--wpUser': wpUser, '--wpPassword': wpPassword, '--datoCmaBaseUrl': cmaBaseUrl, '--wpApiEndpointUrl': wpApiEndpointUrl, } = options; return wpImport( token, environment, wpUrl, wpUser, wpPassword, cmaBaseUrl, wpApiEndpointUrl, ); } if (options['contentful-import']) { const { '--contentfulToken': contentfulToken, '--contentfulSpaceId': contentfulSpaceId, '--contentfulEnvironment': contentfulEnvironment, '--datoCmsToken': datoCmsToken, '--datoCmsEnvironment': datoCmsEnvironment, '--skipContent': skipContent, '--includeOnly': includeOnly, '--datoCmaBaseUrl': datoCmsCmaBaseUrl, '': contentType, } = options; return contentfulImport({ contentfulToken, contentfulSpaceId, contentfulEnvironment, datoCmsCmaBaseUrl, datoCmsToken, datoCmsEnvironment, skipContent, contentType: includeOnly ? contentType : false, }); } return false; };