Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Add support for template customization #131

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Contentful Migrate Tool

[![npm](https://img.shields.io/npm/v/contentful-migrate.svg)](https://www.npmjs.com/package/contentful-migrate)
[![contentful-migration version](https://img.shields.io/npm/dependency-version/contentful-migrate/contentful-migration)](https://www.npmjs.com/package/contentful-migration)
[![Build Status](https://github.com/deluan/contentful-migrate/workflows/CI/badge.svg)](https://github.com/deluan/contentful-migrate/actions)
[![Downloads](https://img.shields.io/npm/dm/contentful-migrate)](https://www.npmjs.com/package/contentful-migrate)
[![npm](https://img.shields.io/npm/v/contentful-migrate-fork.svg)](https://www.npmjs.com/package/contentful-migrate-fork)
[![contentful-migration version](https://img.shields.io/npm/dependency-version/contentful-migrate-fork/contentful-migration)](https://www.npmjs.com/package/contentful-migration)
[![Build Status](https://github.com/devlato/contentful-migrate-fork/workflows/CI/badge.svg)](https://github.com/devlato/contentful-migrate-fork/actions)
[![Downloads](https://img.shields.io/npm/dm/contentful-migrate-fork)](https://www.npmjs.com/package/contentful-migrate-fork)

Manage your Contentful schema by creating incremental scripted changes. This project is based on the ideas exposed
in [Contentful's CMS as Code article](https://www.contentful.com/r/knowledgebase/cms-as-code/)
Expand Down Expand Up @@ -119,10 +119,12 @@ Creates an empty time stamped file in the content-type's migrations folder.
Options:

-c, --content-type <content-type> content type name
-t, --migration-template <migration-template> migration file template path
-e, --extension <extension> generated migration file extension
```

Example: executing the command `ctf-migrate create create-post-model -c post` will create
a file named `./migrations/post/1513695986378-create-post.js` (the timestamp will vary)
Example: executing the command `ctf-migrate create create-post-model -c post -t template.ts -e .ts` will create
a file named `./migrations/post/1513695986378-create-post.ts` (the timestamp will vary)

### list

Expand Down
39 changes: 34 additions & 5 deletions bin/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,53 @@ exports.builder = (yargs) => {
describe: 'content type name',
type: 'string',
requiresArg: true,
demandOption: true
demandOption: false
})
.option('template-file', {
alias: 't',
describe: 'template file path',
type: 'string',
requiresArg: true,
demandOption: false
})
.option('extension', {
alias: 'e',
describe: 'migration file extension',
type: 'string',
requiresArg: true,
demandOption: false
})
.positional('name', {
describe: 'descriptive name for the migration file',
type: 'string'
})
}

exports.handler = ({ name, contentType }) => {
const migrationsDirectory = path.join('.', 'migrations', contentType)
const templateFile = path.join(__dirname, '..', '..', 'lib', 'template.js')
exports.handler = ({ name, contentType, templateFile, extension }) => {
const migrationsDirectory = !!contentType
? path.join(process.cwd(), 'migrations', contentType)
: path.join(process.cwd(), 'migrations')
templateFile = !!templateFile
? path.isAbsolute(templateFile)
? templateFile
: path.join(process.cwd(), templateFile)
: !!process.env.TEMPLATE_FILE && typeof process.env.TEMPLATE_FILE === 'string'
? path.isAbsolute(process.env.TEMPLATE_FILE)
? process.env.TEMPLATE_FILE
: path.join(process.cwd(), process.env.TEMPLATE_FILE)
: path.join(__dirname, '..', '..', 'lib', 'template.js')
extension = !!extension
? extension
: !!process.env.MIGRATION_FILE_EXTENSION && typeof process.env.MIGRATION_FILE_EXTENSION === 'string'
? process.env.MIGRATION_FILE_EXTENSION
: '.js'

generator({
name,
templateFile,
migrationsDirectory,
dateFormat: 'UTC:yyyymmddHHMMss',
extension: '.js'
extension: extension
}, (error, filename) => {
if (error) {
log(chalk.bold.red(`🚨 Template generation error ${error.message}`))
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "contentful-migrate",
"version": "0.13.0",
"description": "Migration tooling for Contentful, with state management",
"name": "contentful-migrate-fork",
"version": "0.13.1",
"description": "Migration tooling for Contentful, with state management and custom templates support",
"keywords": [
"migrate",
"migrations",
"contentful",
"cms-as-code"
"cms-as-code",
"typescript"
],
"engines": {
"node": ">=8"
Expand All @@ -28,17 +29,18 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/deluan/contentful-migrate.git"
"url": "git+https://github.com/devlato/contentful-migrate.git"
},
"contributors": [
"Denis Tokarev",
"Deluan Quintao",
"Jerry Ma"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/deluan/contentful-migrate/issues"
"url": "https://github.com/devlato/contentful-migrate/issues"
},
"homepage": "https://github.com/deluan/contentful-migrate#readme",
"homepage": "https://github.com/devlato/contentful-migrate#readme",
Copy link

@Gisleburt Gisleburt Jan 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch out for the changes in package.json if you merge this PR, they'll mostly need to be put back to what they were before.

"devDependencies": {
"expect.js": "^0.3.1",
"growl": "^1.10.5",
Expand Down