-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wp-now: create first version of the command (#188)
* wp-now: create dummy commands and new package * wp-now: re-create wp-now folders using nx * wp-now: execute php code example * wp-now: add connect node proxy to php runtime * wp-now: download latest wp zip in .wp-now dir * wp-now: download wordpress and proxy requests fixing location * wp-now: remove unused run method * wp-now: clean unused imports * wp-now: css fixed, redirect fixed * wp-now: setup sqlite * wp-now: use express and change the response to bytes * wp-now: rename download lib * wp-now: add sqlite funciton * wp-now: move sqlite logic to nodejs and unify paths * wp-now: split create-server run-cli logic * wp-now: update yarn lock * wp-now: import HTTPMethod from abstract * wp-now: avoid importing abstract * wp-now: remove async from mountSqlite * wp-now: clean unnecesary cli * wp-now: fix imports after merge using NodePHP and universal * wp-now: change build phase to esbuild module * wp-now: remove clear console lines * wp-now: use portFinder for open port source of truth * wp-now: receive path as paramter * wp-now: accept path and mode, enable plugin mode * wp-now: infer mode plugin, theme, index or core * wp-now: infer mode static directory * wp-now: rename patchFile to updateFile * wp-now: add comments to constants * wp-now: reduce amount of child folders for sqlite * wp-now: run always wp-now cli mode Exmaple: nx preview wp-now start --path=/Users/macbookpro/gutenberg * wp-now: use path as a parameter instead of cwd() * wp-now: fix code style * wp-now: remove unnecessary log port number * wp-now: update SQLite plugin name under quotes * wp-now: remove node env suggestion from run-cli * wp-now: project.json run commands sequentially * wp-now: rename wordpress versions path * wp-now: fix code style * wp-now: rename requestBodyToMultipartFormData * wp-now: reuse defineSiteUrl * wp-now: include a WP-NOW Readme and copy it to dist * wp-now: improve the readme redaction * wp-now: improve the readme redaction * wp-now: add phpVersion parameter Closes: #232 * wp-now: fix code style * wp-now: default mode is index * wp-now: fix code style * wp-now: use dashes for wordpress-versions folder * wp-now: update readme * wp-now: remove wp-content argument to use only home directory * wp-now: rename phpVersion argument name to php * wp-now: pass php version value from php argument
- Loading branch information
Showing
20 changed files
with
1,336 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# WP-NOW | ||
|
||
`wp-now` is a Command Line Interface (CLI) tool designed to streamline the process of setting up a local WordPress environment by using only Node.js. This powerful tool is optimized for developers working on WordPress themes and plugins. | ||
|
||
## Getting Started | ||
|
||
Follow these steps to build and run `wp-now` locally: | ||
|
||
### Building | ||
|
||
To build the project, use the following commands in your terminal: | ||
|
||
```bash | ||
nvm use | ||
yarn install | ||
yarn build | ||
``` | ||
|
||
### Running | ||
|
||
To start the web server and execute your WordPress plugin or theme, use the following command: | ||
|
||
```bash | ||
nx preview wp-now start --path=/path/to/wordpress-plugin-or-theme | ||
``` | ||
|
||
Replace `/path/to/wordpress-plugin-or-theme` with the actual path to your plugin or theme folder. | ||
|
||
## Contributing | ||
|
||
We welcome contributions from the community! Please refer to the main [README.md](../../README.md) file for instructions on how to contribute to this project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as esbuild from 'esbuild'; | ||
|
||
await esbuild.build({ | ||
entryPoints: ['packages/wp-now/src/main.ts'], | ||
outdir: 'dist/packages/wp-now', | ||
bundle: true, | ||
packages: 'external', | ||
format: 'esm', | ||
platform: 'node', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'wp-now', | ||
preset: '../../jest.preset.js', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]s$': [ | ||
'ts-jest', | ||
{ tsconfig: '<rootDir>/tsconfig.spec.json' }, | ||
], | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/packages/wp-now', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "wp-now", | ||
"version": "0.0.0", | ||
"description": "WordPress Playground CLI", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/WordPress/wordpress-playground" | ||
}, | ||
"homepage": "https://developer.wordpress.org/playground", | ||
"author": "The WordPress contributors", | ||
"contributors": [ | ||
{ | ||
"name": "Antonio Sejas", | ||
"email": "[email protected]", | ||
"url": "https://github.com/sejas" | ||
} | ||
], | ||
"publishConfig": { | ||
"access": "public", | ||
"directory": "../../../dist/packages/wp-now" | ||
}, | ||
"license": "(GPL-2.0-or-later OR MPL-2.0)", | ||
"type": "module", | ||
"main": "main.js", | ||
"bin": "main.js", | ||
"gitHead": "e6a7ed1b4e3e804590a5d9c40d95dfb9e6281e1a" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{ | ||
"name": "wp-now", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/wp-now/src", | ||
"projectType": "application", | ||
"targets": { | ||
"build": { | ||
"executor": "nx:noop", | ||
"dependsOn": ["build:package-json", "build:bundle"] | ||
}, | ||
"build:package-json": { | ||
"executor": "@wp-playground/nx-extensions:package-json", | ||
"options": { | ||
"tsConfig": "packages/wp-now/tsconfig.lib.json", | ||
"outputPath": "dist/packages/wp-now", | ||
"buildTarget": "wp-now:build:bundle" | ||
}, | ||
"dependsOn": ["build:bundle"] | ||
}, | ||
"build:bundle": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"commands": [ | ||
"node packages/wp-now/esbuild.mjs", | ||
"cp packages/wp-now/package.json dist/packages/wp-now", | ||
"cp packages/wp-now/README.md dist/packages/wp-now" | ||
], | ||
"parallel": false | ||
} | ||
}, | ||
"preview": { | ||
"executor": "@wp-playground/nx-extensions:built-script", | ||
"options": { | ||
"scriptPath": "dist/packages/wp-now/main.js" | ||
}, | ||
"dependsOn": ["build"] | ||
}, | ||
"serve": { | ||
"executor": "@nrwl/js:node", | ||
"defaultConfiguration": "development", | ||
"options": { | ||
"buildTarget": "wp-now:build" | ||
}, | ||
"configurations": { | ||
"development": { | ||
"buildTarget": "wp-now:build:development" | ||
}, | ||
"production": { | ||
"buildTarget": "wp-now:build:production" | ||
} | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["packages/wp-now/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nrwl/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "packages/wp-now/jest.config.ts", | ||
"passWithNoTests": true | ||
}, | ||
"configurations": { | ||
"ci": { | ||
"ci": true, | ||
"codeCoverage": true | ||
} | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import os from 'os'; | ||
import path from 'path'; | ||
|
||
/** | ||
* The hidden folder name for storing WP Now related files. | ||
*/ | ||
export const WP_NOW_HIDDEN_FOLDER = '.wp-now'; | ||
|
||
/** | ||
* The full path to the hidden WP Now folder in the user's home directory. | ||
*/ | ||
export const WP_NOW_PATH = path.join(os.homedir(), WP_NOW_HIDDEN_FOLDER); | ||
|
||
/** | ||
* The path where WordPress zip files will be unzipped and stored within the WP Now folder. | ||
*/ | ||
export const WORDPRESS_VERSIONS_PATH = path.join( | ||
WP_NOW_PATH, | ||
'wordpress-versions' | ||
); | ||
|
||
/** | ||
* The file name for the SQLite plugin name. | ||
*/ | ||
export const SQLITE_FILENAME = 'sqlite-database-integration'; | ||
|
||
/** | ||
* The full path to the "SQLite database integration" folder. | ||
*/ | ||
export const SQLITE_PATH = path.join(WP_NOW_PATH, `${SQLITE_FILENAME}-main`); | ||
|
||
/** | ||
* The URL for downloading the latest version of WordPress. | ||
*/ | ||
export const WP_DOWNLOAD_URL = 'https://wordpress.org/latest.zip'; | ||
|
||
/** | ||
* The URL for downloading the "SQLite database integration" WordPress Plugin. | ||
*/ | ||
export const SQLITE_URL = | ||
'https://github.com/WordPress/sqlite-database-integration/archive/refs/heads/main.zip'; | ||
|
||
/** | ||
* The default starting port for running the WP Now server. | ||
*/ | ||
export const DEFAULT_PORT = 8881; | ||
|
||
/** | ||
* The default PHP version to use when running the WP Now server. | ||
*/ | ||
export const DEFAULT_PHP_VERSION = '8.0'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import request from 'request'; | ||
import fs from 'fs-extra'; | ||
import unzipper from 'unzipper'; | ||
import path from 'path'; | ||
import { | ||
SQLITE_FILENAME, | ||
SQLITE_PATH, | ||
SQLITE_URL, | ||
WORDPRESS_VERSIONS_PATH, | ||
WP_DOWNLOAD_URL, | ||
WP_NOW_PATH, | ||
} from './constants'; | ||
|
||
async function downloadFile(url: string, dest: string): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
const file = fs.createWriteStream(dest); | ||
request(url) | ||
.pipe(file) | ||
.on('finish', () => { | ||
file.close(() => resolve()); | ||
}) | ||
.on('error', (err: Error) => { | ||
fs.unlink(dest); | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
|
||
async function downloadFileAndUnzip({ | ||
url, | ||
zipPath, | ||
unzipPath, | ||
checkFinalPath, | ||
itemName, | ||
}) { | ||
if (!fs.existsSync(checkFinalPath)) { | ||
try { | ||
fs.ensureDirSync(path.dirname(zipPath)); | ||
console.log(`Downloading ${itemName}...`); | ||
await downloadFile(url, zipPath); | ||
// unzip the file | ||
console.log(`Unzipping ${itemName}...`); | ||
await fs | ||
.createReadStream(zipPath) | ||
.pipe(unzipper.Extract({ path: unzipPath })) | ||
.promise(); | ||
console.log('Removing Zip.'); | ||
await fs.remove(zipPath); | ||
} catch (err) { | ||
console.error(`Error downloading or unzipping ${itemName}:`, err); | ||
} | ||
} else { | ||
console.log(`${itemName} folder already exists. Skipping download.`); | ||
} | ||
} | ||
|
||
export async function downloadWordPress(fileName = 'latest') { | ||
return downloadFileAndUnzip({ | ||
url: WP_DOWNLOAD_URL, | ||
zipPath: path.join(WORDPRESS_VERSIONS_PATH, `${fileName}.zip`), | ||
unzipPath: path.join(WORDPRESS_VERSIONS_PATH, fileName), | ||
checkFinalPath: path.join(WORDPRESS_VERSIONS_PATH, fileName), | ||
itemName: `WordPress ${fileName}`, | ||
}); | ||
} | ||
|
||
export async function downloadSqlite() { | ||
return downloadFileAndUnzip({ | ||
url: SQLITE_URL, | ||
zipPath: path.join(WP_NOW_PATH, `${SQLITE_FILENAME}.zip`), | ||
unzipPath: WP_NOW_PATH, | ||
checkFinalPath: SQLITE_PATH, | ||
itemName: 'Sqlite', | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { runCli } from './run-cli'; | ||
|
||
runCli(); |
Oops, something went wrong.