Skip to content

Commit a33e5d3

Browse files
authored
Release/6.0.0 (#167)
* Adds bin installer (#166) * Restructure folders * Add installation bin test post install script Fix scripts path Adjust bin scripts Add installation process * Update theme_version references
1 parent 47f6666 commit a33e5d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+729
-411
lines changed

.eslintignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules/**/*.js
1+
node_modules/**/*.js
2+
dist/**/*

.eslintrc

+13-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
"browser": true,
44
"jquery": true,
55
"node": true,
6-
"es6": true,
6+
"es6": true
77
},
8+
"parser": "babel-eslint",
89
"globals": {
910
"bowser": true
1011
},
1112
"rules": {
1213
"comma-dangle": 0,
13-
"no-cond-assign": [1,"except-parens"],
14+
"no-cond-assign": [1, "except-parens"],
1415
"no-console": 1,
1516
"no-constant-condition": 1,
1617
"no-control-regex": 1,
@@ -22,10 +23,10 @@
2223
"no-empty": 1,
2324
"no-ex-assign": 1,
2425
"no-extra-boolean-cast": 1,
25-
"no-extra-parens": [1,"all"],
26+
"no-extra-parens": [1, "all"],
2627
"no-extra-semi": 1,
2728
"no-func-assign": 1,
28-
"no-inner-declarations": [1,"both"],
29+
"no-inner-declarations": [1, "both"],
2930
"no-invalid-regexp": 1,
3031
"no-irregular-whitespace": 1,
3132
"no-negated-in-lhs": 1,
@@ -42,10 +43,14 @@
4243
"no-undef": 1,
4344
"no-undefined": 1,
4445
"no-unused-vars": 1,
45-
"array-bracket-spacing": [1,"always",{"singleValue":true,"objectsInArrays":true,"arraysInArrays":true}],
46-
"camelcase": [1,{"properties":"always"}],
47-
"comma-spacing": [1,{"after":true}],
46+
"array-bracket-spacing": [
47+
0,
48+
"always",
49+
{ "singleValue": true, "objectsInArrays": true, "arraysInArrays": true }
50+
],
51+
"camelcase": [1, { "properties": "always" }],
52+
"comma-spacing": [1, { "after": true }],
4853
"indent": ["error", 2],
49-
"quotes": [1,"double","avoid-escape"]
54+
"quotes": [1, "double", "avoid-escape"]
5055
}
5156
}

bin/cli.js

+257
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
#!/usr/bin/env node
2+
3+
/* eslint-disable no-console */
4+
5+
require("colors");
6+
7+
const { exec } = require("child_process");
8+
const fs = require("fs-extra");
9+
const path = require("path");
10+
const _ = require("lodash");
11+
const https = require("https");
12+
const replace = require("replace");
13+
const prompt = require("prompt");
14+
15+
const packageJson = require("../package.json");
16+
17+
const [, , ...project] = process.argv;
18+
19+
const wpCustomize = () => {
20+
prompt.start();
21+
22+
prompt.get(
23+
[
24+
"Theme_Name",
25+
"Theme_URI",
26+
"Author",
27+
"Author_URI",
28+
"Description",
29+
"License",
30+
"License_URI",
31+
"Text_Domain"
32+
],
33+
function(err, result) {
34+
let themeName = result.Theme_Name,
35+
themeURI = result.Theme_URI,
36+
author = result.Author,
37+
authorURI = result.Author_URI,
38+
description = result.Description,
39+
license = result.License,
40+
licenseURI = result.License_URI,
41+
textdomain = result.Text_Domain;
42+
43+
if (themeName) {
44+
replace({
45+
regex: "Theme Name:",
46+
replacement: "Theme Name: " + themeName,
47+
paths: [`${project}/style.css`],
48+
silent: true
49+
});
50+
}
51+
52+
if (themeURI) {
53+
replace({
54+
regex: "Theme URI:",
55+
replacement: "Theme URI: " + themeURI,
56+
paths: [`${project}/style.css`],
57+
silent: true
58+
});
59+
}
60+
61+
if (author) {
62+
replace({
63+
regex: "Author:",
64+
replacement: "Author: " + author,
65+
paths: [`${project}/style.css`],
66+
silent: true
67+
});
68+
}
69+
70+
if (authorURI) {
71+
replace({
72+
regex: "Author URI:",
73+
replacement: "Author URI: " + authorURI,
74+
paths: [`${project}/style.css`],
75+
silent: true
76+
});
77+
}
78+
79+
if (description) {
80+
replace({
81+
regex: "Description:",
82+
replacement: "Description: " + description,
83+
paths: [`${project}/style.css`],
84+
silent: true
85+
});
86+
}
87+
88+
if (license) {
89+
replace({
90+
regex: "License:",
91+
replacement: "License: " + license,
92+
paths: [`${project}/style.css`],
93+
silent: true
94+
});
95+
}
96+
97+
if (licenseURI) {
98+
replace({
99+
regex: "License URI:",
100+
replacement: "License URI: " + licenseURI,
101+
paths: [`${project}/style.css`],
102+
silent: true
103+
});
104+
}
105+
106+
if (textdomain) {
107+
replace({
108+
regex: "Text Domain:",
109+
replacement: "Text Domain: " + textdomain,
110+
paths: [`${project}/style.css`],
111+
silent: true
112+
});
113+
}
114+
console.log("✅ WordPress theme configured".green);
115+
console.log("💖 Remember - you're amazing.".cyan);
116+
console.log("✨ Prelude was configured successfully!");
117+
}
118+
);
119+
};
120+
121+
console.log(`🛠 Creating theme ${project}...`.cyan);
122+
123+
const setupProject = async () => {
124+
try {
125+
await exec(
126+
`mkdir ${project} && cd ${project} && yarn init --yes`,
127+
initErr => {
128+
if (initErr) {
129+
console.error(
130+
`😭 Something went really wrong... try again: ${initErr}`.red
131+
);
132+
}
133+
134+
// copy main theme files
135+
fs.copySync(path.join(__dirname, "../src"), `${project}/`);
136+
137+
// copy other config files
138+
const otherFiles = [
139+
".babelrc",
140+
".browserslistrc",
141+
".editorconfig",
142+
".eslintignore",
143+
".eslintrc"
144+
];
145+
146+
for (let index = 0; index < otherFiles.length; index++) {
147+
fs.createReadStream(
148+
path.join(__dirname, `../${otherFiles[index]}`)
149+
).pipe(fs.createWriteStream(`${project}/${otherFiles[index]}`));
150+
}
151+
152+
const devDependencies = [];
153+
Object.keys(packageJson.devDependencies).forEach(dep =>
154+
devDependencies.push(`${dep}@${packageJson.devDependencies[dep]}`)
155+
);
156+
157+
const strippedDevDependencies = _.join(devDependencies, " ");
158+
159+
const dependencies = [];
160+
Object.keys(packageJson.dependencies).forEach(dep =>
161+
dependencies.push(`${dep}@${packageJson.dependencies[dep]}`)
162+
);
163+
164+
const strippedDependencies = _.join(dependencies, " ");
165+
166+
// install deps
167+
console.log("⌛ Installing dependencies...".yellow);
168+
exec(
169+
`cd ${project} && yarn add ${strippedDependencies}`,
170+
(yarnErr, yarnStdout) => {
171+
if (yarnErr) {
172+
console.error(yarnErr);
173+
return;
174+
}
175+
console.log(yarnStdout);
176+
console.log("✅ dependencies installed".green);
177+
// install dev deps
178+
console.log("⌛ Installing devDependencies...".yellow);
179+
exec(
180+
`cd ${project} && yarn add ${strippedDevDependencies} -D`,
181+
(yarnErr, yarnStdout) => {
182+
if (yarnErr) {
183+
console.error(yarnErr);
184+
return;
185+
}
186+
console.log(yarnStdout);
187+
console.log("✅ devDependencies installed".green);
188+
console.log("🙈 Setting up .gitignore...".yellow);
189+
https.get(
190+
"https://raw.githubusercontent.com/factor1/prelude-wp/master/.gitignore",
191+
res => {
192+
res.setEncoding("utf8");
193+
let body = "";
194+
res.on("data", data => {
195+
body += data;
196+
});
197+
res.on("end", async () => {
198+
await fs.writeFile(
199+
`${project}/.gitignore`,
200+
body,
201+
{ encoding: "utf-8" },
202+
err => {
203+
if (err) throw err;
204+
}
205+
);
206+
console.log("✅ .gitignore configured".green);
207+
console.log("🎨 Configuring WP Theme Info".yellow);
208+
try {
209+
wpCustomize();
210+
} catch (error) {
211+
console.error(
212+
"❗ Error configuring WP Theme information",
213+
error
214+
);
215+
}
216+
});
217+
}
218+
);
219+
}
220+
);
221+
}
222+
);
223+
224+
// add scripts to package.json
225+
const themePackageJson = `${project}/package.json`;
226+
227+
const packageScripts = `
228+
"scripts": {
229+
"start": "NODE_ENV=development gulp serve",
230+
"build": "yarn format && NODE_ENV=production gulp build",
231+
"test": "eslint .",
232+
"format": "prettier *.js *css --write",
233+
"release-major": "yarn test && node ./util/versionUpdate.js --major && yarn build",
234+
"release-minor": "yarn test && node ./util/versionUpdate.js --minor && yarn build",
235+
"release-patch": "yarn test && node ./util/versionUpdate.js --patch && yarn build"
236+
}
237+
`;
238+
239+
fs.readFile(themePackageJson, (err, file) => {
240+
if (err) {
241+
throw err;
242+
}
243+
const data = file
244+
.toString()
245+
.replace(`"main": "index.js"`, packageScripts); // eslint-disable-line quotes
246+
247+
fs.writeFile(themePackageJson, data, err2 => err2 || true);
248+
});
249+
}
250+
);
251+
} catch (error) {
252+
console.warn("😭 Something terrible happened... Try again.");
253+
throw new Error(error);
254+
}
255+
};
256+
257+
setupProject();

package.json

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "prelude-wp",
3-
"version": "5.0.2",
4-
"theme_version": "0.0.1",
3+
"version": "6.0.0",
54
"description": "Prelude is a Wordpress starter theme that helps you craft custom themes. It uses Gulp to compile and minify scss/css, concatenate and minify JS, compress images, and more.",
65
"main": "./util/moveFiles.js",
76
"repository": "[email protected]:factor1/prelude-wp.git",
@@ -12,21 +11,27 @@
1211
"start": "NODE_ENV=development gulp serve",
1312
"build": "yarn format && NODE_ENV=production gulp build",
1413
"test": "eslint .",
15-
"format": "prettier *.js *css --write",
14+
"format": "prettier *.js *.css --write",
1615
"release-major": "yarn test && node ./util/versionUpdate.js --major && yarn build",
1716
"release-minor": "yarn test && node ./util/versionUpdate.js --minor && yarn build",
1817
"release-patch": "yarn test && node ./util/versionUpdate.js --patch && yarn build"
1918
},
19+
"bin": {
20+
"prelude-wp": "./bin/cli.js"
21+
},
2022
"dependencies": {
23+
"bowser": "^2.5.2"
24+
},
25+
"devDependencies": {
2126
"@babel/core": "^7.5.5",
2227
"@babel/preset-env": "^7.5.5",
23-
"babel-eslint": "^10.0.2",
24-
"bowser": "^2.5.2",
28+
"babel-eslint": "8",
2529
"browser-sync": "^2.26.7",
2630
"colors": "^1.3.3",
2731
"del": "^5.0.0",
2832
"dotenv": "^8.0.0",
2933
"eslint": "^6.0.1",
34+
"fs-extra": "^8.1.0",
3035
"gulp": "^4.0.2",
3136
"gulp-autoprefixer": "^6.1.0",
3237
"gulp-babel": "^8.0.0",
@@ -41,8 +46,11 @@
4146
"lodash": "^4.17.15",
4247
"node-sass": "^4.12.0",
4348
"normalize-scss": "^7.0.1",
49+
"path": "^0.12.7",
4450
"prettier": "^1.18.2",
45-
"replace": "^1.1.0",
51+
"prompt": "^1.0.0",
52+
"replace": "^1.1.1",
53+
"slugify": "^1.3.4",
4654
"yargs": "^13.3.0"
4755
}
4856
}

404.php renamed to src/404.php

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

functions.php renamed to src/functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$NPM_PACKAGE = file_get_contents(get_template_directory() . '/package.json');
44
$NPM_PACKAGE = json_decode($NPM_PACKAGE, true);
5-
$THEME_VERSION = $NPM_PACKAGE['theme_version'];
5+
$THEME_VERSION = $NPM_PACKAGE['version'];
66

77
define( 'THEME_VERSION', $THEME_VERSION );
88

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

index.php renamed to src/index.php

File renamed without changes.

page.php renamed to src/page.php

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

style.css renamed to src/style.css

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)