Skip to content

Commit e0eec4d

Browse files
authored
Merge pull request #7 from NMFS-RADFish/task/pass-name-as-arg
Update output directory path
2 parents 03f549a + aab44c5 commit e0eec4d

File tree

7 files changed

+1415
-105
lines changed

7 files changed

+1415
-105
lines changed

.eslintrc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"es2021": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"prettier"
9+
],
10+
"parserOptions": {
11+
"ecmaVersion": 12,
12+
"sourceType": "module",
13+
"ecmaFeatures": {
14+
"jsx": true
15+
}
16+
},
17+
"plugins": [
18+
"prettier"
19+
],
20+
"rules": {
21+
"prettier/prettier": "error"
22+
}
23+
}

.github/workflows/run-tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ jobs:
1515
- name: Use Node.js
1616
uses: actions/setup-node@v1
1717
with:
18-
node-version: '18'
18+
node-version: "18"
1919

2020
- name: Install build dependencies
2121
run: npm install
2222

23+
- name: Lint code
24+
run: npm run lint
25+
2326
- name: Run tests
2427
run: npm test

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": true,
3+
"tabWidth": 2,
4+
"printWidth": 100,
5+
"singleQuote": false,
6+
"trailingComma": "all",
7+
"bracketSpacing": true
8+
}

config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ const applicationTypes = [
6161
{
6262
name: "None of the above",
6363
value: "other",
64-
description:
65-
"By selecting this option, you are skipping any preconfigured application setup",
64+
description: "By selecting this option, you are skipping any preconfigured application setup",
6665
},
6766
];
6867

index.js

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,46 @@
11
#!/usr/bin/env node
22
import { execSync } from "child_process";
3-
import { fileURLToPath } from "url";
4-
import { join, dirname } from "path";
53
import { confirm } from "@inquirer/prompts";
64
import select from "@inquirer/select";
75
import { Command } from "commander";
86
import ora from "ora";
97
import { validateRegion } from "./validators.js";
108
import { regionConfig } from "./config.js";
9+
import path from "path";
1110

1211
const program = new Command();
1312

14-
// checking to see if vals are provided as argv
15-
// if not, proceed with inquirer
16-
let regionProvidedAsArgv = false;
17-
1813
program
1914
.name("Create Radfish App")
2015
.description("The CLI to bootstrap a radfish app!")
2116
.version("0.0.1");
2217

2318
// program options
24-
program
25-
.argument("<repository>")
26-
.option("-r --region <string>", "specified region");
19+
program.argument("<projectDirectoryPath>").option("-r --region <string>", "specified region");
2720

28-
program.action((repository, options) => {
21+
program.action((projectDirectoryPath, options) => {
2922
const isValidRegion = validateRegion(options.region);
3023

3124
if (!isValidRegion) {
3225
const regionCodes = regionConfig
3326
.map((region) => region.code)
3427
.join(" , ")
3528
.replace(/, $/, ""); // remove comma from last elem
36-
console.error(
37-
"Invalid region code. Here are the valid regions: ",
38-
regionCodes
39-
);
29+
console.error("Invalid region code. Here are the valid regions: ", regionCodes);
4030
}
4131

42-
scaffoldRadFishApp(repository);
32+
scaffoldRadFishApp(projectDirectoryPath);
4333
});
4434

4535
// check options passed in via cli command
4636
const options = program.opts();
4737

48-
if (options && options.region) {
49-
regionProvidedAsArgv = true;
50-
}
38+
async function scaffoldRadFishApp(projectDirectoryPath) {
39+
const targetDirectory = path.resolve(
40+
process.cwd(),
41+
`${projectDirectoryPath.trim().replace(/\s+/g, "-")}`, // replace whitespaces in the filepath
42+
);
5143

52-
async function scaffoldRadFishApp(repository) {
5344
async function defineRegion() {
5445
return await select({
5546
name: "region",
@@ -60,19 +51,14 @@ async function scaffoldRadFishApp(repository) {
6051

6152
async function confirmConfiguration(region) {
6253
return await confirm({
63-
message: `You are about to scaffold an application for the region of ${region} in the following project directory: ../${repository}
54+
message: `You are about to scaffold an application for the region of ${region} in the following project directory: ${targetDirectory}
6455
Okay to proceed?`,
6556
});
6657
}
6758

6859
// this will clone the radfish app boilerplate and spin it up
6960
function bootstrapApp() {
7061
const repoUrl = "git@github.com:NMFS-RADFish/boilerplate.git"; // via ssh each user/developer will need to have ssh keypair setup in github org
71-
const targetDirectory = `../${repository.replace(/\s+/g, "-")}`; // remove any whitespaces from filepath...just in case
72-
73-
const __filename = fileURLToPath(import.meta.url);
74-
const __dirname = dirname(__filename);
75-
7662
const spinner = ora("Setting up application").start();
7763

7864
// Clone the repository
@@ -85,8 +71,7 @@ async function scaffoldRadFishApp(repository) {
8571
}
8672

8773
// Change to the cloned repository directory
88-
const repoPath = join(__dirname, targetDirectory);
89-
process.chdir(repoPath);
74+
process.chdir(targetDirectory);
9075

9176
// Run an npm script (replace 'your-script-name' with the actual npm script name)
9277
try {

0 commit comments

Comments
 (0)