Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added "c" as an alias for component command #72

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions bin/reacli.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ const createElement = async ({ firstParam = null, pathsToComponentsToCreate = []

if (validatePath(path) && validateName(path)) {
try {
switch (firstParam) {
case "component":
if (firstParam === "component" || firstParam === "c") {
promises.push(createComponent(path, options))
break;
case "hook":
} else if (firstParam === "hook") {
promises.push(createHook(path, options))
break;
default:
} else {
program.outputHelp()
break;
}
} catch (error) {
console.log("ERROR: ", error)
Expand All @@ -44,6 +40,7 @@ const outputHelpDetails = () => {
console.log("")
console.log("Commands:")
console.log(" component [path(s)] [options]")
console.log(" c [path(s)] [options]")
console.log(" hook [path(s)] [options]")
console.log("")
console.log("Examples:")
Expand Down
39 changes: 28 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

147 changes: 147 additions & 0 deletions test/integration-tests/component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,151 @@ describe("Component creation with CLI", () => {
})
})
})
})

describe("Component creation with CLI alias", () => {
test("reacli c ./simple-component", (testDone) => {
const fixture = new Tacks(Dir())
const componentName = "simple-component"
const expectedPath = path.resolve(__dirname, "..", "fixtures", componentName)
const componentPath = path.resolve(`${fixturePath}/${componentName}`)

withFixture(testDone, fixture, (done) => {
common(["c", componentPath], {
cwd: fixturePath,
}, (err, code, stdout, stderr) => {
const { same } = dircompare.compareSync(expectedPath, componentPath);

expect(same).toBeTruthy()
expect(code).toEqual(0)
done()
})
})
})

test("reacli c ./flow-component --flow", (testDone) => {
const fixture = new Tacks(Dir())
const componentName = "flow-component"
const expectedPath = path.resolve(__dirname, "..", "fixtures", componentName)
const componentPath = path.resolve(`${fixturePath}/${componentName}`)

withFixture(testDone, fixture, (done) => {
common(["c", componentPath, "--flow"], {
cwd: fixturePath,
}, (err, code, stdout, stderr) => {
const { same } = dircompare.compareSync(expectedPath, componentPath);

expect(same).toBeTruthy()
expect(code).toEqual(0)
done()
})
})
})

test("reacli c ./redux-component --redux", (testDone) => {
const fixture = new Tacks(Dir())
const componentName = "redux-component"
const expectedPath = path.resolve(__dirname, "..", "fixtures", componentName)
const componentPath = path.resolve(`${fixturePath}/${componentName}`)

withFixture(testDone, fixture, (done) => {
common(["c", componentPath, "--redux"], {
cwd: fixturePath,
}, (err, code, stdout, stderr) => {
const { same } = dircompare.compareSync(expectedPath, componentPath);

expect(same).toBeTruthy()
expect(code).toEqual(0)
done()
})
})
})

test("reacli c ./scss-component --scss", (testDone) => {
const fixture = new Tacks(Dir())
const componentName = "scss-component"
const expectedPath = path.resolve(__dirname, "..", "fixtures", componentName)
const componentPath = path.resolve(`${fixturePath}/${componentName}`)

withFixture(testDone, fixture, (done) => {
common(["c", componentPath, "--scss"], {
cwd: fixturePath,
}, (err, code, stdout, stderr) => {
const { same } = dircompare.compareSync(expectedPath, componentPath);

expect(same).toBeTruthy()
expect(code).toEqual(0)
done()
})
})
})

test("reacli c ./combination-component --redux --scss", (testDone) => {
const fixture = new Tacks(Dir())
const componentName = "combination-component"
const expectedPath = path.resolve(__dirname, "..", "fixtures", componentName)
const componentPath = path.resolve(`${fixturePath}/${componentName}`)

withFixture(testDone, fixture, (done) => {
common(["c", componentPath, "--redux", "--scss"], {
cwd: fixturePath,
}, (err, code, stdout, stderr) => {
const { same } = dircompare.compareSync(expectedPath, componentPath);

expect(same).toBeTruthy()
expect(code).toEqual(0)
done()
})
})
})

test("reacli c ./extension-js-component --extension js", (testDone) => {
const fixture = new Tacks(Dir())
const componentName = "extension-js-component"
const expectedPath = path.resolve(__dirname, "..", "fixtures", componentName)
const componentPath = path.resolve(`${fixturePath}/${componentName}`)

withFixture(testDone, fixture, (done) => {
common(["c", componentPath, "--extension", "js"], {
cwd: fixturePath,
}, (err, code, stdout, stderr) => {
const { same } = dircompare.compareSync(expectedPath, componentPath);

expect(same).toBeTruthy()
expect(code).toEqual(0)
done()
})
})
})

test("reacli c ./pre-configured-component", (testDone) => {
const fixture = new Tacks(Dir({
"package.json": File({
name: "this-is-a-cool-test",
}),
".reacli": File({
redux: true,
flow: true,
scss: true,
extension: "js",
}),
}))


const componentName = "pre-configured-component"
const expectedPath = path.resolve(__dirname, "..", "fixtures", componentName)
const componentPath = path.resolve(`${fixturePath}/${componentName}`)

withFixture(testDone, fixture, (done) => {
common(["c", componentPath], {
cwd: fixturePath,
}, (err, code, stdout, stderr) => {
const { same } = dircompare.compareSync(expectedPath, componentPath);

expect(same).toBeTruthy()
expect(code).toEqual(0)
done()
})
})
})
})