Skip to content

Commit

Permalink
feat: add check against camelCase appName
Browse files Browse the repository at this point in the history
If we do not pass camelCase to appName, then it might not work
for output.jsonpFunction.
  • Loading branch information
swashata committed Oct 22, 2018
1 parent 3126650 commit 1869b5b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
2 changes: 2 additions & 0 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@babel/preset-flow": "^7.0.0",
"@babel/preset-typescript": "^7.1.0",
"@types/browser-sync": "^0.0.42",
"@types/camelcase": "^4.1.0",
"@types/execa": "^0.9.0",
"@types/figlet": "^1.2.0",
"@types/figures": "^2.0.0",
Expand All @@ -44,6 +45,7 @@
"babel-loader": "^8.0.2",
"boxen": "^2.0.0",
"browser-sync": "^2.24.7",
"camelcase": "^5.0.0",
"chalk": "^2.4.1",
"clean-webpack-plugin": "^0.1.19",
"commander": "^2.18.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/scripts/src/bin/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function serve(options: ProgramOptions | undefined): void {
} catch (e) {
spinner.stop();
console.log(`${logSymbols.error} could not start server.`);
console.log(pe.render(e));
console.error(pe.render(e));
process.exit(1);
}
}
10 changes: 10 additions & 0 deletions packages/scripts/src/config/getProjectAndServerConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import camelCase from 'camelcase';
import chalk from 'chalk';
import path from 'path';
import { ProjectConfig } from './project.config.default';
import { ServerConfig } from './server.config.default';
Expand Down Expand Up @@ -61,6 +63,14 @@ export function getProjectAndServerConfig(
`Server configuration must export an object literal. Right now it is ${typeof serverConfig}`
);
}
// Check if the appName is okay
if (!/^[A-Za-z]+$/.test(projectConfig.appName)) {
throw new Error(
`appName must be in camelCase. Currently ${
projectConfig.appName
}, try ${camelCase(projectConfig.appName)}`
);
}
// @todo
// Also validate the config, but let's leave it for now
// Make sure to do it in future
Expand Down
15 changes: 11 additions & 4 deletions packages/scripts/src/scripts/Bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import camelCase from 'camelcase';
import fs from 'fs';
import handlebars from 'handlebars';
import inquirer from 'inquirer';
import path from 'path';
import slugify from 'slugify';

interface Pkg {
name: string;
Expand Down Expand Up @@ -132,18 +134,23 @@ export class Bootstrap {
},
// Ask appName (auto-generate from package.json)
{
message: answers => `Name of WordPress ${answers.type}`,
message: answers =>
`Name of WordPress ${answers.type} (camelCase)`,
name: 'appName',
type: 'input',
default: this.pkg.name || '',
default: camelCase(this.pkg.name) || '',
filter: camelCase,
},
// Ask slug (default, directory name)
{
message: answers =>
`Slug (directory name) of your ${answers.type}`,
`Slug (directory name) of your ${
answers.type
} (alphanumeric & dash)`,
name: 'slug',
type: 'input',
default: path.basename(this.cwd),
default: slugify(path.basename(this.cwd)),
filter: slugify,
},
// Ask outputPath (relative), defaults 'dist'
{
Expand Down
30 changes: 5 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,10 @@
"@types/node" "*"
"@types/serve-static" "*"

"@types/camelcase@^4.1.0":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@types/camelcase/-/camelcase-4.1.0.tgz#e054f7986f31658d49936261b5cd4588ef29d1ee"

"@types/chalk@^2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@types/chalk/-/chalk-2.2.0.tgz#b7f6e446f4511029ee8e3f43075fb5b73fbaa0ba"
Expand Down Expand Up @@ -7071,30 +7075,6 @@ node-sass@^4.9.3:
stdout-stream "^1.4.0"
"true-case-path" "^1.0.2"

node-sass@^4.9.4:
version "4.9.4"
resolved "https://registry.yarnpkg.com/node-sass/-/node-sass-4.9.4.tgz#349bd7f1c89422ffe7e1e4b60f2055a69fbc5512"
dependencies:
async-foreach "^0.1.3"
chalk "^1.1.1"
cross-spawn "^3.0.0"
gaze "^1.0.0"
get-stdin "^4.0.1"
glob "^7.0.3"
in-publish "^2.0.0"
lodash.assign "^4.2.0"
lodash.clonedeep "^4.3.2"
lodash.mergewith "^4.6.0"
meow "^3.7.0"
mkdirp "^0.5.1"
nan "^2.10.0"
node-gyp "^3.8.0"
npmlog "^4.0.0"
request "^2.88.0"
sass-graph "^2.2.4"
stdout-stream "^1.4.0"
"true-case-path" "^1.0.2"

"nopt@2 || 3":
version "3.0.6"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9"
Expand Down Expand Up @@ -8790,7 +8770,7 @@ [email protected]:
tunnel-agent "^0.6.0"
uuid "^3.1.0"

request@^2.87.0, request@^2.88.0:
request@^2.87.0:
version "2.88.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef"
dependencies:
Expand Down

0 comments on commit 1869b5b

Please sign in to comment.