This repository was archived by the owner on Jan 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathexecute.ts
More file actions
75 lines (68 loc) · 2.79 KB
/
execute.ts
File metadata and controls
75 lines (68 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { resolve } from "path";
import {
CreateWorkspaceOpts,
createGitFolder,
completeWorkspace,
removeExamplePlugin,
applyWorkspaceName,
applyPorts,
promptGitLab,
ProjectResult
} from "./";
import { createPluginPrompt } from "../create-plugin";
import { applyName } from "../create-package";
import { generateLicenseFile } from "../utils";
import { applyPackageJson, applyPhpNamespace } from "../misc";
import { createDotEnv } from "./createDotEnv";
/**
* Generate a new workspace from a given repository and disconnect it.
* Also do some garbage collection and movements for other commands.
*/
async function createWorkspaceExecute(input: CreateWorkspaceOpts) {
const createCwd = resolve(process.cwd(), input.workspace);
const utilsPath = resolve(createCwd, "packages/utils");
const gitlabProjectCreator = await promptGitLab(input.workspace);
let gitLabProject: ProjectResult;
// Run create-plugin command without installation (because this is done below)
// So we have all prompts in one flow, awesome!
await createPluginPrompt(
{
cwd: createCwd
},
async () => {
if (gitlabProjectCreator !== false) {
gitLabProject = await gitlabProjectCreator();
}
createGitFolder(input.checkout, input.repository, createCwd, gitLabProject);
createDotEnv(createCwd, input);
removeExamplePlugin(createCwd);
applyWorkspaceName(input.workspace, createCwd);
applyPorts(input.portWp, input.portPma, createCwd);
},
async (createPluginCwd, pluginData) => {
// Brand first package: utils
const splitNs = pluginData.namespace.split("\\");
const utilsNamespace =
(splitNs.length > 1 ? splitNs.slice(0, -1).join("\\") : pluginData.namespace) + "\\Utils";
applyPhpNamespace(utilsPath, utilsNamespace, "utils");
// Re-apply namespace of utils package for this plugin because before it did not know the namespace
applyPhpNamespace(createPluginCwd, pluginData.namespace, "plugin");
applyName(utilsPath, "utils");
applyPackageJson(
input.workspace,
utilsPath,
{
author: pluginData.author,
description: "Utility functionality for all your WordPress plugins.",
homepage: pluginData.authorUri,
version: "1.0.0"
},
false
);
generateLicenseFile(utilsPath, pluginData.author, pluginData.pluginDesc);
// Complete
await completeWorkspace(createPluginCwd, createCwd, utilsPath, gitLabProject);
}
);
}
export { createWorkspaceExecute };