Skip to content

Commit 3fcbc2c

Browse files
committed
feat(config): enforce a single netlify-cms folder
BREAKING CHANGE: the cms config file should be placed in the "netlify-cms" folder and named "config.yml" along with the extensions js files BREAKING CHANGE: remove `extensionsDir` option closes #21
1 parent d23a138 commit 3fcbc2c

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

Diff for: README.md

+21-16
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,34 @@
4747

4848
## Usage
4949

50-
### Netlify CMS `config.yml`
50+
### Netlify CMS module config folder
51+
52+
This module will look for the Netlify CMS config file and extensions in the following folder: `[nuxt.js srcDir]/netlify-cms`.
53+
54+
:information_source: The nuxt.js [srcDir](https://nuxtjs.org/api/configuration-srcdir/) is set to the project root folder by default. If you don't change this value in nuxt config, you'll just have to create the "netlify-cms" directory at your project root folder.
55+
56+
:information_source: If you don't use any of the following two features, there's no need to create this folder.
57+
58+
#### Netlify CMS `config.yml`
5159

5260
You can specify a [custom configuration](https://www.netlifycms.org/docs/#configuration), that will be parsed and merged with the module's [netlify CMS options](#cmsconfig).
5361

54-
You have to place the file in your [project root](https://nuxtjs.org/api/configuration-rootdir/) and name it `netlify-cms.yml` instead of `config.yml`, for clarity.
62+
You have to place the file in your Netlify CMS module config folder and name it `config.yml`.
5563

56-
:information_source: Note that each path in the file (`media_folder` and collections `folder` fields) will be rewritten to prepend nuxt.js [srcDir](https://nuxtjs.org/api/configuration-srcdir/), so please specify each path relative to this folder.
64+
:information_source: Note that each path in the file (`media_folder`, collections `folder` fields and collections `file` fields) will be rewritten to prepend nuxt.js [srcDir](https://nuxtjs.org/api/configuration-srcdir/), so please specify each path relative to this folder.
5765

5866
This file can be changed while `nuxt dev` is running, and Netlify CMS will be updated automatically.
5967

68+
#### Netlify CMS extensions
69+
70+
This module will look for [Netlify CMS extensions](https://github.com/netlify/netlify-cms/blob/master/docs/intro.md#customization) in \*.js files contained in Netlify CMS module config folder and subfolders, and include them in the CMS build.
71+
72+
These are of two kinds, [Custom Previews](https://www.netlifycms.org/docs/customization/) and [Widgets](https://www.netlifycms.org/docs/extending/).
73+
74+
:information_source: The global variable `CMS` is available to these javascript files to reference the CMS object.
75+
76+
:information_source: The contents of this directory and subdirectories can be changed while `nuxt dev` is running, and Netlify CMS will be updated automatically.
77+
6078
## Options
6179
You can pass options using module options or `netlifyCms` section in `nuxt.config.js`.
6280

@@ -83,19 +101,6 @@ cmsConfig wholly reflects [Netlify CMS config.yml](#netlify-cms-configyml), in j
83101

84102
:information_source: The paths are also rewritten according to nuxt.js [srcDir](https://nuxtjs.org/api/configuration-srcdir/)
85103

86-
### `extensionsDir`:
87-
- Default: `"netlify-cms"`
88-
89-
extensionsDir defines the directory where this module will look for [Netlify CMS extensions](https://github.com/netlify/netlify-cms/blob/master/docs/intro.md#customization) in *.js files to include in the build.
90-
91-
These are of two kinds, [Custom Previews](https://www.netlifycms.org/docs/customization/) and [Widgets](https://www.netlifycms.org/docs/extending/).
92-
93-
:information_source: This path will be rewritten to prepend nuxt.js [srcDir](https://nuxtjs.org/api/configuration-srcdir/), so please specify it relative to this folder.
94-
95-
:information_source: The global variable `CMS` is available to these javascript files to reference the CMS object.
96-
97-
This directory can be changed while `nuxt dev` is running, and Netlify CMS will be updated automatically.
98-
99104
## CONTRIBUTING
100105

101106
* ⇄ Pull requests and ★ Stars are always welcome.

Diff for: src/configManager.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,22 @@ import _ from "lodash";
77
import CmsConfigFile from "./utils/cms.config.file";
88

99
const NUXT_CONFIG_KEY = "netlifyCms";
10+
const NUXT_DIST_DIR = "dist";
1011
const CMS_CONFIG_KEY = "cmsConfig";
11-
const CMS_CONFIG_FILENAME = "netlify-cms.yml";
12+
const CMS_CONFIG_DIR = "netlify-cms";
13+
const CMS_CONFIG_FILENAME = "config.yml";
1214

1315
// Defaults
1416
const DEFAULTS = {
1517
adminPath: "admin",
1618
adminTitle: "Content Manager",
17-
extensionsDir: "netlify-cms",
1819
cmsConfig: {
1920
media_folder: "static/uploads"
2021
}
2122
};
2223

2324
class ConfigManager {
2425
constructor(nuxtOptions, moduleOptions) {
25-
this._cmsConfigFile = new CmsConfigFile(
26-
join(nuxtOptions.rootDir, CMS_CONFIG_FILENAME)
27-
);
28-
2926
this._relativeSrcDir = relative(nuxtOptions.rootDir, nuxtOptions.srcDir);
3027

3128
this._userOptions = {
@@ -41,9 +38,17 @@ class ConfigManager {
4138
CMS_CONFIG_KEY
4239
);
4340
options.adminPath = options.adminPath.replace(/\/?$/, "/");
44-
options.extensionsDir = join(nuxtOptions.srcDir, options.extensionsDir);
45-
options.buildDir = join(nuxtOptions.buildDir, "dist", options.adminPath);
41+
options.buildDir = join(
42+
nuxtOptions.buildDir,
43+
NUXT_DIST_DIR,
44+
options.adminPath
45+
);
46+
options.moduleConfigDir = join(nuxtOptions.srcDir, CMS_CONFIG_DIR);
4647
this._config = Object.freeze(options);
48+
49+
this._cmsConfigFile = new CmsConfigFile(
50+
join(this._config.moduleConfigDir, CMS_CONFIG_FILENAME)
51+
);
4752
}
4853

4954
get config() {

Diff for: src/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function webpackNetlifyCmsConfig(
2121
nuxtOptions.router.base,
2222
moduleConfig.adminPath
2323
);
24-
const EXTENSIONS_DIR = moduleConfig.extensionsDir;
24+
const EXTENSIONS_DIR = moduleConfig.moduleConfigDir;
2525
const PAGE_TITLE = moduleConfig.adminTitle;
2626
const PAGE_TEMPLATE = resolve(__dirname, "../lib/template", "index.html");
2727
const REQUIRE_EXTENSIONS = existsSync(EXTENSIONS_DIR) ? true : false;

0 commit comments

Comments
 (0)