create-sitecore-jss 20.0.0-canary.78
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 +202 -0
- package/dist/InitializerFactory.js +49 -0
- package/dist/common/Initializer.js +2 -0
- package/dist/common/args/base.js +2 -0
- package/dist/common/args/styleguide.js +2 -0
- package/dist/common/prompts/base.js +40 -0
- package/dist/common/prompts/styleguide.js +28 -0
- package/dist/common/steps/index.js +13 -0
- package/dist/common/steps/install.js +46 -0
- package/dist/common/steps/next.js +60 -0
- package/dist/common/steps/transform.js +185 -0
- package/dist/common/utils/cmd.js +39 -0
- package/dist/common/utils/helpers.js +92 -0
- package/dist/index.js +91 -0
- package/dist/init-runner.js +50 -0
- package/dist/initializers/nextjs/args.js +2 -0
- package/dist/initializers/nextjs/index.js +65 -0
- package/dist/initializers/nextjs/prompts.js +19 -0
- package/dist/initializers/nextjs/remove-dev-dependencies.js +24 -0
- package/dist/initializers/nextjs-styleguide/index.js +49 -0
- package/dist/templates/nextjs/.env +49 -0
- package/dist/templates/nextjs/.eslintrc +25 -0
- package/dist/templates/nextjs/.gitattributes +11 -0
- package/dist/templates/nextjs/.gitignore +33 -0
- package/dist/templates/nextjs/.graphql-let.yml +10 -0
- package/dist/templates/nextjs/.prettierignore +1 -0
- package/dist/templates/nextjs/.prettierrc +8 -0
- package/dist/templates/nextjs/LICENSE.txt +202 -0
- package/dist/templates/nextjs/README.md +3 -0
- package/dist/templates/nextjs/next-env.d.ts +6 -0
- package/dist/templates/nextjs/next.config.js +56 -0
- package/dist/templates/nextjs/package.json +88 -0
- package/dist/templates/nextjs/public/favicon.ico +0 -0
- package/dist/templates/nextjs/public/sc_logo.svg +20 -0
- package/dist/templates/nextjs/scripts/bootstrap.ts +40 -0
- package/dist/templates/nextjs/scripts/fetch-graphql-introspection-data.ts +49 -0
- package/dist/templates/nextjs/scripts/generate-component-factory.ts +95 -0
- package/dist/templates/nextjs/scripts/generate-config.ts +85 -0
- package/dist/templates/nextjs/scripts/generate-plugins.ts +103 -0
- package/dist/templates/nextjs/scripts/scaffold-component.ts +89 -0
- package/dist/templates/nextjs/scripts/templates/component-factory.ts +119 -0
- package/dist/templates/nextjs/scripts/templates/component-src.ts +27 -0
- package/dist/templates/nextjs/scripts/utils.ts +59 -0
- package/dist/templates/nextjs/sitecore/config/{{appName}}.config +151 -0
- package/dist/templates/nextjs/src/Layout.tsx +53 -0
- package/dist/templates/nextjs/src/Navigation.tsx +27 -0
- package/dist/templates/nextjs/src/NotFound.tsx +19 -0
- package/dist/templates/nextjs/src/assets/app.css +28 -0
- package/dist/templates/nextjs/src/components/ContentBlock.tsx +24 -0
- package/dist/templates/nextjs/src/lib/component-props/index.ts +23 -0
- package/dist/templates/nextjs/src/lib/data-fetcher.ts +16 -0
- package/dist/templates/nextjs/src/lib/dictionary-service-factory.ts +30 -0
- package/dist/templates/nextjs/src/lib/layout-service-factory.ts +25 -0
- package/dist/templates/nextjs/src/lib/next-config/plugins/graphql.js +32 -0
- package/dist/templates/nextjs/src/lib/next-config/plugins/monorepo.js +27 -0
- package/dist/templates/nextjs/src/lib/page-props-factory/index.ts +50 -0
- package/dist/templates/nextjs/src/lib/page-props-factory/plugins/componentProps.ts +38 -0
- package/dist/templates/nextjs/src/lib/page-props-factory/plugins/normalMode.ts +75 -0
- package/dist/templates/nextjs/src/lib/page-props-factory/plugins/previewMode.ts +27 -0
- package/dist/templates/nextjs/src/lib/page-props.ts +16 -0
- package/dist/templates/nextjs/src/lib/sitemap-fetcher/index.ts +25 -0
- package/dist/templates/nextjs/src/lib/sitemap-fetcher/plugins/graphqlSitemapService.ts +36 -0
- package/dist/templates/nextjs/src/pages/404.tsx +5 -0
- package/dist/templates/nextjs/src/pages/[[...path]].tsx +91 -0
- package/dist/templates/nextjs/src/pages/_app.tsx +19 -0
- package/dist/templates/nextjs/src/pages/_error.tsx +35 -0
- package/dist/templates/nextjs/src/pages/api/editing/data/[key].ts +24 -0
- package/dist/templates/nextjs/src/pages/api/editing/render.ts +30 -0
- package/dist/templates/nextjs/src/temp/.gitignore +3 -0
- package/dist/templates/nextjs/src/temp/GraphQLIntrospectionResult.json +22216 -0
- package/dist/templates/nextjs/tsconfig.json +42 -0
- package/dist/templates/nextjs/tsconfig.scripts.json +6 -0
- package/dist/templates/nextjs-styleguide/data/component-content/.gitignore +0 -0
- package/dist/templates/nextjs-styleguide/data/component-content/Styleguide/ContentReuse/LoremIpsumContentBlock/en.yml +9 -0
- package/dist/templates/nextjs-styleguide/data/content/.gitignore +0 -0
- package/dist/templates/nextjs-styleguide/data/content/Styleguide/ContentListField/Item1/en.yml +6 -0
- package/dist/templates/nextjs-styleguide/data/content/Styleguide/ContentListField/Item2/en.yml +6 -0
- package/dist/templates/nextjs-styleguide/data/content/Styleguide/ItemLinkField/Item1/en.yml +6 -0
- package/dist/templates/nextjs-styleguide/data/content/Styleguide/ItemLinkField/Item2/en.yml +6 -0
- package/dist/templates/nextjs-styleguide/data/dictionary/en.yml +4 -0
- package/dist/templates/nextjs-styleguide/data/dictionary/{{language}}.yml +4 -0
- package/dist/templates/nextjs-styleguide/data/media/files/jss.pdf +0 -0
- package/dist/templates/nextjs-styleguide/data/media/img/jss_logo.png +0 -0
- package/dist/templates/nextjs-styleguide/data/media/img/sc_logo.png +0 -0
- package/dist/templates/nextjs-styleguide/data/routes/en.yml +63 -0
- package/dist/templates/nextjs-styleguide/data/routes/graphql/en.yml +27 -0
- package/dist/templates/nextjs-styleguide/data/routes/graphql/sample-1/en.yml +9 -0
- package/dist/templates/nextjs-styleguide/data/routes/graphql/sample-2/en.yml +9 -0
- package/dist/templates/nextjs-styleguide/data/routes/styleguide/custom-route-type/en.yml +12 -0
- package/dist/templates/nextjs-styleguide/data/routes/styleguide/en.yml +246 -0
- package/dist/templates/nextjs-styleguide/data/routes/styleguide/{{language}}.yml +25 -0
- package/dist/templates/nextjs-styleguide/data/routes/{{language}}.yml +4 -0
- package/dist/templates/nextjs-styleguide/package.json +13 -0
- package/dist/templates/nextjs-styleguide/scripts/disconnected-mode-proxy.ts +48 -0
- package/dist/templates/nextjs-styleguide/scripts/scaffold-component.ts +130 -0
- package/dist/templates/nextjs-styleguide/scripts/templates/component-manifest.ts +30 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/component-content.sitecore.ts +117 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/ContentBlock.sitecore.ts +19 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Checkbox.sitecore.ts +23 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-ContentList.sitecore.ts +32 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Custom.sitecore.ts +23 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Date.sitecore.ts +23 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-File.sitecore.ts +20 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Image.sitecore.ts +23 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-ItemLink.sitecore.ts +32 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Link.sitecore.ts +25 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Number.sitecore.ts +20 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-RichText.sitecore.ts +28 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Text.sitecore.ts +28 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/graphql/GraphQL-ConnectedDemo.sitecore.ts +18 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/graphql/GraphQL-IntegratedDemo.sitecore.graphql +71 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/graphql/GraphQL-IntegratedDemo.sitecore.ts +25 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/graphql/GraphQL-Layout.sitecore.ts +15 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-ComponentParams.sitecore.ts +20 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-CustomRouteType.sitecore.ts +31 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Layout-Reuse.sitecore.ts +20 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Layout-Tabs-Tab.sitecore.ts +23 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Layout-Tabs.sitecore.ts +20 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Layout.sitecore.ts +15 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Multilingual.sitecore.ts +26 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-RouteFields.sitecore.ts +22 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Section.sitecore.ts +16 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-SitecoreContext.sitecore.ts +19 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Tracking.sitecore.ts +19 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/config.js +5 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/content.sitecore.ts +117 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/dictionary.sitecore.ts +52 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/placeholders.sitecore.ts +21 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/routes.sitecore.ts +88 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/templates/Styleguide-ContentList-Template.sitecore.ts +12 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/templates/Styleguide-Explanatory-Component.sitecore.ts +20 -0
- package/dist/templates/nextjs-styleguide/sitecore/definitions/templates/Styleguide-ItemLink-Template.sitecore.ts +13 -0
- package/dist/templates/nextjs-styleguide/src/Navigation.tsx +41 -0
- package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Checkbox.tsx +52 -0
- package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-ContentList.tsx +58 -0
- package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Custom.tsx +25 -0
- package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Date.tsx +55 -0
- package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-File.tsx +30 -0
- package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Image.tsx +58 -0
- package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-ItemLink.tsx +50 -0
- package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Link.tsx +46 -0
- package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Number.tsx +34 -0
- package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-RichText.tsx +35 -0
- package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Text.tsx +43 -0
- package/dist/templates/nextjs-styleguide/src/components/graphql/GraphQL-ConnectedDemo.dynamic.graphql +69 -0
- package/dist/templates/nextjs-styleguide/src/components/graphql/GraphQL-ConnectedDemo.dynamic.tsx +148 -0
- package/dist/templates/nextjs-styleguide/src/components/graphql/GraphQL-IntegratedDemo.tsx +130 -0
- package/dist/templates/nextjs-styleguide/src/components/graphql/GraphQL-Layout.tsx +37 -0
- package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-ComponentParams.tsx +47 -0
- package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-CustomRouteType.tsx +37 -0
- package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Layout-Reuse.tsx +45 -0
- package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Layout-Tabs-Tab.tsx +41 -0
- package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Layout-Tabs.tsx +111 -0
- package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Layout.tsx +68 -0
- package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Multilingual.tsx +50 -0
- package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-RouteFields.tsx +37 -0
- package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Section.tsx +22 -0
- package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-SitecoreContext.tsx +25 -0
- package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Specimen.tsx +41 -0
- package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Tracking.tsx +341 -0
- package/dist/templates/nextjs-styleguide/src/lib/component-props/styleguide.ts +11 -0
- package/dist/templates/nextjs-styleguide/src/lib/next-config/plugins/disconnected.js +43 -0
- package/dist/templates/nextjs-styleguide/src/lib/next-config/plugins/styleguide.js +10 -0
- package/dist/templates/nextjs-styleguide/src/lib/sitemap-fetcher/plugins/disconnectedSitemapService.ts +46 -0
- package/dist/templates/nextjs-styleguide/src/pages/_app.tsx +33 -0
- package/package.json +61 -0
package/LICENSE.MD
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.InitializerFactory = void 0;
|
|
35
|
+
const path_1 = __importDefault(require("path"));
|
|
36
|
+
class InitializerFactory {
|
|
37
|
+
create(name) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
try {
|
|
40
|
+
const { default: Initializer } = yield Promise.resolve().then(() => __importStar(require(path_1.default.resolve(__dirname, 'initializers', name, 'index'))));
|
|
41
|
+
return new Initializer();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.InitializerFactory = InitializerFactory;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.clientAppPrompts = exports.FetchWith = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
var FetchWith;
|
|
9
|
+
(function (FetchWith) {
|
|
10
|
+
FetchWith["GraphQL"] = "GraphQL";
|
|
11
|
+
FetchWith["REST"] = "REST";
|
|
12
|
+
})(FetchWith = exports.FetchWith || (exports.FetchWith = {}));
|
|
13
|
+
exports.clientAppPrompts = [
|
|
14
|
+
{
|
|
15
|
+
type: 'input',
|
|
16
|
+
name: 'appName',
|
|
17
|
+
message: 'What is the name of your app?',
|
|
18
|
+
default: 'sitecore-jss-app',
|
|
19
|
+
validate: (input) => {
|
|
20
|
+
if (!/^[a-z\-_.]+$/.test(input)) {
|
|
21
|
+
console.error(chalk_1.default.red(`${input} is not a valid name; you may use lowercase letters, hyphens, and underscores only.`));
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: 'input',
|
|
29
|
+
name: 'hostName',
|
|
30
|
+
message: 'What is your Sitecore hostname?',
|
|
31
|
+
default: 'https://cm.jss.localhost',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: 'list',
|
|
35
|
+
name: 'fetchWith',
|
|
36
|
+
message: 'How would you like to fetch Layout and Dictionary data?',
|
|
37
|
+
choices: Object.values(FetchWith),
|
|
38
|
+
default: FetchWith.GraphQL,
|
|
39
|
+
},
|
|
40
|
+
];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.styleguidePrompts = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const LANGUAGE_REGEXP = /^(([a-z]{2}-[A-Z]{2})|([a-z]{2}))$/;
|
|
9
|
+
exports.styleguidePrompts = [
|
|
10
|
+
{
|
|
11
|
+
type: 'input',
|
|
12
|
+
name: 'language',
|
|
13
|
+
message: 'Which additional language do you want to support (en is default and required)? Leave empty if not needed',
|
|
14
|
+
validate: (input) => {
|
|
15
|
+
if (!input)
|
|
16
|
+
return true;
|
|
17
|
+
if (!LANGUAGE_REGEXP.test(input)) {
|
|
18
|
+
console.error(chalk_1.default.red(`\n${input} is not a valid code; you may use language identifier, for example 'en',\nor you can add country code, for example 'US'. The language code is then 'en-US'.`));
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
else if (input === 'en') {
|
|
22
|
+
console.error(chalk_1.default.red(`\nen is included in the Styleguide by default. \nYou ${chalk_1.default.italic('may')} however add an en-* locale, for example 'en-UK'.`));
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformFilename = exports.transform = exports.merge = exports.diffFiles = exports.nextSteps = exports.lintFix = exports.installPackages = void 0;
|
|
4
|
+
var install_1 = require("./install");
|
|
5
|
+
Object.defineProperty(exports, "installPackages", { enumerable: true, get: function () { return install_1.installPackages; } });
|
|
6
|
+
Object.defineProperty(exports, "lintFix", { enumerable: true, get: function () { return install_1.lintFix; } });
|
|
7
|
+
var next_1 = require("./next");
|
|
8
|
+
Object.defineProperty(exports, "nextSteps", { enumerable: true, get: function () { return next_1.nextSteps; } });
|
|
9
|
+
var transform_1 = require("./transform");
|
|
10
|
+
Object.defineProperty(exports, "diffFiles", { enumerable: true, get: function () { return transform_1.diffFiles; } });
|
|
11
|
+
Object.defineProperty(exports, "merge", { enumerable: true, get: function () { return transform_1.merge; } });
|
|
12
|
+
Object.defineProperty(exports, "transform", { enumerable: true, get: function () { return transform_1.transform; } });
|
|
13
|
+
Object.defineProperty(exports, "transformFilename", { enumerable: true, get: function () { return transform_1.transformFilename; } });
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.lintFix = exports.installPackages = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const cmd_1 = require("../utils/cmd");
|
|
10
|
+
const helpers_1 = require("../utils/helpers");
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} projectFolder
|
|
13
|
+
* @param {boolean} [silent]
|
|
14
|
+
*/
|
|
15
|
+
const installPackages = (projectFolder, silent) => {
|
|
16
|
+
silent || console.log(chalk_1.default.cyan('Installing packages...'));
|
|
17
|
+
if (helpers_1.isDevEnvironment(projectFolder)) {
|
|
18
|
+
silent || console.log(chalk_1.default.yellow('Detected development environment.'));
|
|
19
|
+
cmd_1.run('yarn', ['install'], {
|
|
20
|
+
cwd: projectFolder,
|
|
21
|
+
encoding: 'utf8',
|
|
22
|
+
}, silent);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
cmd_1.run('npm', ['install'], {
|
|
26
|
+
cwd: projectFolder,
|
|
27
|
+
encoding: 'utf8',
|
|
28
|
+
}, silent);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.installPackages = installPackages;
|
|
32
|
+
/**
|
|
33
|
+
* @param {string} projectFolder
|
|
34
|
+
* @param {boolean} [silent]
|
|
35
|
+
*/
|
|
36
|
+
const lintFix = (projectFolder, silent) => {
|
|
37
|
+
var _a;
|
|
38
|
+
const packagePath = path_1.default.join(projectFolder, 'package.json');
|
|
39
|
+
const pkg = helpers_1.openPackageJson(packagePath);
|
|
40
|
+
if (!((_a = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _a === void 0 ? void 0 : _a.lint)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
silent || console.log(chalk_1.default.cyan('Linting app...'));
|
|
44
|
+
cmd_1.run('npm', ['run', 'lint', '--', '--fix'], { cwd: projectFolder, encoding: 'utf8' });
|
|
45
|
+
};
|
|
46
|
+
exports.lintFix = lintFix;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.nextSteps = void 0;
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const nextSteps = (appName, nextStepsArr) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
console.log(chalk_1.default.red(' -/oyhdmNNNNmdhyo/- '));
|
|
19
|
+
console.log(chalk_1.default.red(' :sdMMMMMMMMMMMMMMMMMMMMds: '));
|
|
20
|
+
console.log(chalk_1.default.red(' :yNMMMMMMMMMMMMMMMMMMMMMMMMMMNy: '));
|
|
21
|
+
console.log(chalk_1.default.red(' /mMMMMMMMMMNdyo+//://+shmMMMMMMMMMm/ '));
|
|
22
|
+
console.log(chalk_1.default.red(' :mMMMMMMMMh+. `:smMMMMMMMm: '));
|
|
23
|
+
console.log(chalk_1.default.red(' `yMMMMMMMm+` :yMMMMMMMs` '));
|
|
24
|
+
console.log(chalk_1.default.red(' `dMMMMMMN/ .hMMMMMMd` '));
|
|
25
|
+
console.log(chalk_1.default.red(' `mMMMMMMh` -s/+MMMMMMd` '));
|
|
26
|
+
console.log(chalk_1.default.red(' yMMMMMMh `:yNMMMs/MMMMMMy '));
|
|
27
|
+
console.log(chalk_1.default.red(' :MMMMMMm` `hMMMMMMMsoMMMMMM-'));
|
|
28
|
+
console.log(chalk_1.default.red(' yMMMMMM/ dMMMMMMM:mMMMMMy'));
|
|
29
|
+
console.log(chalk_1.default.red(' NMMMMMN` oMyossss:sMMMMMm'));
|
|
30
|
+
console.log(chalk_1.default.red(' MMMMMMN yM:NMMMMyoMMMMMN'));
|
|
31
|
+
console.log(chalk_1.default.red(' mMMMMMM` :Md+MMMMMoyMMMMMm'));
|
|
32
|
+
console.log(chalk_1.default.red(' yMMMMMM+ :NN+NMMMMM-NMMMMMy'));
|
|
33
|
+
console.log(chalk_1.default.red(' :MMMMMMN:- `sMdyMNymMMosMMMMMM-'));
|
|
34
|
+
console.log(chalk_1.default.red(' yMMMMMMd/o` .oNdhmMhhMmh++MMMMMMy '));
|
|
35
|
+
console.log(chalk_1.default.red(' `dMMMMMMm+do.- ./oyhhhNNhyNMMNosMMMMMMd` '));
|
|
36
|
+
console.log(chalk_1.default.red(' `dMMMMMMMssNdhsoo+/+oyyyydMmhhhMMMNs+mMMMMMMd` '));
|
|
37
|
+
console.log(chalk_1.default.red(' `yMMMMMMMNyydMNddddddddddhmMMMMho+dMMMMMMMy` '));
|
|
38
|
+
console.log(chalk_1.default.red(' :mMMMMMMMMmhhhdNMMMMMMMMmhssohMMMMMMMMm: '));
|
|
39
|
+
console.log(chalk_1.default.red(' /mMMMMMMMMMMNdhyyyyyyyhmMMMMMMMMMMm/ '));
|
|
40
|
+
console.log(chalk_1.default.red(' :yNMMMMMMMMMMMMMMMMMMMMMMMMMMNy: '));
|
|
41
|
+
console.log(chalk_1.default.red(' :sdMMMMMMMMMMMMMMMMMMMMds: '));
|
|
42
|
+
console.log(chalk_1.default.red(' `-/oyhdmNNNNmdhyo/- '));
|
|
43
|
+
console.log();
|
|
44
|
+
console.log(chalk_1.default.white(' __________'));
|
|
45
|
+
console.log(chalk_1.default.white(' __ / / __/ __/'));
|
|
46
|
+
console.log(chalk_1.default.white(' / // /\\ \\_\\ \\ '));
|
|
47
|
+
console.log(chalk_1.default.white(' \\___/___/___/'));
|
|
48
|
+
console.log();
|
|
49
|
+
console.log(`JSS application ${chalk_1.default.green(appName)} is ready!`);
|
|
50
|
+
console.log();
|
|
51
|
+
console.log(chalk_1.default.yellow('Next steps:'));
|
|
52
|
+
nextStepsArr.forEach((step) => {
|
|
53
|
+
console.log(step);
|
|
54
|
+
});
|
|
55
|
+
console.log('* Enable source control (i.e. git init) (optional)');
|
|
56
|
+
console.log('* Check out the JSS documentation at https://jss.sitecore.com');
|
|
57
|
+
console.log();
|
|
58
|
+
console.log(chalk_1.default.green('Enjoy!'));
|
|
59
|
+
});
|
|
60
|
+
exports.nextSteps = nextSteps;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.transform = exports.diffAndWriteFiles = exports.diffFiles = exports.merge = exports.transformFilename = void 0;
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
|
+
const glob_1 = __importDefault(require("glob"));
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const ejs_1 = require("ejs");
|
|
21
|
+
const inquirer_1 = require("inquirer");
|
|
22
|
+
const helpers_1 = require("../utils/helpers");
|
|
23
|
+
const diff_1 = require("diff");
|
|
24
|
+
const ASSET_REGEX = /\.(gif|jpg|jpeg|tiff|png|svg|ashx|ico|pdf)$/;
|
|
25
|
+
const transformFilename = (file, args) => {
|
|
26
|
+
// eslint-disable-next-line guard-for-in
|
|
27
|
+
for (const key in args) {
|
|
28
|
+
const value = args[key];
|
|
29
|
+
if (typeof value !== 'string')
|
|
30
|
+
continue;
|
|
31
|
+
file = file.replace(`{{${key}}}`, value);
|
|
32
|
+
}
|
|
33
|
+
return file;
|
|
34
|
+
};
|
|
35
|
+
exports.transformFilename = transformFilename;
|
|
36
|
+
const merge = (targetObj, sourceObj) => {
|
|
37
|
+
const mergeObject = (target, source) => {
|
|
38
|
+
for (const key of Object.keys(source)) {
|
|
39
|
+
const sourceVal = source[key];
|
|
40
|
+
const targetVal = target[key];
|
|
41
|
+
if (Array.isArray(targetVal) && Array.isArray(sourceVal)) {
|
|
42
|
+
// use Set to remove duplicates from arrays
|
|
43
|
+
target[key] = [...new Set([...targetVal, ...sourceVal])];
|
|
44
|
+
}
|
|
45
|
+
else if (!Array.isArray(targetVal) &&
|
|
46
|
+
!Array.isArray(sourceVal) &&
|
|
47
|
+
typeof targetVal === 'object' &&
|
|
48
|
+
typeof sourceVal === 'object') {
|
|
49
|
+
target[key] = helpers_1.sortKeys(mergeObject(targetVal, sourceVal));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
target[key] = sourceVal;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return target;
|
|
56
|
+
};
|
|
57
|
+
const result = JSON.stringify(mergeObject(targetObj, sourceObj), null, 2);
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
exports.merge = merge;
|
|
61
|
+
/**
|
|
62
|
+
* @param {string} sourceFileContent transformed version of our template
|
|
63
|
+
* @param {string} targetFilePath user's file path
|
|
64
|
+
*/
|
|
65
|
+
const diffFiles = (sourceFileContent, targetFilePath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
if (!fs_extra_1.default.pathExistsSync(targetFilePath))
|
|
67
|
+
return '';
|
|
68
|
+
const targetFileContents = fs_extra_1.default.readFileSync(path_1.default.resolve(process.cwd(), targetFilePath), 'utf8');
|
|
69
|
+
if (targetFileContents === sourceFileContent)
|
|
70
|
+
return '';
|
|
71
|
+
const diff = targetFilePath.endsWith('.json')
|
|
72
|
+
? diff_1.diffJson(JSON.parse(targetFileContents), JSON.parse(sourceFileContent))
|
|
73
|
+
: diff_1.diffLines(targetFileContents, sourceFileContent);
|
|
74
|
+
diff.forEach((change) => {
|
|
75
|
+
const color = change.added ? chalk_1.default.green : change.removed ? chalk_1.default.red : chalk_1.default.gray;
|
|
76
|
+
const prefix = change.added ? '+' : change.removed ? '-' : '=';
|
|
77
|
+
change.value.split('\n').forEach((value) => {
|
|
78
|
+
if (!value)
|
|
79
|
+
return;
|
|
80
|
+
console.log(color(`${prefix} ${value}`));
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
// TODO - enhancement: Write 'pagination' function that prints off
|
|
84
|
+
// only x lines and prints remaining x lines on user input.
|
|
85
|
+
// allow user to move forward and back like when piping to more in bash
|
|
86
|
+
// examples of more: https://shapeshed.com/unix-more/#what-is-the-more-command-in-unix
|
|
87
|
+
console.log(`Showing potential changes in ${chalk_1.default.yellow(targetFilePath.replace('/', '\\'))}`);
|
|
88
|
+
const answer = yield inquirer_1.prompt({
|
|
89
|
+
type: 'list',
|
|
90
|
+
name: 'choice',
|
|
91
|
+
choices: ['yes', 'skip', 'yes to all', 'abort'],
|
|
92
|
+
message: `File ${chalk_1.default.yellow(targetFilePath.replace('/', '\\'))} is about to be overwritten with the above changes. Are you sure you want to continue?`,
|
|
93
|
+
});
|
|
94
|
+
return answer.choice;
|
|
95
|
+
});
|
|
96
|
+
exports.diffFiles = diffFiles;
|
|
97
|
+
const diffAndWriteFiles = ({ rendered, pathToNewFile, destinationPath, answers, file, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
+
const choice = yield exports.diffFiles(rendered, exports.transformFilename(pathToNewFile, answers));
|
|
99
|
+
const destination = `${destinationPath}\\${exports.transformFilename(file, answers)}`;
|
|
100
|
+
switch (choice) {
|
|
101
|
+
case 'yes':
|
|
102
|
+
helpers_1.writeFileToPath(destination, rendered);
|
|
103
|
+
return;
|
|
104
|
+
case 'yes to all':
|
|
105
|
+
// set force to true so diff is not run again
|
|
106
|
+
answers.force = true;
|
|
107
|
+
helpers_1.writeFileToPath(destination, rendered);
|
|
108
|
+
return;
|
|
109
|
+
case 'skip':
|
|
110
|
+
return;
|
|
111
|
+
case 'abort':
|
|
112
|
+
console.log(chalk_1.default.yellow('Goodbye!'));
|
|
113
|
+
return process.exit();
|
|
114
|
+
// eslint-disable no-fallthrough
|
|
115
|
+
case '':
|
|
116
|
+
// writeFile to default case so that when an initializer is
|
|
117
|
+
// run for the first time, it will still copy files that
|
|
118
|
+
// do not return a diff.
|
|
119
|
+
helpers_1.writeFileToPath(destination, rendered);
|
|
120
|
+
return;
|
|
121
|
+
default:
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
exports.diffAndWriteFiles = diffAndWriteFiles;
|
|
126
|
+
const transform = (templatePath, answers, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
+
const destinationPath = path_1.default.resolve(answers.destination);
|
|
128
|
+
if (!answers.appPrefix) {
|
|
129
|
+
answers.appPrefix = false;
|
|
130
|
+
}
|
|
131
|
+
// pass in helper to answers object
|
|
132
|
+
const ejsData = Object.assign(Object.assign({}, answers), { helper: {
|
|
133
|
+
getPascalCaseName: helpers_1.getPascalCaseName,
|
|
134
|
+
getAppPrefix: helpers_1.getAppPrefix,
|
|
135
|
+
} });
|
|
136
|
+
// the templates to be run through ejs render or copied directly
|
|
137
|
+
// depending on the options.filter
|
|
138
|
+
const files = glob_1.default.sync('**/*', { cwd: templatePath, dot: true, nodir: true });
|
|
139
|
+
for (const file of files) {
|
|
140
|
+
try {
|
|
141
|
+
const pathToNewFile = `${destinationPath}\\${file}`;
|
|
142
|
+
const pathToTemplate = path_1.default.join(templatePath, file);
|
|
143
|
+
if (options.filter && !options.filter(pathToTemplate)) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
// holds the content to be written to the new file
|
|
147
|
+
let str;
|
|
148
|
+
// if the directory doesn't exist, create it
|
|
149
|
+
fs_extra_1.default.mkdirsSync(path_1.default.dirname(exports.transformFilename(pathToNewFile, answers)));
|
|
150
|
+
if (file.match(ASSET_REGEX)) {
|
|
151
|
+
// pdfs may have <% encoded, which throws an error for ejs.
|
|
152
|
+
// we simply want to copy file if it's a pdf, not render it with ejs.
|
|
153
|
+
fs_extra_1.default.copySync(pathToTemplate, pathToNewFile);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (file.endsWith('package.json') && fs_extra_1.default.existsSync(pathToNewFile)) {
|
|
157
|
+
// we treat package.json a bit differently
|
|
158
|
+
// read the current package.json and the partial (templatePkg)
|
|
159
|
+
// merge them and set the result to str which will then go through diff
|
|
160
|
+
// and use ejs render instead of renderFile
|
|
161
|
+
const currentPkg = helpers_1.openPackageJson(pathToNewFile);
|
|
162
|
+
const templatePkg = helpers_1.openPackageJson(pathToTemplate);
|
|
163
|
+
str = exports.merge(currentPkg, templatePkg);
|
|
164
|
+
}
|
|
165
|
+
str = str ? ejs_1.render(str, ejsData) : yield ejs_1.renderFile(path_1.default.resolve(pathToTemplate), ejsData);
|
|
166
|
+
if (!answers.force) {
|
|
167
|
+
yield exports.diffAndWriteFiles({
|
|
168
|
+
rendered: str,
|
|
169
|
+
pathToNewFile,
|
|
170
|
+
destinationPath,
|
|
171
|
+
answers,
|
|
172
|
+
file,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
helpers_1.writeFileToPath(`${destinationPath}\\${exports.transformFilename(file, answers)}`, str);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.log(chalk_1.default.red(error));
|
|
181
|
+
console.log(`Error occurred when trying to render to ${chalk_1.default.yellow(path_1.default.resolve(file))}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
exports.transform = transform;
|