@drupal-canvas/create 0.0.1 → 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/README.md +4 -3
- package/dist/index.js +44 -19
- package/package.json +1 -1
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
|
@@ -18,14 +18,6 @@ var templates_default = [
|
|
|
18
18
|
url: "git@github.com:balintbrews/canvas-cc-starter.git",
|
|
19
19
|
ref: "main"
|
|
20
20
|
}
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
id: "canvas-cc-starter-2",
|
|
24
|
-
label: "canvas-cc-starter-2",
|
|
25
|
-
repository: {
|
|
26
|
-
url: "git@github.com:balintbrews/canvas-cc-starter.git",
|
|
27
|
-
ref: "main"
|
|
28
|
-
}
|
|
29
21
|
}
|
|
30
22
|
];
|
|
31
23
|
|
|
@@ -47,13 +39,15 @@ function detectPackageManager() {
|
|
|
47
39
|
// package.json
|
|
48
40
|
var package_default = {
|
|
49
41
|
name: "@drupal-canvas/create",
|
|
50
|
-
version: "0.0
|
|
42
|
+
version: "0.1.0",
|
|
51
43
|
description: "CLI to scaffold a codebase for working with Drupal Canvas Code Components"};
|
|
52
44
|
|
|
53
45
|
// src/lib/meta-info.ts
|
|
54
46
|
var getName = () => package_default.name;
|
|
55
47
|
var getDescription = () => package_default.description;
|
|
56
48
|
var getVersion = () => package_default.version;
|
|
49
|
+
var GIT_TERMINAL_PROMPT = 0;
|
|
50
|
+
var use_git_default = (baseDir) => simpleGit(baseDir).env({ ...process.env, GIT_TERMINAL_PROMPT });
|
|
57
51
|
|
|
58
52
|
// src/create.ts
|
|
59
53
|
async function createApp(ctx) {
|
|
@@ -61,14 +55,20 @@ async function createApp(ctx) {
|
|
|
61
55
|
try {
|
|
62
56
|
const s1 = p2.spinner();
|
|
63
57
|
s1.start("Fetching initial codebase");
|
|
64
|
-
const
|
|
65
|
-
|
|
58
|
+
const hasCommitSHARef = /^[a-f0-9]{40}$/i.test(template.repository.ref);
|
|
59
|
+
const git = use_git_default();
|
|
60
|
+
const options = {
|
|
66
61
|
"--depth": 1
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
await
|
|
62
|
+
};
|
|
63
|
+
if (template.repository.ref !== "HEAD" && !hasCommitSHARef) {
|
|
64
|
+
options["--branch"] = template.repository.ref;
|
|
65
|
+
}
|
|
66
|
+
await git.clone(template.repository.url, appName, options);
|
|
67
|
+
const gitAppDir = use_git_default(`${process.cwd()}/${appName}`);
|
|
68
|
+
if (hasCommitSHARef) {
|
|
69
|
+
await gitAppDir.fetch("origin", template.repository.ref);
|
|
70
|
+
await gitAppDir.checkout(template.repository.ref);
|
|
71
|
+
}
|
|
72
72
|
await rimraf(`${process.cwd()}/${appName}/.git`);
|
|
73
73
|
const packageJsonPath = join(process.cwd(), appName, "package.json");
|
|
74
74
|
const packageJsonContent = await readFile(packageJsonPath, "utf-8");
|
|
@@ -154,9 +154,12 @@ function validateName(name) {
|
|
|
154
154
|
process.on("SIGINT", () => process.exit(0));
|
|
155
155
|
process.on("SIGTERM", () => process.exit(0));
|
|
156
156
|
var program = new Command();
|
|
157
|
-
program.name(getName()).description(getDescription()).version(getVersion()).argument("[app-name]", "
|
|
157
|
+
program.name(getName()).description(getDescription()).version(getVersion()).argument("[app-name]", "name of the app to create").option(
|
|
158
158
|
"-t, --template <template>",
|
|
159
|
-
"
|
|
159
|
+
"use template when scaffolding (predefined name or custom Git repository URL)"
|
|
160
|
+
).option(
|
|
161
|
+
"-r, --ref <ref>",
|
|
162
|
+
"use Git ref when cloning template repository (for example, branch name or tag)"
|
|
160
163
|
).action(async (appNameArg, options) => {
|
|
161
164
|
p2.intro(chalk.bold("Drupal Canvas Create"));
|
|
162
165
|
try {
|
|
@@ -164,7 +167,26 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
|
|
|
164
167
|
const template2 = templates_default.find(
|
|
165
168
|
(t) => t.id === options.template
|
|
166
169
|
);
|
|
167
|
-
|
|
170
|
+
const isCustomRepositoryUrl = [
|
|
171
|
+
// Remote repositories.
|
|
172
|
+
"https://",
|
|
173
|
+
"http://",
|
|
174
|
+
"git@",
|
|
175
|
+
// Local repositories.
|
|
176
|
+
"../",
|
|
177
|
+
"./",
|
|
178
|
+
"/"
|
|
179
|
+
].some((prefix) => options.template?.startsWith(prefix));
|
|
180
|
+
if (!template2 && isCustomRepositoryUrl) {
|
|
181
|
+
templates_default.push({
|
|
182
|
+
id: options.template,
|
|
183
|
+
label: options.template,
|
|
184
|
+
repository: {
|
|
185
|
+
url: options.template,
|
|
186
|
+
ref: "HEAD"
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
} else if (!template2) {
|
|
168
190
|
p2.log.error(`Template "${options.template}" not found`);
|
|
169
191
|
process.exit(1);
|
|
170
192
|
}
|
|
@@ -217,6 +239,9 @@ program.name(getName()).description(getDescription()).version(getVersion()).argu
|
|
|
217
239
|
const template = templates_default.find(
|
|
218
240
|
(t) => t.id === templateId
|
|
219
241
|
);
|
|
242
|
+
if (options.ref) {
|
|
243
|
+
template.repository.ref = options.ref;
|
|
244
|
+
}
|
|
220
245
|
p2.note(`Template: ${template.label}
|
|
221
246
|
App name: ${appName}`);
|
|
222
247
|
await createApp({ template, appName });
|