Skip to content

Commit

Permalink
chore(contented): use contented.config.mjs as default (#538)
Browse files Browse the repository at this point in the history
#### What this PR does / why we need it:

So that projects can use mjs.
  • Loading branch information
fuxingloh authored Aug 4, 2023
1 parent 0fe6e26 commit da6833a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
8 changes: 4 additions & 4 deletions packages/contented-example/docs/01-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[Contented](https://contented.dev) is a Markdown-based authoring workflow that encourage developer authoring within
its contextual Git repository. `npm i @contentedjs/contented`

With a headless design of 1 config file `contented.config.js`, developers can start writing
With a headless design of 1 config file `contented.config.mjs`, developers can start writing
their [markdown content](04-markdown) and preview it on their localhost `contented write`. Choosing convention over
configuration reduces HTML/UI clutter, allowing developers to focus on authoring.

Expand Down Expand Up @@ -58,7 +58,7 @@ repo/
│ │ ├─ 02:overview.md
│ │ └─ 03:faq.md
│ └─ package.json
├─ contented.config.js
├─ contented.config.mjs
├─ package.json
└─ README.md
```
Expand All @@ -83,11 +83,11 @@ repo/
}
```

**contented.config.js**
**contented.config.mjs**

```js
/** @type {import('@contentedjs/contented').ContentedConfig} */
module.exports = {
export default {
preview: {
url: 'https://contented.dev',
name: 'Contented',
Expand Down
8 changes: 5 additions & 3 deletions packages/contented-example/docs/03-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ configure your `package.json` with these fields:
}
```

**`contented.config.js`:**
**`contented.config.mjs`:**

```js
/** @type {import('@contentedjs/contented').ContentedConfig} */
module.exports = {
const config = {
preview: {
url: 'https://contented.dev',
name: 'Contented',
Expand All @@ -47,6 +47,8 @@ module.exports = {
],
},
};

export default config;
```

**Netlify TOML:**
Expand Down Expand Up @@ -99,7 +101,7 @@ automatically ignore files in your `.gitignore` and `.contentedignore`.

> You should also add a `.gitignore` too with `echo "dist\n.contented" > .gitignore`. (Okay fine! 3 files it is. Ughhhh)
### `contented.config.js`
### `contented.config.mjs`

```typescript
export interface ContentedConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class PipelineCollectionNotFoundException extends Error {
constructor(pipelineName){
super(`Pipeline type '${pipelineName}' cannot resolve its collection. Please check if contented.config.js is properly configured.`)
super(`Pipeline type '${pipelineName}' cannot resolve its collection. Please check if contented.config.mjs is properly configured.`)
}
}
13 changes: 12 additions & 1 deletion packages/contented/src/commands/BaseCommand.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { existsSync } from 'node:fs';
import { join } from 'node:path';

import { Command } from 'clipanion';
Expand All @@ -7,8 +8,18 @@ import { ContentedConfig } from '../index.js';
export abstract class BaseCommand extends Command {
static paths = [[`build`]];

/**
* Load the configuration file for Contented.
* Checks for `contented.config.mjs` or `contented.config.js` in the current working directory.
*
* @returns {Promise<ContentedConfig>} A promise that resolves to the loaded configuration object.
*/
async loadConfig(): Promise<ContentedConfig> {
const configPath = join(process.cwd(), 'contented.config.js');
let configPath = join(process.cwd(), 'contented.config.mjs');
if (!existsSync(configPath)) {
configPath = join(process.cwd(), 'contented.config.js');
}

// eslint-disable-next-line no-console
console.log(`Loading config from: ${configPath}`);
const config = await import(configPath);
Expand Down
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"cache": false
},
"build": {
"inputs": ["tsconfig.json", "contented.config.js", "src/**"],
"inputs": ["tsconfig.json", "contented.config.mjs", "src/**"],
"outputs": ["dist/**"],
"dependsOn": ["^build"]
},
Expand Down

0 comments on commit da6833a

Please sign in to comment.