@jee-r/astro-decap-cms 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ # Changesets
2
+
3
+ Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4
+ with multi-package repos, or single-package repos to help you version and publish your code. You can
5
+ find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6
+
7
+ We have a quick list of common questions to get you started engaging with this project in
8
+ [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "https://unpkg.com/@changesets/config@2.1.1/schema.json",
3
+ "changelog": [
4
+ "@changesets/changelog-github",
5
+ { "repo": "delucis/astro-netlify-cms" }
6
+ ],
7
+ "commit": false,
8
+ "fixed": [],
9
+ "linked": [],
10
+ "access": "public",
11
+ "baseBranch": "latest",
12
+ "updateInternalDependencies": "patch",
13
+ "ignore": []
14
+ }
@@ -0,0 +1,37 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [latest]
6
+ pull_request:
7
+ branches: [latest]
8
+
9
+ # Automatically cancel in-progress actions on the same branch
10
+ concurrency:
11
+ group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }}
12
+ cancel-in-progress: true
13
+
14
+ jobs:
15
+ test:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - name: Checkout
19
+ uses: actions/checkout@v3
20
+
21
+ - name: Setup Node.js 16.x
22
+ uses: actions/setup-node@v2
23
+ with:
24
+ node-version: 16.x
25
+
26
+ - name: Cache node_modules
27
+ uses: actions/cache@v2
28
+ with:
29
+ path: ~/.npm
30
+ key: node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
31
+ restore-keys: node-${{ matrix.node }}-
32
+
33
+ - name: Install Dependencies
34
+ run: npm ci
35
+
36
+ - name: Test
37
+ run: npm t
@@ -0,0 +1,42 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ concurrency: ${{ github.workflow }}-${{ github.ref }}
9
+
10
+ jobs:
11
+ release:
12
+ name: Release
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - name: Checkout Repo
16
+ uses: actions/checkout@v2
17
+ with:
18
+ # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
19
+ fetch-depth: 0
20
+
21
+ - name: Setup Node.js 16.x
22
+ uses: actions/setup-node@v2
23
+ with:
24
+ node-version: 16.x
25
+
26
+ - name: Cache node_modules
27
+ uses: actions/cache@v2
28
+ with:
29
+ path: ~/.npm
30
+ key: node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
31
+ restore-keys: node-${{ matrix.node }}-
32
+
33
+ - name: Install Dependencies
34
+ run: npm ci
35
+
36
+ - name: Create Release Pull Request
37
+ uses: changesets/action@v1
38
+ with:
39
+ publish: npx changeset publish
40
+ env:
41
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
package/CHANGELOG.md ADDED
@@ -0,0 +1,165 @@
1
+ # astro-netlify-cms
2
+
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Switch from netlify-cms to decap-cms
8
+
9
+ ## 0.5.4
10
+
11
+ ### Patch Changes
12
+
13
+ - [#76](https://github.com/delucis/astro-netlify-cms/pull/76) [`2e24122`](https://github.com/delucis/astro-netlify-cms/commit/2e241229a38d7aa783ea9df462e66b8c15ffa963) Thanks [@Marocco2](https://github.com/Marocco2)! - Support for Astro v3
14
+
15
+ ## 0.5.3
16
+
17
+ ### Patch Changes
18
+
19
+ - [#63](https://github.com/delucis/astro-netlify-cms/pull/63) [`e3884e3`](https://github.com/delucis/astro-netlify-cms/commit/e3884e303ba49fd70fb90fc412715de6dec6cfbd) Thanks [@dependabot](https://github.com/apps/dependabot)! - Bump simple-git from 3.15.1 to 3.16.0
20
+
21
+ ## 0.5.2
22
+
23
+ ### Patch Changes
24
+
25
+ - [`8f23e86`](https://github.com/delucis/astro-netlify-cms/commit/8f23e8667b591838aff456649d7bc059072dd9b0) Thanks [@delucis](https://github.com/delucis)! - Update peer dependencies to support Astro v2
26
+
27
+ ## 0.5.1
28
+
29
+ ### Patch Changes
30
+
31
+ - [#56](https://github.com/delucis/astro-netlify-cms/pull/56) [`b5cb7aa`](https://github.com/delucis/astro-netlify-cms/commit/b5cb7aac1d243af7a4e9814be1f47158e28a897c) Thanks [@dependabot](https://github.com/apps/dependabot)! - Bump json5 and react-hot-loader
32
+
33
+ ## 0.5.0
34
+
35
+ ### Minor Changes
36
+
37
+ - [#53](https://github.com/delucis/astro-netlify-cms/pull/53) [`40d0385`](https://github.com/delucis/astro-netlify-cms/commit/40d03858fa4a049684e1b9cc895c7280e7479cb5) Thanks [@delucis](https://github.com/delucis)! - Don’t automatically inject `@astrojs/react` integration
38
+
39
+ ⚠️ BREAKING CHANGE ⚠️
40
+
41
+ Previously, this integration included [`@astrojs/react`](https://docs.astro.build/en/guides/integrations-guide/react/) and injected it to Astro’s integrations config for you. This is no longer the case.
42
+
43
+ If you are using React components and were relying on this, make sure to add the integration when upgrading. The simplest way to do this is to run:
44
+
45
+ ```bash
46
+ npx astro add react
47
+ ```
48
+
49
+ ## 0.4.0
50
+
51
+ ### Minor Changes
52
+
53
+ - [#48](https://github.com/delucis/astro-netlify-cms/pull/48) [`a1a0002`](https://github.com/delucis/astro-netlify-cms/commit/a1a0002c63c542a4dd82ae093effaf18bb824a84) Thanks [@delucis](https://github.com/delucis)! - Add support for importing npm packages via `previewStyles` config
54
+
55
+ ⚠️ **BREAKING CHANGE** ⚠️
56
+
57
+ This release changes how you import a local CSS file in `previewStyles`.
58
+ These must now be prefixed with a leading `/`:
59
+
60
+ ```diff
61
+ {
62
+ previewStyles: [
63
+ - 'src/styles/base.css',
64
+ + '/src/styles/base.css',
65
+ ],
66
+ }
67
+ ```
68
+
69
+ This allows us to support importing CSS you may have installed from an npm module, for example importing font CSS from Fontsource:
70
+
71
+ ```js
72
+ previewStyles: ["@fontsource/roboto"];
73
+ ```
74
+
75
+ ## 0.3.5
76
+
77
+ ### Patch Changes
78
+
79
+ - [#46](https://github.com/delucis/astro-netlify-cms/pull/46) [`cdbf7d6`](https://github.com/delucis/astro-netlify-cms/commit/cdbf7d63df2bbb1b65c661e87f93369f3977725a) Thanks [@delucis](https://github.com/delucis)! - Include identity widget on admin route even when `disableIdentityWidgetInjection` is set to `true`
80
+
81
+ ## 0.3.4
82
+
83
+ ### Patch Changes
84
+
85
+ - [#41](https://github.com/delucis/astro-netlify-cms/pull/41) [`7e53467`](https://github.com/delucis/astro-netlify-cms/commit/7e53467096dad33bd2c15f060f3c4c4ad03a7a1e) Thanks [@dependabot](https://github.com/apps/dependabot)! - Bump loader-utils from 1.4.0 to 1.4.2
86
+
87
+ ## 0.3.3
88
+
89
+ ### Patch Changes
90
+
91
+ - [#38](https://github.com/delucis/astro-netlify-cms/pull/38) [`9b2802c`](https://github.com/delucis/astro-netlify-cms/commit/9b2802cb1727d9e1e2f695ad1631c71af9bb9a52) Thanks [@delucis](https://github.com/delucis)! - Restart Netlify CMS proxy server when astro.config reloads
92
+
93
+ ## 0.3.2
94
+
95
+ ### Patch Changes
96
+
97
+ - [#33](https://github.com/delucis/astro-netlify-cms/pull/33) [`d62b891`](https://github.com/delucis/astro-netlify-cms/commit/d62b8917f78ba7520c32ba0ba6bd32d818183c28) Thanks [@Marocco2](https://github.com/Marocco2)! - Add `disableIdentityWidgetInjection` option
98
+
99
+ - [#36](https://github.com/delucis/astro-netlify-cms/pull/36) [`c508be4`](https://github.com/delucis/astro-netlify-cms/commit/c508be466b0c46dcd9bc6897045e0b90f173b9ab) Thanks [@delucis](https://github.com/delucis)! - Fix an issue in some browsers with the rich text editor.
100
+
101
+ Adds the workaround documented in [netlify/netlify-cms#5092](https://github.com/netlify/netlify-cms/issues/5092) to the admin dashboard.
102
+
103
+ ## 0.3.2-next.0
104
+
105
+ ### Patch Changes
106
+
107
+ - [#33](https://github.com/delucis/astro-netlify-cms/pull/33) [`d62b891`](https://github.com/delucis/astro-netlify-cms/commit/d62b8917f78ba7520c32ba0ba6bd32d818183c28) Thanks [@Marocco2](https://github.com/Marocco2)! - Add `disableIdentityWidgetInjection` option
108
+
109
+ ## 0.3.1
110
+
111
+ ### Patch Changes
112
+
113
+ - [`bd64e05`](https://github.com/delucis/astro-netlify-cms/commit/bd64e057e5df57f8e1b494336a98617fb239f5ac) Thanks [@delucis](https://github.com/delucis)! - Upgrade React dependencies
114
+
115
+ ## 0.3.0
116
+
117
+ ### Minor Changes
118
+
119
+ - [#30](https://github.com/delucis/astro-netlify-cms/pull/30) [`6757440`](https://github.com/delucis/astro-netlify-cms/commit/6757440b968332f0b1dc6a52ee70a6c1852f7b15) Thanks [@delucis](https://github.com/delucis)! - Refactor to use Astro’s built-in `injectRoute` helper to add the admin dashboard.
120
+
121
+ Significantly simplifies the Vite plugin logic and should make future improvements easier to implement.
122
+
123
+ ## 0.2.5
124
+
125
+ ### Patch Changes
126
+
127
+ - [`013a42d`](https://github.com/delucis/astro-netlify-cms/commit/013a42d0e7d656b760283af19422c9602d83a9e3) Thanks [@delucis](https://github.com/delucis)! - Fix preview styles in production builds
128
+
129
+ ## 0.2.4
130
+
131
+ ### Patch Changes
132
+
133
+ - [#25](https://github.com/delucis/astro-netlify-cms/pull/25) [`eba6556`](https://github.com/delucis/astro-netlify-cms/commit/eba65563e2815242877498bf43f8a1d8b3e4f41a) Thanks [@Opposedmatty](https://github.com/Opposedmatty)! - Fix typo in description meta tag
134
+
135
+ ## 0.2.3
136
+
137
+ ### Patch Changes
138
+
139
+ - [#23](https://github.com/delucis/astro-netlify-cms/pull/23) [`26243d5`](https://github.com/delucis/astro-netlify-cms/commit/26243d54ebee46122053d315ad929c4636a123e2) Thanks [@codelastnight](https://github.com/codelastnight)! - remove node join() from vite-plugin-admin-dashboard to allow windows to run dev
140
+
141
+ ## 0.2.2
142
+
143
+ ### Patch Changes
144
+
145
+ - [`a7c4e43`](https://github.com/delucis/astro-netlify-cms/commit/a7c4e43511af695b91c0b2b19a750d769d692f98) Thanks [@delucis](https://github.com/delucis)! - Hot fix: remove comment clashing with over-eager whitespace collapsing by astro-compress
146
+
147
+ ## 0.2.1
148
+
149
+ ### Patch Changes
150
+
151
+ - [`cb7adcc`](https://github.com/delucis/astro-netlify-cms/commit/cb7adcc8c0a61756817449cf240efacf82cd79c1) Thanks [@delucis](https://github.com/delucis)! - Fix for compression support: end import statements with semi-colons
152
+
153
+ ## 0.2.0
154
+
155
+ ### Minor Changes
156
+
157
+ - [`0726494`](https://github.com/delucis/astro-netlify-cms/commit/0726494a5908a50ac859a92c7bf78f18f2399437) — Update to Astro v1 🚀
158
+
159
+ ### Patch Changes
160
+
161
+ - [`f5b06ed`](https://github.com/delucis/astro-netlify-cms/commit/f5b06ed24ec3f90ed17a6dd33def80e531e9ffd3) — Run `netlify-cms-proxy-server` in shell on Windows (fixes [#13](https://github.com/delucis/astro-netlify-cms/issues/13))
162
+
163
+ ## 0.1.0
164
+
165
+ Initial release
package/README.md ADDED
@@ -0,0 +1,139 @@
1
+ ![Astro + Decap CMS](header.png)
2
+
3
+ <p align="center">
4
+ Add <a href="https://decapcms.org/">Decap CMS</a>’s admin dashboard
5
+ to any <a href="https://astro.build/">Astro</a> project
6
+ </p>
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm i astro-decap-cms
12
+ ```
13
+
14
+ ## What is this?
15
+
16
+ This is an integration for the [Astro](https://astro.build/) site builder,
17
+ which adds support for [Decap CMS](https:///), an
18
+ open-source, Git-based content management system.
19
+
20
+ Adding the integration will:
21
+
22
+ - Add the Decap CMS dashboard at `/admin` (or another route if you prefer)
23
+ - Inject Netlify’s [Identity Widget](https://github.com/netlify/netlify-identity-widget) across your site to support logging in to the admin app
24
+ - Run a [local proxy server](https://decapcms.org/docs/beta-features/#working-with-a-local-git-repository) in `dev` mode to allow local content updates via the CMS
25
+
26
+ Usually each of these requires individual set up and configuration. Using this integration, you configure your CMS once in `astro.config.mjs`, sit back, and enjoy!
27
+
28
+ > Looking for a quick way to get started? [Try out the Blog Starter with Decap CMS →](https://github.com/delucis/astro-netlify-cms-starter)
29
+
30
+ ## Usage
31
+
32
+ ### Adding the integration
33
+
34
+ To add Decap CMS to your project, import and use the integration in your
35
+ Astro config file, adding it to the `integrations` array.
36
+
37
+ ```js
38
+ // astro.config.mjs
39
+
40
+ import { defineConfig } from 'astro/config';
41
+ import NetlifyCMS from 'astro-decap-cms';
42
+
43
+ export default defineConfig({
44
+ integrations: [
45
+ NetlifyCMS({
46
+ config: {
47
+ backend: {
48
+ name: 'git-gateway',
49
+ branch: 'main',
50
+ },
51
+ collections: [
52
+ // Content collections
53
+ ],
54
+ },
55
+ }),
56
+ ],
57
+ });
58
+ ```
59
+
60
+ ### Configuration options
61
+
62
+ You can pass an options object to the integration to configure how it behaves.
63
+
64
+ #### `adminPath`
65
+
66
+ **Type:** `string`
67
+ **Default:** `'/admin'`
68
+
69
+ Determines the route where the Decap CMS admin dashboard will be available on your site.
70
+
71
+ Feeling nostalgic for WordPress? You could set this to `'/wp-admin'`!
72
+
73
+ #### `config`
74
+
75
+ **Type:** `CmsConfig`
76
+
77
+ This option is **required**. It allows you to configure Decap CMS with the
78
+ same options you would use when using Decap CMS’s `config.yml` file format.
79
+
80
+ You can see [a full list of configuration options in the Decap CMS docs](https://decapcms.org/docs/configuration-options/).
81
+
82
+ At a minimum, you _must_ set the `backend` and `collections` options:
83
+
84
+ ```js
85
+ config: {
86
+ // Use Netlify’s “Git Gateway” authentication and target our default branch
87
+ backend: {
88
+ name: 'git-gateway',
89
+ branch: 'main',
90
+ },
91
+ collections: [
92
+ // Define a blog post collection
93
+ {
94
+ name: 'posts',
95
+ label: 'Blog Posts',
96
+ folder: 'src/pages/posts',
97
+ create: true,
98
+ delete: true,
99
+ fields: [
100
+ { name: 'title', widget: 'string', label: 'Post Title' },
101
+ { name: 'body', widget: 'markdown', label: 'Post Body' },
102
+ ],
103
+ },
104
+ ],
105
+ };
106
+ ```
107
+
108
+ #### `previewStyles`
109
+
110
+ **Type:** `Array<string | [string, { raw: true }]>`
111
+
112
+ Sets custom CSS styles to apply in the Decap CMS preview pane.
113
+
114
+ You can provide URLs to external CSS stylesheets (Google Fonts for example), paths to local CSS files in your project, or even raw CSS strings:
115
+
116
+ ```js
117
+ previewStyles: [
118
+ // Path to a local CSS file, relative to your project’s root directory
119
+ '/src/styles/main.css',
120
+ // An npm module identifier
121
+ '@fontsource/roboto',
122
+ // A URL to an externally hosted CSS file
123
+ 'https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&display=swap',
124
+ // Raw CSS!
125
+ ['p { color: red; }', { raw: true }],
126
+ ];
127
+ ```
128
+
129
+ #### `disableIdentityWidgetInjection`
130
+
131
+ **Type:** `boolean`
132
+ **Default:** `false`
133
+
134
+ By default, `astro-decap-cms` injects Netlify’s [Identity Widget](https://github.com/netlify/netlify-identity-widget) across your site to enable authentication. If you only want to inject the widget on the admin route, you can set `disableIdentityWidgetInjection: true`.
135
+
136
+ ## To-do
137
+
138
+ - Support registering custom preview components to render content as it is edited.
139
+ - Support registering custom block components for use in the Markdown editor.
@@ -0,0 +1,22 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>Content Manager</title>
5
+ <meta
6
+ name="description"
7
+ content="Admin dashboard for managing website content"
8
+ />
9
+ <script>
10
+ import options from 'virtual:astro-decap-cms/user-config';
11
+ import initCMS from './dist/cms';
12
+ initCMS(options);
13
+ </script>
14
+ <style is:global>
15
+ /* Workaround for https://github.com/netlify/netlify-cms/issues/5092 */
16
+ [data-slate-editor] {
17
+ -webkit-user-modify: read-write !important;
18
+ }
19
+ </style>
20
+ </head>
21
+ <body></body>
22
+ </html>
package/dist/cms.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { InitCmsOptions } from './types';
2
+ export default function initCMS({ cms, config, previewStyles, }: InitCmsOptions): void;
package/dist/cms.js ADDED
@@ -0,0 +1,23 @@
1
+ export default function initCMS({ cms, config, previewStyles = [], }) {
2
+ // Provide default values given we can make a reasonable guess
3
+ const mediaDefaults = !config.media_folder
4
+ ? { media_folder: 'public', public_folder: '/' }
5
+ : {};
6
+ cms.init({
7
+ config: Object.assign(Object.assign({
8
+ // Don’t try to load config.yml as we’re providing the config below
9
+ load_config_file: false,
10
+ // Enable use of the Netlify CMS proxy server when working locally
11
+ local_backend: true }, mediaDefaults), config),
12
+ });
13
+ /**
14
+ * One drawback of using Netlify CMS is that it registers all preview
15
+ * styles globally — not scoped to a specific collection.
16
+ * You lose Astro components’ scoped styling anyway by being forced
17
+ * to use React, but just be extra careful.
18
+ *
19
+ * The (undocumented?) `raw: true` setting treats the first argument as
20
+ * a raw CSS string to inject instead of as a URL to load a stylesheet from.
21
+ */
22
+ previewStyles.forEach(([style, opts]) => cms.registerPreviewStyle(style, opts));
23
+ }
@@ -0,0 +1 @@
1
+ export declare function initIdentity(adminPath: string): void;
@@ -0,0 +1,11 @@
1
+ import identity from 'netlify-identity-widget';
2
+ export function initIdentity(adminPath) {
3
+ identity.on('init', (user) => {
4
+ if (!user) {
5
+ identity.on('login', () => {
6
+ document.location.href = adminPath;
7
+ });
8
+ }
9
+ });
10
+ identity.init();
11
+ }
@@ -0,0 +1,15 @@
1
+ import type { AstroIntegration } from 'astro';
2
+ import type { CmsConfig } from 'decap-cms-core';
3
+ import type { PreviewStyle } from './types.js';
4
+ interface NetlifyCMSOptions {
5
+ /**
6
+ * Path at which the Netlify CMS admin dashboard should be served.
7
+ * @default '/admin'
8
+ */
9
+ adminPath?: string;
10
+ config: Omit<CmsConfig, 'load_config_file' | 'local_backend'>;
11
+ disableIdentityWidgetInjection?: boolean;
12
+ previewStyles?: PreviewStyle[];
13
+ }
14
+ export default function NetlifyCMS({ disableIdentityWidgetInjection, adminPath, config: cmsConfig, previewStyles, }: NetlifyCMSOptions): AstroIntegration;
15
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ import { spawn } from 'node:child_process';
2
+ import AdminDashboard from './vite-plugin-admin-dashboard.js';
3
+ const widgetPath = 'astro-decap-cms/identity-widget';
4
+ export default function NetlifyCMS({ disableIdentityWidgetInjection = false, adminPath = '/admin', config: cmsConfig, previewStyles = [], }) {
5
+ if (!adminPath.startsWith('/')) {
6
+ throw new Error('`adminPath` option must be a root-relative pathname, starting with "/", got "' +
7
+ adminPath +
8
+ '"');
9
+ }
10
+ if (adminPath.endsWith('/')) {
11
+ adminPath = adminPath.slice(0, -1);
12
+ }
13
+ let proxy;
14
+ const NetlifyCMSIntegration = {
15
+ name: 'decap-cms',
16
+ hooks: {
17
+ 'astro:config:setup': ({ config, injectRoute, injectScript, updateConfig, }) => {
18
+ var _a;
19
+ const identityWidgetScript = `import { initIdentity } from '${widgetPath}'; initIdentity('${adminPath}');`;
20
+ const newConfig = {
21
+ // Default to the URL provided by Netlify when building there. See:
22
+ // https://docs.netlify.com/configure-builds/environment-variables/#deploy-urls-and-metadata
23
+ site: config.site || process.env.URL,
24
+ vite: {
25
+ plugins: [
26
+ ...(((_a = config.vite) === null || _a === void 0 ? void 0 : _a.plugins) || []),
27
+ AdminDashboard({
28
+ config: cmsConfig,
29
+ previewStyles,
30
+ identityWidget: disableIdentityWidgetInjection
31
+ ? identityWidgetScript
32
+ : '',
33
+ }),
34
+ ],
35
+ },
36
+ };
37
+ updateConfig(newConfig);
38
+ injectRoute({
39
+ pattern: adminPath,
40
+ entryPoint: 'astro-decap-cms/admin-dashboard.astro',
41
+ });
42
+ if (!disableIdentityWidgetInjection) {
43
+ injectScript('page', identityWidgetScript);
44
+ }
45
+ },
46
+ 'astro:server:start': () => {
47
+ proxy = spawn('decap-server', {
48
+ stdio: 'inherit',
49
+ // Run in shell on Windows to make sure the npm package can be found.
50
+ shell: process.platform === 'win32',
51
+ });
52
+ process.on('exit', () => proxy.kill());
53
+ },
54
+ 'astro:server:done': () => {
55
+ proxy.kill();
56
+ },
57
+ },
58
+ };
59
+ return NetlifyCMSIntegration;
60
+ }
@@ -0,0 +1,11 @@
1
+ import type CMS from 'decap-cms-app';
2
+ import type { CmsConfig } from 'decap-cms-core';
3
+ export declare type NormalizedPreviewStyle = [pathOrUrl: string] | [rawCSS: string, meta: {
4
+ raw: boolean;
5
+ }];
6
+ export declare type PreviewStyle = string | NormalizedPreviewStyle;
7
+ export interface InitCmsOptions {
8
+ cms: typeof CMS;
9
+ config: CmsConfig;
10
+ previewStyles?: NormalizedPreviewStyle[];
11
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { CmsConfig } from 'decap-cms-core';
2
+ import type { Plugin } from 'vite';
3
+ import type { PreviewStyle } from './types';
4
+ export default function AdminDashboardPlugin({ config, previewStyles, identityWidget, }: {
5
+ config: Omit<CmsConfig, 'load_config_file' | 'local_backend'>;
6
+ previewStyles: PreviewStyle[];
7
+ identityWidget: string;
8
+ }): Plugin;
@@ -0,0 +1,45 @@
1
+ const virtualModuleId = 'virtual:astro-decap-cms/user-config';
2
+ const resolvedVirtualModuleId = '\0' + virtualModuleId;
3
+ function generateVirtualConfigModule({ config, previewStyles = [], identityWidget, }) {
4
+ const imports = [];
5
+ const styles = [];
6
+ previewStyles.forEach((entry, index) => {
7
+ if (!Array.isArray(entry))
8
+ entry = [entry];
9
+ const [style, opts] = entry;
10
+ if ((opts === null || opts === void 0 ? void 0 : opts.raw) || style.startsWith('http')) {
11
+ styles.push(JSON.stringify([style, opts]));
12
+ }
13
+ else {
14
+ const name = `style__${index}`;
15
+ imports.push(`import ${name} from '${style}?raw';`);
16
+ styles.push(`[${name}, { raw: true }]`);
17
+ }
18
+ });
19
+ return `${imports.join('\n')}
20
+ import * as NCMS from 'decap-cms-app';
21
+ ${identityWidget}
22
+ export default {
23
+ cms: NCMS,
24
+ config: JSON.parse('${JSON.stringify(config)}'),
25
+ previewStyles: [${styles.join(',')}],
26
+ };
27
+ `;
28
+ }
29
+ export default function AdminDashboardPlugin({ config, previewStyles, identityWidget, }) {
30
+ return {
31
+ name: 'vite-plugin-decap-cms-admin-dashboard',
32
+ resolveId(id) {
33
+ if (id === virtualModuleId)
34
+ return resolvedVirtualModuleId;
35
+ },
36
+ load(id) {
37
+ if (id === resolvedVirtualModuleId)
38
+ return generateVirtualConfigModule({
39
+ config,
40
+ previewStyles,
41
+ identityWidget,
42
+ });
43
+ },
44
+ };
45
+ }
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@jee-r/astro-decap-cms",
3
+ "version": "0.6.0",
4
+ "description": "Add Decap CMS’s admin dashboard to your Astro project",
5
+ "repository": "jee-r/astro-decap-cms",
6
+ "homepage": "https://github.com/jee-r/astro-decap-cms",
7
+ "author": "jee-r",
8
+ "license": "MIT",
9
+ "type": "module",
10
+ "exports": {
11
+ ".": "./dist/index.js",
12
+ "./cms": "./dist/cms.js",
13
+ "./identity-widget": "./dist/identity-widget.js",
14
+ "./vite-plugin-admin-dashboard": "./dist/vite-plugin-admin-dashboard.js",
15
+ "./admin-dashboard.astro": "./admin-dashboard.astro"
16
+ },
17
+ "types": "./dist/index.d.ts",
18
+ "scripts": {
19
+ "prepack": "tsc",
20
+ "test:smoke": "tsc && cd demo && npm ci && npm run build",
21
+ "test": "npm run test:smoke"
22
+ },
23
+ "keywords": [
24
+ "astro-component",
25
+ "cms",
26
+ "astro",
27
+ "decap-cms",
28
+ "netlify-cms"
29
+ ],
30
+ "dependencies": {
31
+ "@types/react": "^17.0.50",
32
+ "decap-cms-app": "^3.0.0",
33
+ "decap-server": "^3.0.0",
34
+ "netlify-identity-widget": "^1.9.2",
35
+ "react": "^17.0.2",
36
+ "react-dom": "^17.0.2"
37
+ },
38
+ "peerDependencies": {
39
+ "astro": "^1.0.0 || ^2.0.0-beta || ^3.0.0-beta"
40
+ },
41
+ "devDependencies": {
42
+ "@changesets/changelog-github": "^0.4.7",
43
+ "@changesets/cli": "^2.25.0",
44
+ "astro": "^1.5.2"
45
+ }
46
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "target": "es6",
5
+ "moduleResolution": "node",
6
+ "outDir": "./dist",
7
+ "skipLibCheck": true
8
+ },
9
+ "include": ["integration/**/*.ts"]
10
+ }