@drupal-canvas/create 0.0.1 → 1.0.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/README.md +4 -3
- package/dist/index.js +52 -19
- package/package.json +1 -1
- package/templates.json +11 -3
package/README.md
CHANGED
|
@@ -30,9 +30,10 @@ npx @drupal-canvas/create@latest my-app
|
|
|
30
30
|
|
|
31
31
|
### Options
|
|
32
32
|
|
|
33
|
-
| Option | Description
|
|
34
|
-
| --------------- |
|
|
35
|
-
| `--template -t` | Template to use when scaffolding the app.
|
|
33
|
+
| Option | Description |
|
|
34
|
+
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
35
|
+
| `--template -t` | Template to use when scaffolding the app. One of the predefined templates (currently available: `canvas-cc-starter`) or URL to custom template's Git repository. |
|
|
36
|
+
| `--ref <ref>` | Custom Git ref to use when cloning the template repository. For example, a branch name or a tag. |
|
|
36
37
|
|
|
37
38
|
### Example
|
|
38
39
|
|
package/dist/index.js
CHANGED
|
@@ -12,18 +12,18 @@ import validate from 'validate-npm-package-name';
|
|
|
12
12
|
// templates.json
|
|
13
13
|
var templates_default = [
|
|
14
14
|
{
|
|
15
|
-
id: "
|
|
16
|
-
label: "
|
|
15
|
+
id: "acquia-nebula",
|
|
16
|
+
label: "acquia/nebula",
|
|
17
17
|
repository: {
|
|
18
|
-
url: "git@github.com:
|
|
18
|
+
url: "git@github.com:acquia/nebula.git",
|
|
19
19
|
ref: "main"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
id: "canvas-
|
|
24
|
-
label: "canvas-
|
|
23
|
+
id: "balintbrews-canvas-starter",
|
|
24
|
+
label: "balintbrews/canvas-starter",
|
|
25
25
|
repository: {
|
|
26
|
-
url: "git@github.com:balintbrews/canvas-
|
|
26
|
+
url: "git@github.com:balintbrews/canvas-starter.git",
|
|
27
27
|
ref: "main"
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -47,13 +47,15 @@ function detectPackageManager() {
|
|
|
47
47
|
// package.json
|
|
48
48
|
var package_default = {
|
|
49
49
|
name: "@drupal-canvas/create",
|
|
50
|
-
version: "0.0
|
|
50
|
+
version: "1.0.0",
|
|
51
51
|
description: "CLI to scaffold a codebase for working with Drupal Canvas Code Components"};
|
|
52
52
|
|
|
53
53
|
// src/lib/meta-info.ts
|
|
54
54
|
var getName = () => package_default.name;
|
|
55
55
|
var getDescription = () => package_default.description;
|
|
56
56
|
var getVersion = () => package_default.version;
|
|
57
|
+
var GIT_TERMINAL_PROMPT = 0;
|
|
58
|
+
var use_git_default = (baseDir) => simpleGit(baseDir).env({ ...process.env, GIT_TERMINAL_PROMPT });
|
|
57
59
|
|
|
58
60
|
// src/create.ts
|
|
59
61
|
async function createApp(ctx) {
|
|
@@ -61,14 +63,20 @@ async function createApp(ctx) {
|
|
|
61
63
|
try {
|
|
62
64
|
const s1 = p2.spinner();
|
|
63
65
|
s1.start("Fetching initial codebase");
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
+
const hasCommitSHARef = /^[a-f0-9]{40}$/i.test(template.repository.ref);
|
|
67
|
+
const git = use_git_default();
|
|
68
|
+
const options = {
|
|
66
69
|
"--depth": 1
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
await
|
|
70
|
+
};
|
|
71
|
+
if (template.repository.ref !== "HEAD" && !hasCommitSHARef) {
|
|
72
|
+
options["--branch"] = template.repository.ref;
|
|
73
|
+
}
|
|
74
|
+
await git.clone(template.repository.url, appName, options);
|
|
75
|
+
const gitAppDir = use_git_default(`${process.cwd()}/${appName}`);
|
|
76
|
+
if (hasCommitSHARef) {
|
|
77
|
+
await gitAppDir.fetch("origin", template.repository.ref);
|
|
78
|
+
await gitAppDir.checkout(template.repository.ref);
|
|
79
|
+
}
|
|
72
80
|
await rimraf(`${process.cwd()}/${appName}/.git`);
|
|
73
81
|
const packageJsonPath = join(process.cwd(), appName, "package.json");
|
|
74
82
|
const packageJsonContent = await readFile(packageJsonPath, "utf-8");
|
|
@@ -154,9 +162,12 @@ function validateName(name) {
|
|
|
154
162
|
process.on("SIGINT", () => process.exit(0));
|
|
155
163
|
process.on("SIGTERM", () => process.exit(0));
|
|
156
164
|
var program = new Command();
|
|
157
|
-
program.name(getName()).description(getDescription()).version(getVersion()).argument("[app-name]", "
|
|
165
|
+
program.name(getName()).description(getDescription()).version(getVersion()).argument("[app-name]", "name of the app to create").option(
|
|
158
166
|
"-t, --template <template>",
|
|
159
|
-
"
|
|
167
|
+
"use template when scaffolding (predefined name or custom Git repository URL)"
|
|
168
|
+
).option(
|
|
169
|
+
"-r, --ref <ref>",
|
|
170
|
+
"use Git ref when cloning template repository (for example, branch name or tag)"
|
|
160
171
|
).action(async (appNameArg, options) => {
|
|
161
172
|
p2.intro(chalk.bold("Drupal Canvas Create"));
|
|
162
173
|
try {
|
|
@@ -164,7 +175,26 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
|
|
|
164
175
|
const template2 = templates_default.find(
|
|
165
176
|
(t) => t.id === options.template
|
|
166
177
|
);
|
|
167
|
-
|
|
178
|
+
const isCustomRepositoryUrl = [
|
|
179
|
+
// Remote repositories.
|
|
180
|
+
"https://",
|
|
181
|
+
"http://",
|
|
182
|
+
"git@",
|
|
183
|
+
// Local repositories.
|
|
184
|
+
"../",
|
|
185
|
+
"./",
|
|
186
|
+
"/"
|
|
187
|
+
].some((prefix) => options.template?.startsWith(prefix));
|
|
188
|
+
if (!template2 && isCustomRepositoryUrl) {
|
|
189
|
+
templates_default.push({
|
|
190
|
+
id: options.template,
|
|
191
|
+
label: options.template,
|
|
192
|
+
repository: {
|
|
193
|
+
url: options.template,
|
|
194
|
+
ref: "HEAD"
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
} else if (!template2) {
|
|
168
198
|
p2.log.error(`Template "${options.template}" not found`);
|
|
169
199
|
process.exit(1);
|
|
170
200
|
}
|
|
@@ -202,9 +232,9 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
|
|
|
202
232
|
} else {
|
|
203
233
|
const selected = await p2.select({
|
|
204
234
|
message: "Select a template",
|
|
205
|
-
options: templates_default.map((t) => ({
|
|
235
|
+
options: templates_default.map((t, index) => ({
|
|
206
236
|
value: t.id,
|
|
207
|
-
label: t.label
|
|
237
|
+
label: index === 0 ? `${t.label} (Recommended)` : t.label
|
|
208
238
|
}))
|
|
209
239
|
});
|
|
210
240
|
if (p2.isCancel(selected)) {
|
|
@@ -217,6 +247,9 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
|
|
|
217
247
|
const template = templates_default.find(
|
|
218
248
|
(t) => t.id === templateId
|
|
219
249
|
);
|
|
250
|
+
if (options.ref) {
|
|
251
|
+
template.repository.ref = options.ref;
|
|
252
|
+
}
|
|
220
253
|
p2.note(`Template: ${template.label}
|
|
221
254
|
App name: ${appName}`);
|
|
222
255
|
await createApp({ template, appName });
|
package/package.json
CHANGED
package/templates.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
[
|
|
2
2
|
{
|
|
3
|
-
"id": "
|
|
4
|
-
"label": "
|
|
3
|
+
"id": "acquia-nebula",
|
|
4
|
+
"label": "acquia/nebula",
|
|
5
5
|
"repository": {
|
|
6
|
-
"url": "git@github.com:
|
|
6
|
+
"url": "git@github.com:acquia/nebula.git",
|
|
7
|
+
"ref": "main"
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"id": "balintbrews-canvas-starter",
|
|
12
|
+
"label": "balintbrews/canvas-starter",
|
|
13
|
+
"repository": {
|
|
14
|
+
"url": "git@github.com:balintbrews/canvas-starter.git",
|
|
7
15
|
"ref": "main"
|
|
8
16
|
}
|
|
9
17
|
}
|