@stratawp/cli 0.3.0 → 0.4.1

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.
Files changed (2) hide show
  1. package/dist/create.js +76 -3
  2. package/package.json +1 -1
package/dist/create.js CHANGED
@@ -42,6 +42,34 @@ async function main() {
42
42
  name: "author",
43
43
  message: "Author name:"
44
44
  },
45
+ {
46
+ type: "select",
47
+ name: "template",
48
+ message: "Choose a starting template:",
49
+ choices: [
50
+ {
51
+ title: "Basic Theme (Recommended)",
52
+ description: "Simple starter with essential blocks and clean structure",
53
+ value: "basic"
54
+ },
55
+ {
56
+ title: "Advanced Theme",
57
+ description: "Portfolio features, team members, advanced blocks",
58
+ value: "advanced"
59
+ },
60
+ {
61
+ title: "Store Theme",
62
+ description: "WooCommerce ready with product features",
63
+ value: "store"
64
+ },
65
+ {
66
+ title: "Minimal",
67
+ description: "Start from scratch with minimal setup",
68
+ value: "minimal"
69
+ }
70
+ ],
71
+ initial: 0
72
+ },
45
73
  {
46
74
  type: "select",
47
75
  name: "cssFramework",
@@ -88,9 +116,26 @@ async function createTheme(config) {
88
116
  spinner.fail(`Directory ${config.slug} already exists`);
89
117
  process.exit(1);
90
118
  }
91
- await fs.ensureDir(themePath);
92
- spinner.text = "Copying template files...";
93
- await createBasicStructure(themePath, config);
119
+ if (config.template === "minimal") {
120
+ await fs.ensureDir(themePath);
121
+ spinner.text = "Creating basic structure...";
122
+ await createBasicStructure(themePath, config);
123
+ } else {
124
+ spinner.text = `Downloading ${config.template} theme template...`;
125
+ const degit = (await import("degit")).default;
126
+ const templateMap = {
127
+ basic: "JonImmsWordpressDev/StrataWP/examples/basic-theme#main",
128
+ advanced: "JonImmsWordpressDev/StrataWP/examples/advanced-theme#main",
129
+ store: "JonImmsWordpressDev/StrataWP/examples/store-theme#main"
130
+ };
131
+ const emitter = degit(templateMap[config.template], {
132
+ cache: false,
133
+ force: true
134
+ });
135
+ await emitter.clone(themePath);
136
+ spinner.text = "Customizing theme...";
137
+ await customizeTheme(themePath, config);
138
+ }
94
139
  spinner.text = "Installing dependencies...";
95
140
  await execa("pnpm", ["install"], { cwd: themePath });
96
141
  spinner.succeed(chalk.green("Theme created successfully!"));
@@ -105,6 +150,34 @@ async function createTheme(config) {
105
150
  process.exit(1);
106
151
  }
107
152
  }
153
+ async function customizeTheme(themePath, config) {
154
+ const styleCssPath = path.join(themePath, "style.css");
155
+ if (await fs.pathExists(styleCssPath)) {
156
+ let styleContent = await fs.readFile(styleCssPath, "utf-8");
157
+ styleContent = styleContent.replace(/Theme Name:.*$/m, `Theme Name: ${config.name}`).replace(/Description:.*$/m, `Description: ${config.description}`).replace(/Author:.*$/m, `Author: ${config.author}`).replace(/Text Domain:.*$/m, `Text Domain: ${config.slug}`);
158
+ await fs.writeFile(styleCssPath, styleContent);
159
+ }
160
+ const packageJsonPath = path.join(themePath, "package.json");
161
+ if (await fs.pathExists(packageJsonPath)) {
162
+ const packageJson = await fs.readJson(packageJsonPath);
163
+ packageJson.name = config.slug;
164
+ packageJson.description = config.description;
165
+ packageJson.author = config.author;
166
+ await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
167
+ }
168
+ const readmePath = path.join(themePath, "README.md");
169
+ if (await fs.pathExists(readmePath)) {
170
+ let readmeContent = await fs.readFile(readmePath, "utf-8");
171
+ readmeContent = readmeContent.replace(/^#\s+.*$/m, `# ${config.name}`);
172
+ await fs.writeFile(readmePath, readmeContent);
173
+ }
174
+ const viteConfigPath = path.join(themePath, "vite.config.ts");
175
+ if (await fs.pathExists(viteConfigPath)) {
176
+ let viteConfig = await fs.readFile(viteConfigPath, "utf-8");
177
+ viteConfig = viteConfig.replace(/namespace:\s*['"][\w-]+['"]/, `namespace: '${config.slug}'`);
178
+ await fs.writeFile(viteConfigPath, viteConfig);
179
+ }
180
+ }
108
181
  async function offerWordPressLinking(themePath, slug) {
109
182
  console.log();
110
183
  const { shouldLink } = await prompts({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stratawp/cli",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "CLI tool for StrataWP - create and manage WordPress themes",
5
5
  "author": "Jon Imms",
6
6
  "license": "GPL-3.0-or-later",