Skip to content

Commit

Permalink
Make the test project generator more composable (redwoodjs#3099)
Browse files Browse the repository at this point in the history
* Make the test project generator more composable | Add ability to use rufus

* Remove lint steps

* Lint fix

* Renable tailwind | Resync after creation

* Add project:copy to postinstall

* Pass verbose and link flags

* WIP

* Tailwind setup changes | Fix blogpost codemod

* Fix blogpost codemod
  • Loading branch information
dac09 authored Jul 28, 2021
1 parent a1894c3 commit 2af0ea7
Show file tree
Hide file tree
Showing 9 changed files with 484 additions and 275 deletions.
15 changes: 13 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@
"statusBar.background": "#b85833",
"statusBarItem.hoverBackground": "#ce7350",
"statusBar.foreground": "#e7e7e7",
"statusBar.border": "#b85833"
"activityBar.activeBackground": "#ce7350",
"activityBar.activeBorder": "#82dc9b",
"activityBar.background": "#ce7350",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#82dc9b",
"activityBarBadge.foreground": "#15202b",
"titleBar.activeBackground": "#b85833",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#b8583399",
"titleBar.inactiveForeground": "#e7e7e799"
},
"search.exclude": {
"**/dist": true,
"**/node_modules": true,
"**/__fixtures__": true,
".yarn-packages-cache": true
},
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"peacock.color": "#b85833"
}
2 changes: 1 addition & 1 deletion packages/cli/src/commands/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const builder = (yargs) => {
description: 'Which dev server(s) to start',
type: 'array',
})
.positional('forward', {
.option('forward', {
alias: 'fwd',
description:
'String of one or more Webpack DevServer config options, for example: `--fwd="--port=1234 --no-open"`',
Expand Down
14 changes: 10 additions & 4 deletions packages/create-redwood-app/src/create-redwood-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const {
_: args,
'yarn-install': yarnInstall,
typescript,
overwrite,
} = yargs
.scriptName(name)
.usage('Usage: $0 <project directory> [option]')
Expand All @@ -63,6 +64,11 @@ const {
type: 'boolean',
describe: 'Generate a TypeScript project. JavaScript by default.',
})
.option('overwrite', {
default: false,
type: 'boolean',
describe: 'Create even if target directory is empty',
})
.version(version)
.strict().argv

Expand All @@ -88,7 +94,7 @@ const newAppDir = path.resolve(process.cwd(), targetDir)
const appDirExists = fs.existsSync(newAppDir)
const templateDir = path.resolve(__dirname, '../template')

const createProjectTasks = ({ newAppDir }) => {
const createProjectTasks = ({ newAppDir, overwrite }) => {
return [
{
title: 'Checking node and yarn compatibility',
Expand Down Expand Up @@ -130,7 +136,7 @@ const createProjectTasks = ({ newAppDir }) => {
{
title: `${appDirExists ? 'Using' : 'Creating'} directory '${newAppDir}'`,
task: () => {
if (appDirExists) {
if (appDirExists && !overwrite) {
// make sure that the target directory is empty
if (fs.readdirSync(newAppDir).length > 0) {
console.error(
Expand All @@ -141,7 +147,7 @@ const createProjectTasks = ({ newAppDir }) => {
} else {
fs.ensureDirSync(path.dirname(newAppDir))
}
fs.copySync(templateDir, newAppDir)
fs.copySync(templateDir, newAppDir, { overwrite: overwrite })
// .gitignore is renamed here to force file inclusion during publishing
fs.rename(
path.join(newAppDir, 'gitignore.template'),
Expand Down Expand Up @@ -175,7 +181,7 @@ new Listr(
[
{
title: 'Creating Redwood app',
task: () => new Listr(createProjectTasks({ newAppDir })),
task: () => new Listr(createProjectTasks({ newAppDir, overwrite })),
},
{
title: 'Installing packages',
Expand Down
14 changes: 4 additions & 10 deletions tasks/test-project/codemods/blogPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export default (file, api) => {
if (file.path.endsWith('.tsx')) {
root.find(j.VariableDeclaration).insertBefore(propsInterface)

// Convert "const BlogPost = () "
// to "const BlogPost = ({ posts }: Props) "
root
.find(j.Identifier, {
name: 'BlogPost',
})
.find(j.ArrowFunctionExpression)
.at(0)
.replaceWith((nodePath) => {
const { node } = nodePath
node.typeAnnotation.typeAnnotation.typeParameters = '<Props>'
node.params = ['{ post }: Props']
return node
})
}
Expand All @@ -56,12 +56,6 @@ export default (file, api) => {
})
.replaceWith((nodePath) => {
const { node } = nodePath
node.init.params = [
...node.init.params,
j.objectPattern([
j.objectProperty(j.identifier('post'), j.identifier('post')),
]),
]
node.init.body.body[0].argument = body
return node
})
Expand Down
31 changes: 31 additions & 0 deletions tasks/test-project/frameworkLinking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-env node, es6*/
const execa = require('execa')

const addFrameworkDepsToProject = (frameworkPath, projectPath) => {
return execa('yarn framework project:deps', {
cwd: frameworkPath,
shell: true,
stdio: 'inherit',
env: {
RWFW_PATH: frameworkPath,
RWJS_CWD: projectPath,
},
})
}

const copyFrameworkPackages = (frameworkPath, projectPath) => {
return execa('yarn framework project:copy', {
cwd: frameworkPath,
shell: true,
stdio: 'inherit',
env: {
RWFW_PATH: frameworkPath,
RWJS_CWD: projectPath,
},
})
}

module.exports = {
copyFrameworkPackages,
addFrameworkDepsToProject,
}
2 changes: 1 addition & 1 deletion tasks/test-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "index.js",
"license": "MIT",
"scripts": {
"transform": "node node_modules/.bin/jscodeshift"
"transform": "node node_modules/.bin/jscodeshift --fail-on-error"
},
"dependencies": {
"jscodeshift": "^0.13.0"
Expand Down
Loading

0 comments on commit 2af0ea7

Please sign in to comment.