-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from 10up/ver0.1.0
Version 0.1
- Loading branch information
Showing
14 changed files
with
3,599 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
# Matches multiple files with brace expansion notation | ||
# Set default charset | ||
[*.{js,json}] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
# Matches the exact files either package.json or .travis.yml | ||
[*{yml}] | ||
indent_style = space | ||
indent_size = 2 |
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,136 @@ | ||
#!/usr/bin/env node | ||
const fs = require("fs-extra"); | ||
const npm = require("npm"); | ||
const npmAddScript = require("npm-add-script"); | ||
|
||
const destPath = process.cwd(); | ||
const sourcePath = __dirname.concat("/src"); | ||
const testsDir = "/tests"; | ||
const binDir = "/tests/bin"; | ||
const cypressDir = "/tests/cypress"; | ||
|
||
const testsPath = destPath.concat(testsDir); | ||
const testsBinPath = destPath.concat(binDir); | ||
const testsCypressPath = destPath.concat(cypressDir); | ||
|
||
// Check if NPM is initialized | ||
try { | ||
fs.accessSync(destPath.concat("/package.json")); | ||
} catch (err) { | ||
console.error("package.json does not exist. Please run npm init first."); | ||
process.exit(1); | ||
} | ||
|
||
// Install Cypress and wp-env. | ||
npm.load({ "save-dev": true }, (err) => { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
npm.commands.install(["cypress", "@wordpress/env"]); | ||
}); | ||
|
||
const scripts = { | ||
"cypress:open": "cypress open --config-file tests/cypress/config.json", | ||
"cypress:run": "cypress run --config-file tests/cypress/config.json", | ||
"env": "wp-env", | ||
"env:start": "wp-env start", | ||
"env:stop": "wp-env stop", | ||
"postenv:start": "./tests/bin/initialize.sh", | ||
}; | ||
|
||
// Add scripts to package.json | ||
Object.keys(scripts).forEach((k, _) => { | ||
try { | ||
npmAddScript({ | ||
key: k, | ||
value: scripts[k], | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}, scripts); | ||
|
||
// Create /tests directory or use existing one. | ||
fs.access(testsPath, (err) => { | ||
if (err) { | ||
console.log("./tests directory does not exist, creating it."); | ||
fs.mkdir(testsPath); | ||
} else { | ||
console.log("./tests directory already exists."); | ||
} | ||
|
||
fs.access(testsBinPath, (err) => { | ||
if (err) { | ||
console.log("./tests/bin directory does not exist, creating it."); | ||
fs.mkdir(testsBinPath); | ||
} else { | ||
console.log("./tests/bin directory already exists."); | ||
} | ||
|
||
/** | ||
* Files to copy from src to dest | ||
* {"filename": chmod (octal number)} | ||
*/ | ||
const filesToCopy = { | ||
"/tests/bin/initialize.sh": 0o755, | ||
"/tests/bin/set-core-version.js": 0o755, | ||
"/tests/bin/wp-cli.yml": null, | ||
"/.wp-env.json": null, | ||
}; | ||
|
||
Object.keys(filesToCopy).forEach((element, _) => { | ||
const source = sourcePath.concat(element); | ||
const dest = destPath.concat(element); | ||
const chmod = filesToCopy[element]; | ||
|
||
fs.access(dest, (err) => { | ||
if (err) { | ||
// Copy file if not exist. | ||
fs.copy(source, dest, (err) => { | ||
if (err) { | ||
console.error(err); | ||
} else { | ||
console.log("." + element.concat(" created.")); | ||
|
||
// Optionally set chmod. | ||
if (null !== chmod) { | ||
fs.chmod(dest, chmod, (err) => { | ||
if (err) { | ||
console.error(err); | ||
} else { | ||
console.log( | ||
"chmod " + | ||
chmod.toString(8) + | ||
" ." + | ||
element | ||
); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
} else { | ||
console.log("." + element.concat(" exists, skipping.")); | ||
} | ||
}); | ||
}, filesToCopy); | ||
}); | ||
|
||
// Copy cypress example test if no tests exist yet. | ||
fs.access(testsCypressPath, (err) => { | ||
if (err) { | ||
fs.copy(sourcePath.concat(cypressDir), testsCypressPath) | ||
.then(() => { | ||
console.log("Copied test example to ./tests/cypress"); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
}); | ||
} else { | ||
console.log( | ||
"./tests/cypress already exists. Skipping copy test example." | ||
); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.