@kitaris/emdash-environment-indicator 0.0.0-stage → 0.1.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.
package/LICENSE.md ADDED
@@ -0,0 +1,377 @@
1
+ block-layouts-js
2
+
3
+ Copyright (C) 2026 Built North
4
+
5
+ This program is free software; you can redistribute it and/or modify it under the terms of the
6
+ GNU General Public License as published by the Free Software Foundation; either version 2 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10
+ even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ General Public License for more details.
12
+
13
+ It bundles and builds on WordPress Gutenberg packages (@wordpress/*), which are
14
+ GPL-2.0-or-later. Copyright 2016-2026 by the Gutenberg contributors.
15
+
16
+ ---
17
+
18
+ ## GNU General Public License, Version 2
19
+
20
+ ### GNU GENERAL PUBLIC LICENSE
21
+
22
+ Version 2, June 1991
23
+
24
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
25
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26
+
27
+ Everyone is permitted to copy and distribute verbatim copies
28
+ of this license document, but changing it is not allowed.
29
+
30
+ ### Preamble
31
+
32
+ The licenses for most software are designed to take away your freedom
33
+ to share and change it. By contrast, the GNU General Public License is
34
+ intended to guarantee your freedom to share and change free
35
+ software--to make sure the software is free for all its users. This
36
+ General Public License applies to most of the Free Software
37
+ Foundation's software and to any other program whose authors commit to
38
+ using it. (Some other Free Software Foundation software is covered by
39
+ the GNU Lesser General Public License instead.) You can apply it to
40
+ your programs, too.
41
+
42
+ When we speak of free software, we are referring to freedom, not
43
+ price. Our General Public Licenses are designed to make sure that you
44
+ have the freedom to distribute copies of free software (and charge for
45
+ this service if you wish), that you receive source code or can get it
46
+ if you want it, that you can change the software or use pieces of it
47
+ in new free programs; and that you know you can do these things.
48
+
49
+ To protect your rights, we need to make restrictions that forbid
50
+ anyone to deny you these rights or to ask you to surrender the rights.
51
+ These restrictions translate to certain responsibilities for you if
52
+ you distribute copies of the software, or if you modify it.
53
+
54
+ For example, if you distribute copies of such a program, whether
55
+ gratis or for a fee, you must give the recipients all the rights that
56
+ you have. You must make sure that they, too, receive or can get the
57
+ source code. And you must show them these terms so they know their
58
+ rights.
59
+
60
+ We protect your rights with two steps: (1) copyright the software, and
61
+ (2) offer you this license which gives you legal permission to copy,
62
+ distribute and/or modify the software.
63
+
64
+ Also, for each author's protection and ours, we want to make certain
65
+ that everyone understands that there is no warranty for this free
66
+ software. If the software is modified by someone else and passed on,
67
+ we want its recipients to know that what they have is not the
68
+ original, so that any problems introduced by others will not reflect
69
+ on the original authors' reputations.
70
+
71
+ Finally, any free program is threatened constantly by software
72
+ patents. We wish to avoid the danger that redistributors of a free
73
+ program will individually obtain patent licenses, in effect making the
74
+ program proprietary. To prevent this, we have made it clear that any
75
+ patent must be licensed for everyone's free use or not licensed at
76
+ all.
77
+
78
+ The precise terms and conditions for copying, distribution and
79
+ modification follow.
80
+
81
+ ### TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
82
+
83
+ **0.** This License applies to any program or other work which
84
+ contains a notice placed by the copyright holder saying it may be
85
+ distributed under the terms of this General Public License. The
86
+ "Program", below, refers to any such program or work, and a "work
87
+ based on the Program" means either the Program or any derivative work
88
+ under copyright law: that is to say, a work containing the Program or
89
+ a portion of it, either verbatim or with modifications and/or
90
+ translated into another language. (Hereinafter, translation is
91
+ included without limitation in the term "modification".) Each licensee
92
+ is addressed as "you".
93
+
94
+ Activities other than copying, distribution and modification are not
95
+ covered by this License; they are outside its scope. The act of
96
+ running the Program is not restricted, and the output from the Program
97
+ is covered only if its contents constitute a work based on the Program
98
+ (independent of having been made by running the Program). Whether that
99
+ is true depends on what the Program does.
100
+
101
+ **1.** You may copy and distribute verbatim copies of the Program's
102
+ source code as you receive it, in any medium, provided that you
103
+ conspicuously and appropriately publish on each copy an appropriate
104
+ copyright notice and disclaimer of warranty; keep intact all the
105
+ notices that refer to this License and to the absence of any warranty;
106
+ and give any other recipients of the Program a copy of this License
107
+ along with the Program.
108
+
109
+ You may charge a fee for the physical act of transferring a copy, and
110
+ you may at your option offer warranty protection in exchange for a
111
+ fee.
112
+
113
+ **2.** You may modify your copy or copies of the Program or any
114
+ portion of it, thus forming a work based on the Program, and copy and
115
+ distribute such modifications or work under the terms of Section 1
116
+ above, provided that you also meet all of these conditions:
117
+
118
+ **a)** You must cause the modified files to carry prominent notices
119
+ stating that you changed the files and the date of any change.
120
+
121
+ **b)** You must cause any work that you distribute or publish, that in
122
+ whole or in part contains or is derived from the Program or any part
123
+ thereof, to be licensed as a whole at no charge to all third parties
124
+ under the terms of this License.
125
+
126
+ **c)** If the modified program normally reads commands interactively
127
+ when run, you must cause it, when started running for such interactive
128
+ use in the most ordinary way, to print or display an announcement
129
+ including an appropriate copyright notice and a notice that there is
130
+ no warranty (or else, saying that you provide a warranty) and that
131
+ users may redistribute the program under these conditions, and telling
132
+ the user how to view a copy of this License. (Exception: if the
133
+ Program itself is interactive but does not normally print such an
134
+ announcement, your work based on the Program is not required to print
135
+ an announcement.)
136
+
137
+ These requirements apply to the modified work as a whole. If
138
+ identifiable sections of that work are not derived from the Program,
139
+ and can be reasonably considered independent and separate works in
140
+ themselves, then this License, and its terms, do not apply to those
141
+ sections when you distribute them as separate works. But when you
142
+ distribute the same sections as part of a whole which is a work based
143
+ on the Program, the distribution of the whole must be on the terms of
144
+ this License, whose permissions for other licensees extend to the
145
+ entire whole, and thus to each and every part regardless of who wrote
146
+ it.
147
+
148
+ Thus, it is not the intent of this section to claim rights or contest
149
+ your rights to work written entirely by you; rather, the intent is to
150
+ exercise the right to control the distribution of derivative or
151
+ collective works based on the Program.
152
+
153
+ In addition, mere aggregation of another work not based on the Program
154
+ with the Program (or with a work based on the Program) on a volume of
155
+ a storage or distribution medium does not bring the other work under
156
+ the scope of this License.
157
+
158
+ **3.** You may copy and distribute the Program (or a work based on it,
159
+ under Section 2) in object code or executable form under the terms of
160
+ Sections 1 and 2 above provided that you also do one of the following:
161
+
162
+ **a)** Accompany it with the complete corresponding machine-readable
163
+ source code, which must be distributed under the terms of Sections 1
164
+ and 2 above on a medium customarily used for software interchange; or,
165
+
166
+ **b)** Accompany it with a written offer, valid for at least three
167
+ years, to give any third party, for a charge no more than your cost of
168
+ physically performing source distribution, a complete machine-readable
169
+ copy of the corresponding source code, to be distributed under the
170
+ terms of Sections 1 and 2 above on a medium customarily used for
171
+ software interchange; or,
172
+
173
+ **c)** Accompany it with the information you received as to the offer
174
+ to distribute corresponding source code. (This alternative is allowed
175
+ only for noncommercial distribution and only if you received the
176
+ program in object code or executable form with such an offer, in
177
+ accord with Subsection b above.)
178
+
179
+ The source code for a work means the preferred form of the work for
180
+ making modifications to it. For an executable work, complete source
181
+ code means all the source code for all modules it contains, plus any
182
+ associated interface definition files, plus the scripts used to
183
+ control compilation and installation of the executable. However, as a
184
+ special exception, the source code distributed need not include
185
+ anything that is normally distributed (in either source or binary
186
+ form) with the major components (compiler, kernel, and so on) of the
187
+ operating system on which the executable runs, unless that component
188
+ itself accompanies the executable.
189
+
190
+ If distribution of executable or object code is made by offering
191
+ access to copy from a designated place, then offering equivalent
192
+ access to copy the source code from the same place counts as
193
+ distribution of the source code, even though third parties are not
194
+ compelled to copy the source along with the object code.
195
+
196
+ **4.** You may not copy, modify, sublicense, or distribute the Program
197
+ except as expressly provided under this License. Any attempt otherwise
198
+ to copy, modify, sublicense or distribute the Program is void, and
199
+ will automatically terminate your rights under this License. However,
200
+ parties who have received copies, or rights, from you under this
201
+ License will not have their licenses terminated so long as such
202
+ parties remain in full compliance.
203
+
204
+ **5.** You are not required to accept this License, since you have not
205
+ signed it. However, nothing else grants you permission to modify or
206
+ distribute the Program or its derivative works. These actions are
207
+ prohibited by law if you do not accept this License. Therefore, by
208
+ modifying or distributing the Program (or any work based on the
209
+ Program), you indicate your acceptance of this License to do so, and
210
+ all its terms and conditions for copying, distributing or modifying
211
+ the Program or works based on it.
212
+
213
+ **6.** Each time you redistribute the Program (or any work based on
214
+ the Program), the recipient automatically receives a license from the
215
+ original licensor to copy, distribute or modify the Program subject to
216
+ these terms and conditions. You may not impose any further
217
+ restrictions on the recipients' exercise of the rights granted herein.
218
+ You are not responsible for enforcing compliance by third parties to
219
+ this License.
220
+
221
+ **7.** If, as a consequence of a court judgment or allegation of
222
+ patent infringement or for any other reason (not limited to patent
223
+ issues), conditions are imposed on you (whether by court order,
224
+ agreement or otherwise) that contradict the conditions of this
225
+ License, they do not excuse you from the conditions of this License.
226
+ If you cannot distribute so as to satisfy simultaneously your
227
+ obligations under this License and any other pertinent obligations,
228
+ then as a consequence you may not distribute the Program at all. For
229
+ example, if a patent license would not permit royalty-free
230
+ redistribution of the Program by all those who receive copies directly
231
+ or indirectly through you, then the only way you could satisfy both it
232
+ and this License would be to refrain entirely from distribution of the
233
+ Program.
234
+
235
+ If any portion of this section is held invalid or unenforceable under
236
+ any particular circumstance, the balance of the section is intended to
237
+ apply and the section as a whole is intended to apply in other
238
+ circumstances.
239
+
240
+ It is not the purpose of this section to induce you to infringe any
241
+ patents or other property right claims or to contest validity of any
242
+ such claims; this section has the sole purpose of protecting the
243
+ integrity of the free software distribution system, which is
244
+ implemented by public license practices. Many people have made
245
+ generous contributions to the wide range of software distributed
246
+ through that system in reliance on consistent application of that
247
+ system; it is up to the author/donor to decide if he or she is willing
248
+ to distribute software through any other system and a licensee cannot
249
+ impose that choice.
250
+
251
+ This section is intended to make thoroughly clear what is believed to
252
+ be a consequence of the rest of this License.
253
+
254
+ **8.** If the distribution and/or use of the Program is restricted in
255
+ certain countries either by patents or by copyrighted interfaces, the
256
+ original copyright holder who places the Program under this License
257
+ may add an explicit geographical distribution limitation excluding
258
+ those countries, so that distribution is permitted only in or among
259
+ countries not thus excluded. In such case, this License incorporates
260
+ the limitation as if written in the body of this License.
261
+
262
+ **9.** The Free Software Foundation may publish revised and/or new
263
+ versions of the General Public License from time to time. Such new
264
+ versions will be similar in spirit to the present version, but may
265
+ differ in detail to address new problems or concerns.
266
+
267
+ Each version is given a distinguishing version number. If the Program
268
+ specifies a version number of this License which applies to it and
269
+ "any later version", you have the option of following the terms and
270
+ conditions either of that version or of any later version published by
271
+ the Free Software Foundation. If the Program does not specify a
272
+ version number of this License, you may choose any version ever
273
+ published by the Free Software Foundation.
274
+
275
+ **10.** If you wish to incorporate parts of the Program into other
276
+ free programs whose distribution conditions are different, write to
277
+ the author to ask for permission. For software which is copyrighted by
278
+ the Free Software Foundation, write to the Free Software Foundation;
279
+ we sometimes make exceptions for this. Our decision will be guided by
280
+ the two goals of preserving the free status of all derivatives of our
281
+ free software and of promoting the sharing and reuse of software
282
+ generally.
283
+
284
+ **NO WARRANTY**
285
+
286
+ **11.** BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
287
+ WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
288
+ EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
289
+ OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
290
+ KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
291
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
292
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
293
+ PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
294
+ THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
295
+
296
+ **12.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
297
+ WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
298
+ AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU
299
+ FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
300
+ CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
301
+ PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
302
+ RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
303
+ FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF
304
+ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
305
+ DAMAGES.
306
+
307
+ ### END OF TERMS AND CONDITIONS
308
+
309
+ ### How to Apply These Terms to Your New Programs
310
+
311
+ If you develop a new program, and you want it to be of the greatest
312
+ possible use to the public, the best way to achieve this is to make it
313
+ free software which everyone can redistribute and change under these
314
+ terms.
315
+
316
+ To do so, attach the following notices to the program. It is safest to
317
+ attach them to the start of each source file to most effectively
318
+ convey the exclusion of warranty; and each file should have at least
319
+ the "copyright" line and a pointer to where the full notice is found.
320
+
321
+ one line to give the program's name and an idea of what it does.
322
+ Copyright (C) yyyy name of author
323
+
324
+ This program is free software; you can redistribute it and/or
325
+ modify it under the terms of the GNU General Public License
326
+ as published by the Free Software Foundation; either version 2
327
+ of the License, or (at your option) any later version.
328
+
329
+ This program is distributed in the hope that it will be useful,
330
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
331
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
332
+ GNU General Public License for more details.
333
+
334
+ You should have received a copy of the GNU General Public License
335
+ along with this program; if not, write to the Free Software
336
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
337
+
338
+ Also add information on how to contact you by electronic and paper
339
+ mail.
340
+
341
+ If the program is interactive, make it output a short notice like this
342
+ when it starts in an interactive mode:
343
+
344
+ Gnomovision version 69, Copyright (C) year name of author
345
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
346
+ type `show w'. This is free software, and you are welcome
347
+ to redistribute it under certain conditions; type `show c'
348
+ for details.
349
+
350
+ The hypothetical commands \`show w' and \`show c' should show the
351
+ appropriate parts of the General Public License. Of course, the
352
+ commands you use may be called something other than \`show w' and
353
+ \`show c'; they could even be mouse-clicks or menu items--whatever
354
+ suits your program.
355
+
356
+ You should also get your employer (if you work as a programmer) or
357
+ your school, if any, to sign a "copyright disclaimer" for the program,
358
+ if necessary. Here is a sample; alter the names:
359
+
360
+ Yoyodyne, Inc., hereby disclaims all copyright
361
+ interest in the program `Gnomovision'
362
+ (which makes passes at compilers) written
363
+ by James Hacker.
364
+
365
+ signature of Ty Coon, 1 April 1989
366
+ Ty Coon, President of Vice
367
+
368
+ This General Public License does not permit incorporating your program
369
+ into proprietary programs. If your program is a subroutine library,
370
+ you may consider it more useful to permit linking proprietary
371
+ applications with the library. If this is what you want to do, use the
372
+ [GNU Lesser General Public
373
+ License](http://www.gnu.org/licenses/lgpl.html) instead of this
374
+ License.
375
+
376
+ ---
377
+
package/README.md CHANGED
@@ -1,3 +1,33 @@
1
- # Temporary Holding Version
1
+ # @kitaris/emdash-environment-indicator
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An [EmDash](https://github.com/emdash-cms/emdash) plugin that shows which environment a site is on the
4
+ dashboard: **Development**, **Staging** or **Production**, so nobody edits the live site thinking it's
5
+ staging (or the other way round).
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ pnpm add @kitaris/emdash-environment-indicator
11
+ ```
12
+
13
+ ```js
14
+ // astro.config.mjs
15
+ import { environmentIndicator } from "@kitaris/emdash-environment-indicator";
16
+
17
+ emdash({
18
+ // ...
19
+ plugins: [environmentIndicator()],
20
+ });
21
+ ```
22
+
23
+ ## How it knows
24
+
25
+ 1. **`EMDASH_ENVIRONMENT`**, if the deployment sets it: `development` (or `dev`, `local`), `staging`
26
+ (`stage`, `preview`) or `production` (`prod`, `live`). Read when the plugin runs in-process.
27
+ 2. Otherwise **the site's hostname**, against the hostnames in the plugin's settings (Plugins →
28
+ environment-indicator → Settings): production first, then staging, then development. One per line;
29
+ `*` matches any part, e.g. `*.staging.example.com`.
30
+ 3. Local hostnames (`localhost`, `127.0.0.1`, `*.localhost`, `*.local`, `*.test`) are development.
31
+ 4. Anything else is production.
32
+
33
+ The widget says how it decided, e.g. "From the hostname staging.example.com, in the plugin's settings."
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Which environment a site is running in: development, staging or production. From an explicit
3
+ * variable when the deployment sets one (EMDASH_ENVIRONMENT), else from the site's hostname: the
4
+ * hostnames configured for each environment, then common local ones, else production.
5
+ *
6
+ * Plain data, no dependencies.
7
+ */
8
+ export type Environment = "development" | "staging" | "production";
9
+ export interface HostRules {
10
+ development?: string;
11
+ staging?: string;
12
+ production?: string;
13
+ }
14
+ export interface Detection {
15
+ environment: Environment;
16
+ /** How it was decided, for the widget to say. */
17
+ source: "variable" | "hostname" | "local hostname" | "default";
18
+ /** What matched: the variable's value, or the hostname pattern. Absent for "default". */
19
+ match?: string;
20
+ }
21
+ /** Hostnames that are local unless configured otherwise. */
22
+ export declare const LOCAL_HOSTS: string[];
23
+ /** An environment named in the variable, or undefined (unset or not a name it knows). */
24
+ export declare function environmentFromVariable(value: string | undefined): Environment | undefined;
25
+ /** Hostname patterns from a setting: one per line or comma separated; `*` matches any part. */
26
+ export declare function parsePatterns(value: string | undefined): string[];
27
+ /** Whether a hostname matches a pattern such as `staging.example.com` or `*.staging.example.com`. */
28
+ export declare function matchesHost(hostname: string, pattern: string): boolean;
29
+ /**
30
+ * The environment, from the variable if it names one, else the hostname: configured production, then
31
+ * staging, then development hostnames, then common local ones; anything else is production.
32
+ */
33
+ export declare function detectEnvironment({ variable, hostname, rules }: {
34
+ variable?: string;
35
+ hostname: string;
36
+ rules?: HostRules;
37
+ }): Detection;
38
+ //# sourceMappingURL=detect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG,SAAS,GAAG,YAAY,CAAC;AAEnE,MAAM,WAAW,SAAS;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACzB,WAAW,EAAE,WAAW,CAAC;IACzB,iDAAiD;IACjD,MAAM,EAAE,UAAU,GAAG,UAAU,GAAG,gBAAgB,GAAG,SAAS,CAAC;IAC/D,yFAAyF;IACzF,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,4DAA4D;AAC5D,eAAO,MAAM,WAAW,UAA0E,CAAC;AAenG,yFAAyF;AACzF,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAE1F;AAED,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAKjE;AAED,qGAAqG;AACrG,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAGtE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAU,EAAE,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,CAAA;CAAE,GAAG,SAAS,CAW3I"}
package/dist/detect.js ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Which environment a site is running in: development, staging or production. From an explicit
3
+ * variable when the deployment sets one (EMDASH_ENVIRONMENT), else from the site's hostname: the
4
+ * hostnames configured for each environment, then common local ones, else production.
5
+ *
6
+ * Plain data, no dependencies.
7
+ */
8
+ /** Hostnames that are local unless configured otherwise. */
9
+ export const LOCAL_HOSTS = ["localhost", "127.0.0.1", "[::1]", "*.localhost", "*.local", "*.test"];
10
+ /** The values the variable accepts for each environment. */
11
+ const ALIASES = {
12
+ development: "development",
13
+ dev: "development",
14
+ local: "development",
15
+ staging: "staging",
16
+ stage: "staging",
17
+ preview: "staging",
18
+ production: "production",
19
+ prod: "production",
20
+ live: "production",
21
+ };
22
+ /** An environment named in the variable, or undefined (unset or not a name it knows). */
23
+ export function environmentFromVariable(value) {
24
+ return value ? ALIASES[value.trim().toLowerCase()] : undefined;
25
+ }
26
+ /** Hostname patterns from a setting: one per line or comma separated; `*` matches any part. */
27
+ export function parsePatterns(value) {
28
+ return (value ?? "")
29
+ .split(/[\n,]/)
30
+ .map((pattern) => pattern.trim().toLowerCase())
31
+ .filter(Boolean);
32
+ }
33
+ /** Whether a hostname matches a pattern such as `staging.example.com` or `*.staging.example.com`. */
34
+ export function matchesHost(hostname, pattern) {
35
+ const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^.]+(?:\\.[^.]+)*");
36
+ return new RegExp(`^${escaped}$`, "i").test(hostname);
37
+ }
38
+ /**
39
+ * The environment, from the variable if it names one, else the hostname: configured production, then
40
+ * staging, then development hostnames, then common local ones; anything else is production.
41
+ */
42
+ export function detectEnvironment({ variable, hostname, rules = {} }) {
43
+ const named = environmentFromVariable(variable);
44
+ if (named && variable)
45
+ return { environment: named, source: "variable", match: variable.trim() };
46
+ const host = hostname.toLowerCase();
47
+ for (const environment of ["production", "staging", "development"]) {
48
+ const match = parsePatterns(rules[environment]).find((pattern) => matchesHost(host, pattern));
49
+ if (match)
50
+ return { environment, source: "hostname", match };
51
+ }
52
+ const local = LOCAL_HOSTS.find((pattern) => matchesHost(host, pattern));
53
+ if (local)
54
+ return { environment: "development", source: "local hostname", match: local };
55
+ return { environment: "production", source: "default" };
56
+ }
57
+ //# sourceMappingURL=detect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,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C;AACvD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,GAAG,EAAE,EAA8D;IAC/H,MAAM,KAAK,GAAG,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAChD,IAAI,KAAK,IAAI,QAAQ;QAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;IACjG,MAAM,IAAI,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IACpC,KAAK,MAAM,WAAW,IAAI,CAAC,YAAY,EAAE,SAAS,EAAE,aAAa,CAAU,EAAE,CAAC;QAC7E,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;QAC9F,IAAI,KAAK;YAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC9D,CAAC;IACD,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IACxE,IAAI,KAAK;QAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IACzF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AACzD,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { PluginDescriptor } from "emdash";
2
+ export declare const PLUGIN_ID = "environment-indicator";
3
+ /**
4
+ * Shows which environment the site is (development, staging or production) on the EmDash dashboard.
5
+ * Add to `emdash({ plugins: [environmentIndicator()] })`. Set `EMDASH_ENVIRONMENT` on each deployment,
6
+ * or list each environment's hostnames in the plugin's settings.
7
+ */
8
+ export declare function environmentIndicator(): PluginDescriptor;
9
+ export { detectEnvironment, type Detection, type Environment } from "./detect.ts";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAE/C,eAAO,MAAM,SAAS,0BAA0B,CAAC;AAEjD;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,gBAAgB,CA4BvD;AAED,OAAO,EAAE,iBAAiB,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ export const PLUGIN_ID = "environment-indicator";
2
+ /**
3
+ * Shows which environment the site is (development, staging or production) on the EmDash dashboard.
4
+ * Add to `emdash({ plugins: [environmentIndicator()] })`. Set `EMDASH_ENVIRONMENT` on each deployment,
5
+ * or list each environment's hostnames in the plugin's settings.
6
+ */
7
+ export function environmentIndicator() {
8
+ return {
9
+ id: PLUGIN_ID,
10
+ version: "0.0.0",
11
+ format: "standard",
12
+ entrypoint: "@kitaris/emdash-environment-indicator/plugin",
13
+ adminWidgets: [{ id: "environment", title: "Environment", size: "full" }],
14
+ settingsSchema: {
15
+ stagingHosts: {
16
+ type: "string",
17
+ label: "Staging hostnames",
18
+ description: "One per line. * matches any part, e.g. staging.example.com or *.staging.example.com.",
19
+ multiline: true,
20
+ },
21
+ productionHosts: {
22
+ type: "string",
23
+ label: "Production hostnames",
24
+ description: "One per line. Anything not listed as development or staging is taken as production anyway.",
25
+ multiline: true,
26
+ },
27
+ developmentHosts: {
28
+ type: "string",
29
+ label: "Development hostnames",
30
+ description: "One per line, besides local ones (localhost, *.local, *.test, ...), which are always development.",
31
+ multiline: true,
32
+ },
33
+ },
34
+ };
35
+ }
36
+ export { detectEnvironment } from "./detect.js";
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAG,uBAAuB,CAAC;AAEjD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB;IACnC,OAAO;QACN,EAAE,EAAE,SAAS;QACb,OAAO,EAAE,OAAO;QAChB,MAAM,EAAE,UAAU;QAClB,UAAU,EAAE,8CAA8C;QAC1D,YAAY,EAAE,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QACzE,cAAc,EAAE;YACf,YAAY,EAAE;gBACb,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,mBAAmB;gBAC1B,WAAW,EAAE,sFAAsF;gBACnG,SAAS,EAAE,IAAI;aACf;YACD,eAAe,EAAE;gBAChB,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,sBAAsB;gBAC7B,WAAW,EAAE,4FAA4F;gBACzG,SAAS,EAAE,IAAI;aACf;YACD,gBAAgB,EAAE;gBACjB,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,uBAAuB;gBAC9B,WAAW,EAAE,mGAAmG;gBAChH,SAAS,EAAE,IAAI;aACf;SACD;KACD,CAAC;AACH,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAoC,MAAM,aAAa,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { SandboxedPlugin } from "emdash/plugin";
2
+ /**
3
+ * The plugin: a dashboard widget saying which environment the site is (Block Kit, so it also runs
4
+ * sandboxed). Hostname rules come from the plugin's settings.
5
+ */
6
+ declare const plugin: SandboxedPlugin;
7
+ export default plugin;
8
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAUrD;;;GAGG;AACH,QAAA,MAAM,MAAM,EAAE,eAgBb,CAAC;AAEF,eAAe,MAAM,CAAC"}
package/dist/plugin.js ADDED
@@ -0,0 +1,31 @@
1
+ import { detectEnvironment } from "./detect.js";
2
+ import { environmentWidget } from "./widget.js";
3
+ /** The deployment's variable, where the plugin can read it (in-process; sandboxed plugins can't). */
4
+ function variable() {
5
+ const env = globalThis.process?.env;
6
+ return env?.EMDASH_ENVIRONMENT;
7
+ }
8
+ /**
9
+ * The plugin: a dashboard widget saying which environment the site is (Block Kit, so it also runs
10
+ * sandboxed). Hostname rules come from the plugin's settings.
11
+ */
12
+ const plugin = {
13
+ routes: {
14
+ admin: {
15
+ handler: async (routeCtx, ctx) => {
16
+ const input = routeCtx.input;
17
+ if (input?.type !== "page_load" || input.page !== "widget:environment")
18
+ return { blocks: [] };
19
+ const hostname = new URL(routeCtx.request.url).hostname;
20
+ const rules = {
21
+ development: (await ctx.settings.get("developmentHosts")) ?? undefined,
22
+ staging: (await ctx.settings.get("stagingHosts")) ?? undefined,
23
+ production: (await ctx.settings.get("productionHosts")) ?? undefined,
24
+ };
25
+ return { blocks: environmentWidget(detectEnvironment({ variable: variable(), hostname, rules }), hostname) };
26
+ },
27
+ },
28
+ },
29
+ };
30
+ export default plugin;
31
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAkB,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,qGAAqG;AACrG,SAAS,QAAQ;IAChB,MAAM,GAAG,GAAI,UAAyE,CAAC,OAAO,EAAE,GAAG,CAAC;IACpG,OAAO,GAAG,EAAE,kBAAkB,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,MAAM,MAAM,GAAoB;IAC/B,MAAM,EAAE;QACP,KAAK,EAAE;YACN,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE;gBAChC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAqD,CAAC;gBAC7E,IAAI,KAAK,EAAE,IAAI,KAAK,WAAW,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB;oBAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;gBAC9F,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;gBACxD,MAAM,KAAK,GAAc;oBACxB,WAAW,EAAE,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAS,kBAAkB,CAAC,CAAC,IAAI,SAAS;oBAC9E,OAAO,EAAE,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAS,cAAc,CAAC,CAAC,IAAI,SAAS;oBACtE,UAAU,EAAE,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAS,iBAAiB,CAAC,CAAC,IAAI,SAAS;iBAC5E,CAAC;gBACF,OAAO,EAAE,MAAM,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC;YAC9G,CAAC;SACD;KACD;CACD,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Block } from "@emdash-cms/blocks";
2
+ import type { Detection } from "./detect.ts";
3
+ /** The dashboard widget: which environment this is, and how that was decided. */
4
+ export declare function environmentWidget(detection: Detection, hostname: string): Block[];
5
+ //# sourceMappingURL=widget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,aAAa,CAAC;AA4B1D,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,EAAE,CAKjF"}
package/dist/widget.js ADDED
@@ -0,0 +1,30 @@
1
+ const TITLES = { development: "Development", staging: "Staging", production: "Production" };
2
+ const DESCRIPTIONS = {
3
+ development: "Local build. Nothing you do here reaches the live site.",
4
+ staging: "Pre-release copy for testing before you deploy.",
5
+ production: "Live site. Published changes are public immediately.",
6
+ };
7
+ /** Banner variants by environment: production stands out, as the one to be careful with. */
8
+ const VARIANTS = { development: "default", staging: "alert", production: "error" };
9
+ /** How the environment was decided, for developers: what matched, and where to change it. */
10
+ function sourceText({ environment, source, match }, host) {
11
+ const matched = (where) => (match && match !== host ? `${host} matched ${match} in ${where}.` : `${host} is in ${where}.`);
12
+ switch (source) {
13
+ case "variable":
14
+ return `Set by EMDASH_ENVIRONMENT=${match}.`;
15
+ case "hostname":
16
+ return matched(`${TITLES[environment]} hostnames`);
17
+ case "local hostname":
18
+ return matched("the common local hostnames");
19
+ case "default":
20
+ return `${host} matched no rule, so it defaults to production. Set EMDASH_ENVIRONMENT or add the hostname in the plugin's settings.`;
21
+ }
22
+ }
23
+ /** The dashboard widget: which environment this is, and how that was decided. */
24
+ export function environmentWidget(detection, hostname) {
25
+ return [
26
+ { type: "banner", title: TITLES[detection.environment], description: DESCRIPTIONS[detection.environment], variant: VARIANTS[detection.environment] },
27
+ { type: "context", text: sourceText(detection, hostname) },
28
+ ];
29
+ }
30
+ //# sourceMappingURL=widget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget.js","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,GAAgC,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,SAA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,EAAE,UAAU,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE;KAC1D,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@kitaris/emdash-environment-indicator",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "An EmDash plugin that shows which environment a site is (development, staging or production) on the dashboard.",
5
+ "license": "GPL-2.0-or-later",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/builtnorth/emdash-plugins.git",
9
+ "directory": "packages/environment-indicator"
10
+ },
11
+ "keywords": [
12
+ "emdash",
13
+ "emdash-plugin",
14
+ "environment",
15
+ "staging"
16
+ ],
17
+ "type": "module",
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "default": "./dist/index.js"
25
+ },
26
+ "./plugin": {
27
+ "types": "./dist/plugin.d.ts",
28
+ "default": "./dist/plugin.js"
29
+ }
30
+ },
31
+ "peerDependencies": {
32
+ "@emdash-cms/blocks": "^1.3.0",
33
+ "emdash": "^1.3.0"
34
+ },
35
+ "devDependencies": {
36
+ "@emdash-cms/blocks": "1.3.1",
37
+ "emdash": "1.3.1"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "scripts": {
43
+ "build": "node ../../scripts/build-package.mjs",
44
+ "test": "vitest run",
45
+ "typecheck": "tsc -p ."
46
+ }
6
47
  }