frontend-project-generator
Advanced tools
Comparing version 0.1.1 to 0.2.0-alpha-1
@@ -20,3 +20,3 @@ { | ||
"plugins": ["@typescript-eslint"], | ||
"rules": {} | ||
"rules": { "import/prefer-default-export": "off" } | ||
} |
// Testing constants | ||
export const TEST_PACKAGE_NAME = 'test'; | ||
export const TEST_PACKAGE_NAME = 'test-repository'; | ||
export const TEST_PACKAGE_NAME_2 = '..'; | ||
@@ -19,1 +19,20 @@ export const TEST_PACKAGE_NAME_3 = 'te-st.1_test'; | ||
export const NEWLINE_ENCODING = '\n'; | ||
// Main Package | ||
export const CREATE_NEXT_APP = 'create-next-app'; | ||
// Plugins | ||
export const PRETTIER = 'prettier'; | ||
export const ESLINT = 'eslint'; | ||
export const HUSKY = 'husky'; | ||
export const LINT_STAGED = 'lint-staged'; | ||
// Node commands | ||
export const NPX = 'npx'; | ||
export const USE_NPM = '--use-npm'; | ||
export const FLAG_TYPESCRIPT = '--typescript'; | ||
// Package Manager commands (npm) | ||
export const NPM_INSTALL = 'npm install'; | ||
export const FLAG_SAVE_DEV = '--save-dev'; | ||
export const FLAG_SAVE_EXACT = '--save-exact'; | ||
// Package Manager commands (yarn) | ||
export const YARN_ADD = 'yarn add'; | ||
export const FLAG_DEV = '--dev'; | ||
export const FLAG_EXACT = '--exact'; |
@@ -0,3 +1,8 @@ | ||
import path from 'path'; | ||
import { execShellPromise } from '../../utils/index.js'; | ||
import installProjectPlugin from '../installProjectPlugin/installProjectPlugin.js'; | ||
import { CREATE_NEXT_APP, FLAG_TYPESCRIPT, NPX, USE_NPM, ESLINT, HUSKY, LINT_STAGED, PRETTIER, } from '../../constants/index.js'; | ||
import config from '../../plugins.config.js'; | ||
import combinePluginWithVersion from '../../utils/combinePluginWithVersion/combinePluginWithVersion.js'; | ||
import { EPackageManager } from '../../enums/index.js'; | ||
import { execPromise } from '../../utils/index.js'; | ||
const createNextProject = (name) => async (promptAnswers) => { | ||
@@ -8,12 +13,92 @@ const projectName = name || promptAnswers["project-name" /* EQuestions.PROJECT_NAME */]; | ||
} | ||
const packageManager = promptAnswers["package-manager" /* EQuestions.PACKAGE_MANAGER */]; | ||
const userWorkingDir = process.cwd(); | ||
const generatorRootDir = path.dirname(process.argv[1]); | ||
try { | ||
await execPromise(`npx create-next-app ${projectName} ${promptAnswers["package-manager" /* EQuestions.PACKAGE_MANAGER */] === EPackageManager.NPM | ||
? `--use-npm` | ||
: ''} --typescript`); | ||
const createNextApp = combinePluginWithVersion(CREATE_NEXT_APP, config[CREATE_NEXT_APP].version); | ||
await execShellPromise(`${NPX} ${createNextApp} ${projectName} ${FLAG_TYPESCRIPT} ${packageManager === EPackageManager.NPM ? USE_NPM : ''}`); | ||
const newProjectDir = path.resolve(path.join(userWorkingDir, projectName)); | ||
// Move to newly created project via cli | ||
process.chdir(newProjectDir); | ||
await installProjectPlugin({ | ||
pluginName: PRETTIER, | ||
pluginVersion: config[PRETTIER].version, | ||
devDep: config[PRETTIER].devDep, | ||
packageManager, | ||
snippet: { | ||
action: config[PRETTIER].snippet.action, | ||
inputCode: config[PRETTIER].snippet.inputCode, | ||
outputFile: config[PRETTIER].snippet.outputFile, | ||
generatorRootDir, | ||
newProjectDir, | ||
}, | ||
config: { | ||
generatorRootDir, | ||
newProjectDir, | ||
configDir: config[PRETTIER].config, | ||
}, | ||
}); | ||
await installProjectPlugin({ | ||
pluginName: ESLINT, | ||
devDep: config[ESLINT].devDep, | ||
packageManager, | ||
nextDefaultPackage: config[ESLINT].nextDefaultPackage, | ||
subPlugins: config[ESLINT].subPlugins, | ||
snippet: { | ||
action: config[ESLINT].snippet.action, | ||
inputCode: config[ESLINT].snippet.inputCode, | ||
outputFile: config[ESLINT].snippet.outputFile, | ||
generatorRootDir, | ||
newProjectDir, | ||
}, | ||
config: { | ||
generatorRootDir, | ||
newProjectDir, | ||
configDir: config[ESLINT].config, | ||
}, | ||
}); | ||
await installProjectPlugin({ | ||
pluginName: LINT_STAGED, | ||
devDep: config[LINT_STAGED].devDep, | ||
packageManager, | ||
subPlugins: config[LINT_STAGED].subPlugins, | ||
snippet: { | ||
action: config[LINT_STAGED].snippet.action, | ||
inputCode: config[LINT_STAGED].snippet.inputCode, | ||
outputFile: config[LINT_STAGED].snippet.outputFile, | ||
generatorRootDir, | ||
newProjectDir, | ||
}, | ||
config: { | ||
generatorRootDir, | ||
newProjectDir, | ||
configDir: config[LINT_STAGED].config, | ||
}, | ||
}); | ||
await installProjectPlugin({ | ||
pluginName: HUSKY, | ||
devDep: config[HUSKY].devDep, | ||
packageManager, | ||
config: { | ||
generatorRootDir, | ||
newProjectDir, | ||
configDir: config[HUSKY].config, | ||
}, | ||
}); | ||
// Run husky git hook | ||
await execShellPromise(`npx husky install`); | ||
// Run linting commands | ||
console.log('Running prettier and eslint...', '\n'); | ||
await execShellPromise(`npx prettier --write .`); | ||
await execShellPromise(`npx eslint --fix .`); | ||
console.log('\n', 'New repository initialized.'); | ||
} | ||
catch (er) { | ||
// eslint-disable-next-line no-console | ||
console.error(er); | ||
} | ||
finally { | ||
// Move back to main dir | ||
process.chdir(userWorkingDir); | ||
} | ||
}; | ||
export default createNextProject; |
@@ -1,4 +0,4 @@ | ||
export { readDirPromise, execPromise } from './promisify.js'; | ||
export { readDirPromise, execShellPromise } from './promisify.js'; | ||
export { default as removeDir } from './removeDir.js'; | ||
export { default as projectNameValidation } from './projectNameValidation/projectNameValidation.js'; | ||
export { default as convertStringsToNewlineList } from './convertStringsToNewlineList/convertStringsToNewlineList.js'; |
@@ -5,2 +5,2 @@ import fs from 'fs'; | ||
export const readDirPromise = promisify(fs.readdir); | ||
export const execPromise = promisify(shell.exec); | ||
export const execShellPromise = promisify(shell.exec); |
{ | ||
"name": "frontend-project-generator", | ||
"version": "0.1.1", | ||
"version": "0.2.0-alpha-1", | ||
"description": "Intent frontend project generator", | ||
@@ -13,3 +13,4 @@ "main": "./lib/index.js", | ||
"scripts": { | ||
"build": "npm run clean && tsc", | ||
"build": "npm run clean && tsc && npm run copy-config", | ||
"copy-config": "cp -r ./configs ./lib", | ||
"clean": "rimraf lib", | ||
@@ -43,4 +44,4 @@ "format:check": "prettier --check .", | ||
"devDependencies": { | ||
"@commitlint/cli": "^17.0.3", | ||
"@commitlint/config-conventional": "^17.0.3", | ||
"@commitlint/cli": "^17.1.2", | ||
"@commitlint/config-conventional": "^17.1.0", | ||
"@types/inquirer": "^8.2.1", | ||
@@ -51,8 +52,10 @@ "@types/jest": "^28.1.6", | ||
"@types/validate-npm-package-name": "^4.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.32.0", | ||
"@typescript-eslint/parser": "^5.32.0", | ||
"eslint": "^8.21.0", | ||
"@typescript-eslint/eslint-plugin": "^5.38.1", | ||
"@typescript-eslint/parser": "^5.38.1", | ||
"create-next-app": "^12.3.1", | ||
"eslint": "^8.24.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-airbnb-typescript": "^17.0.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"husky": "^8.0.1", | ||
@@ -65,3 +68,3 @@ "jest": "^28.1.3", | ||
"ts-node": "^10.8.2", | ||
"typescript": "^4.7.4" | ||
"typescript": "^4.8.4" | ||
}, | ||
@@ -68,0 +71,0 @@ "lint-staged": { |
@@ -5,2 +5,23 @@ # frontend-project-generator | ||
### Project default plugins | ||
| Plugins | Version | Remarks | | ||
| --------------------------------- | -------- | -------------------------------- | | ||
| create-next-app | 12.3.1 | generator base installing module | | ||
| --------------------------------- | -------- | -------------------------------- | | ||
| prettier | 2.7.1 | generated repository plugin | | ||
| --------------------------------- | -------- | -------------------------------- | | ||
| eslint | 8.24.0 | generated repository plugin | | ||
| eslint-config-prettier | 8.5.0 | eslint dependent plugin | | ||
| eslint-plugin-prettier | 4.2.1 | eslint dependent plugin | | ||
| @typescript-eslint/parser | 5.38.1 | eslint dependent plugin | | ||
| @typescript-eslint/eslint-plugin | 5.38.1 | eslint dependent plugin | | ||
| eslint-import-resolver-typescript | 3.5.0 | eslint dependent plugin | | ||
| --------------------------------- | -------- | -------------------------------- | | ||
| husky | 8.0.1 | generated repository plugin | | ||
| --------------------------------- | -------- | -------------------------------- | | ||
| lint-staged | 13.0.3 | generated repository plugin | | ||
| @commitlint/cli | 17.1.2 | lint-staged dependent plugin | | ||
| @commitlint/config-conventional | 17.1.0 | lint-staged dependent plugin | | ||
### Project requirements | ||
@@ -43,1 +64,25 @@ | ||
``` | ||
### Frontend Project Generator development | ||
- Plugins update: | ||
- update plugin `version` property inside `plugins.config.ts` file. | ||
- test if package works, by running script locally. | ||
- update plugin version inside `README.md` file, section > `Project default plugins` | ||
- update plugin in frontend-project-generator `devDependencies` (dependaBot purposes). | ||
- Plugins config file update: | ||
- check if config file exist in `configs/${pluginName}` directory: | ||
- exist: | ||
- update file | ||
- doesn't exist: | ||
- add file | ||
- update plugin `config` property inside `plugins.config.ts` file. | ||
- add `createNextProject.ts > installProjectPlugin` function parameter object `config` property . | ||
- add property to existing `.json` file: | ||
- go to `configs/snippets/addProperty` | ||
- add `${plugin}.json` file with plugin name and wanted content | ||
- update plugin `snippets` property inside `plugins.config.ts` file. Property should consist of with three mandatory properties (`action`, `inputCode`, `outputFile`) | ||
- add snippet property for wanted project in `createNextProject.ts > installProjectPlugin` functions object property | ||
- edit property to existing `.json` file: | ||
- go to `configs/snippets/editProperty` | ||
- edit `${plugin}.json` file and amend its content. |
// Testing constants | ||
export const TEST_PACKAGE_NAME = 'test'; | ||
export const TEST_PACKAGE_NAME = 'test-repository'; | ||
export const TEST_PACKAGE_NAME_2 = '..'; | ||
@@ -24,1 +24,25 @@ export const TEST_PACKAGE_NAME_3 = 'te-st.1_test'; | ||
export const NEWLINE_ENCODING = '\n'; | ||
// Main Package | ||
export const CREATE_NEXT_APP = 'create-next-app'; | ||
// Plugins | ||
export const PRETTIER = 'prettier'; | ||
export const ESLINT = 'eslint'; | ||
export const HUSKY = 'husky'; | ||
export const LINT_STAGED = 'lint-staged'; | ||
// Node commands | ||
export const NPX = 'npx'; | ||
export const USE_NPM = '--use-npm'; | ||
export const FLAG_TYPESCRIPT = '--typescript'; | ||
// Package Manager commands (npm) | ||
export const NPM_INSTALL = 'npm install'; | ||
export const FLAG_SAVE_DEV = '--save-dev'; | ||
export const FLAG_SAVE_EXACT = '--save-exact'; | ||
// Package Manager commands (yarn) | ||
export const YARN_ADD = 'yarn add'; | ||
export const FLAG_DEV = '--dev'; | ||
export const FLAG_EXACT = '--exact'; |
@@ -0,6 +1,20 @@ | ||
/* eslint-disable no-console */ | ||
import pkt from 'inquirer'; | ||
import path from 'path'; | ||
import EQuestions from '../../questions/questions.types.js'; | ||
import { execShellPromise } from '../../utils/index.js'; | ||
import installProjectPlugin from '../installProjectPlugin/installProjectPlugin.js'; | ||
import { | ||
CREATE_NEXT_APP, | ||
FLAG_TYPESCRIPT, | ||
NPX, | ||
USE_NPM, | ||
ESLINT, | ||
HUSKY, | ||
LINT_STAGED, | ||
PRETTIER, | ||
} from '../../constants/index.js'; | ||
import config from '../../plugins.config.js'; | ||
import combinePluginWithVersion from '../../utils/combinePluginWithVersion/combinePluginWithVersion.js'; | ||
import { EPackageManager } from '../../enums/index.js'; | ||
import { execPromise } from '../../utils/index.js'; | ||
@@ -13,13 +27,109 @@ const createNextProject = | ||
} | ||
const packageManager = promptAnswers[EQuestions.PACKAGE_MANAGER]; | ||
const userWorkingDir = process.cwd(); | ||
const generatorRootDir = path.dirname(process.argv[1]); | ||
try { | ||
await execPromise( | ||
`npx create-next-app ${projectName} ${ | ||
promptAnswers[EQuestions.PACKAGE_MANAGER] === EPackageManager.NPM | ||
? `--use-npm` | ||
: '' | ||
} --typescript` | ||
const createNextApp = combinePluginWithVersion( | ||
CREATE_NEXT_APP, | ||
config[CREATE_NEXT_APP].version | ||
); | ||
await execShellPromise( | ||
`${NPX} ${createNextApp} ${projectName} ${FLAG_TYPESCRIPT} ${ | ||
packageManager === EPackageManager.NPM ? USE_NPM : '' | ||
}` | ||
); | ||
const newProjectDir = path.resolve( | ||
path.join(userWorkingDir, projectName) | ||
); | ||
// Move to newly created project via cli | ||
process.chdir(newProjectDir); | ||
await installProjectPlugin({ | ||
pluginName: PRETTIER, | ||
pluginVersion: config[PRETTIER].version, | ||
devDep: config[PRETTIER].devDep, | ||
packageManager, | ||
snippet: { | ||
action: config[PRETTIER].snippet.action, | ||
inputCode: config[PRETTIER].snippet.inputCode, | ||
outputFile: config[PRETTIER].snippet.outputFile, | ||
generatorRootDir, | ||
newProjectDir, | ||
}, | ||
config: { | ||
generatorRootDir, | ||
newProjectDir, | ||
configDir: config[PRETTIER].config, | ||
}, | ||
}); | ||
await installProjectPlugin({ | ||
pluginName: ESLINT, | ||
devDep: config[ESLINT].devDep, | ||
packageManager, | ||
nextDefaultPackage: config[ESLINT].nextDefaultPackage, | ||
subPlugins: config[ESLINT].subPlugins, | ||
snippet: { | ||
action: config[ESLINT].snippet.action, | ||
inputCode: config[ESLINT].snippet.inputCode, | ||
outputFile: config[ESLINT].snippet.outputFile, | ||
generatorRootDir, | ||
newProjectDir, | ||
}, | ||
config: { | ||
generatorRootDir, | ||
newProjectDir, | ||
configDir: config[ESLINT].config, | ||
}, | ||
}); | ||
await installProjectPlugin({ | ||
pluginName: LINT_STAGED, | ||
devDep: config[LINT_STAGED].devDep, | ||
packageManager, | ||
subPlugins: config[LINT_STAGED].subPlugins, | ||
snippet: { | ||
action: config[LINT_STAGED].snippet.action, | ||
inputCode: config[LINT_STAGED].snippet.inputCode, | ||
outputFile: config[LINT_STAGED].snippet.outputFile, | ||
generatorRootDir, | ||
newProjectDir, | ||
}, | ||
config: { | ||
generatorRootDir, | ||
newProjectDir, | ||
configDir: config[LINT_STAGED].config, | ||
}, | ||
}); | ||
await installProjectPlugin({ | ||
pluginName: HUSKY, | ||
devDep: config[HUSKY].devDep, | ||
packageManager, | ||
config: { | ||
generatorRootDir, | ||
newProjectDir, | ||
configDir: config[HUSKY].config, | ||
}, | ||
}); | ||
// Run husky git hook | ||
await execShellPromise(`npx husky install`); | ||
// Run linting commands | ||
console.log('Running prettier and eslint...', '\n'); | ||
await execShellPromise(`npx prettier --write .`); | ||
await execShellPromise(`npx eslint --fix .`); | ||
console.log('\n', 'New repository initialized.'); | ||
} catch (er) { | ||
// eslint-disable-next-line no-console | ||
console.error(er); | ||
} finally { | ||
// Move back to main dir | ||
process.chdir(userWorkingDir); | ||
} | ||
@@ -26,0 +136,0 @@ }; |
@@ -1,4 +0,4 @@ | ||
export { readDirPromise, execPromise } from './promisify.js'; | ||
export { readDirPromise, execShellPromise } from './promisify.js'; | ||
export { default as removeDir } from './removeDir.js'; | ||
export { default as projectNameValidation } from './projectNameValidation/projectNameValidation.js'; | ||
export { default as convertStringsToNewlineList } from './convertStringsToNewlineList/convertStringsToNewlineList.js'; |
@@ -6,2 +6,2 @@ import fs from 'fs'; | ||
export const readDirPromise = promisify(fs.readdir); | ||
export const execPromise = promisify(shell.exec); | ||
export const execShellPromise = promisify(shell.exec); |
@@ -17,3 +17,3 @@ { | ||
"include": ["src"], | ||
"exclude": ["node_modules"] | ||
"exclude": ["node_modules", "configs"] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68743
85
1651
87
23
5