-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: extracted create-package generator in a separate file
- Loading branch information
Alexandru Bereghici
committed
Sep 10, 2021
1 parent
d1ee316
commit a942c3f
Showing
9 changed files
with
114 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,5 @@ | ||
const fs = require('fs'); | ||
const rushJSON = require('./rush.json'); | ||
const createPackageGenerator = require('./tools/plop/create-package-generator'); | ||
|
||
module.exports = function (plop) { | ||
plop.setGenerator('create-package', { | ||
description: 'Creates a new component package', | ||
prompts: [ | ||
{ | ||
type: 'list', | ||
name: 'package-type', | ||
message: 'What type of package?', | ||
choices: [...rushJSON.approvedPackagesPolicy.reviewCategories], | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'package-name', | ||
message: 'What is the package name?', | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'package-description', | ||
message: 'What is the component package description?', | ||
}, | ||
], | ||
actions: function (data) { | ||
data['package-raw-name'] = data['package-name']; | ||
|
||
const packagePaths = data['package-name'].split('.'); | ||
let rootPath = '{{package-type}}/{{kebabCase package-name}}'; | ||
|
||
if (packagePaths.length > 1) { | ||
data['package-raw-name'] = packagePaths.pop(); | ||
rootPath = `{{package-type}}/${packagePaths.join( | ||
'/' | ||
)}/{{kebabCase package-raw-name}}`; | ||
} | ||
|
||
return [ | ||
{ | ||
type: 'add', | ||
path: `${rootPath}/src/index.ts`, | ||
templateFile: 'tools/plop-templates/create-package/package-index.hbs', | ||
skipIfExists: true, | ||
}, | ||
{ | ||
type: 'add', | ||
path: `${rootPath}/src/{{pascalCase package-raw-name}}.tsx`, | ||
templateFile: 'tools/plop-templates/create-package/package-name.hbs', | ||
skipIfExists: true, | ||
}, | ||
{ | ||
type: 'add', | ||
path: `${rootPath}/package.json`, | ||
templateFile: 'tools/plop-templates/create-package/package.hbs', | ||
skipIfExists: true, | ||
}, | ||
{ | ||
type: 'add', | ||
path: `${rootPath}/tsconfig.json`, | ||
templateFile: 'tools/plop-templates/create-package/tsconfig.hbs', | ||
skipIfExists: true, | ||
}, | ||
{ | ||
type: 'add', | ||
path: `${rootPath}/.eslintrc`, | ||
templateFile: 'tools/plop-templates/create-package/eslintrc.hbs', | ||
skipIfExists: true, | ||
}, | ||
{ | ||
type: 'add', | ||
path: `${rootPath}/.eslintignore`, | ||
templateFile: 'tools/plop-templates/create-package/eslintignore.hbs', | ||
skipIfExists: true, | ||
}, | ||
function registerPackageInRushJSON(data) { | ||
const packageName = `@bereghici/${data['package-name']}`; | ||
|
||
if (rushJSON.projects.map(p => p.packageName).includes(packageName)) { | ||
console.log('[SKIPPED] Package already registered in rush.json'); | ||
return; | ||
} | ||
|
||
rushJSON.projects.push({ | ||
packageName, | ||
projectFolder: [data['package-type'], data['package-name']] | ||
.join('/') | ||
.replace('.', '/'), | ||
reviewCategory: data['package-type'], | ||
}); | ||
|
||
fs.writeFile('./rush.json', JSON.stringify(rushJSON), err => { | ||
if (err) { | ||
console.log('Error saving rush.json', err); | ||
} else { | ||
console.log('Successfully added package in rush.json'); | ||
} | ||
}); | ||
}, | ||
]; | ||
}, | ||
}); | ||
plop.setGenerator('create-package', createPackageGenerator(plop)); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
const fs = require('fs'); | ||
const rushJSON = require('../../rush.json'); | ||
|
||
module.exports = function () { | ||
return { | ||
description: 'Creates a new component package', | ||
prompts: [ | ||
{ | ||
type: 'list', | ||
name: 'package-type', | ||
message: 'What type of package?', | ||
choices: [...rushJSON.approvedPackagesPolicy.reviewCategories], | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'package-name', | ||
message: 'What is the package name?', | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'package-description', | ||
message: 'What is the component package description?', | ||
}, | ||
], | ||
actions: function (data) { | ||
data['package-raw-name'] = data['package-name']; | ||
|
||
const packagePaths = data['package-name'].split('.'); | ||
let rootPath = '{{package-type}}/{{kebabCase package-name}}'; | ||
|
||
if (packagePaths.length > 1) { | ||
data['package-raw-name'] = packagePaths.pop(); | ||
rootPath = `{{package-type}}/${packagePaths.join( | ||
'/' | ||
)}/{{kebabCase package-raw-name}}`; | ||
} | ||
|
||
return [ | ||
{ | ||
type: 'add', | ||
path: `${rootPath}/src/index.ts`, | ||
templateFile: 'tools/plop-templates/create-package/package-index.hbs', | ||
skipIfExists: true, | ||
}, | ||
{ | ||
type: 'add', | ||
path: `${rootPath}/src/{{pascalCase package-raw-name}}.tsx`, | ||
templateFile: 'tools/plop-templates/create-package/package-name.hbs', | ||
skipIfExists: true, | ||
}, | ||
{ | ||
type: 'add', | ||
path: `${rootPath}/package.json`, | ||
templateFile: 'tools/plop-templates/create-package/package.hbs', | ||
skipIfExists: true, | ||
}, | ||
{ | ||
type: 'add', | ||
path: `${rootPath}/tsconfig.json`, | ||
templateFile: 'tools/plop-templates/create-package/tsconfig.hbs', | ||
skipIfExists: true, | ||
}, | ||
{ | ||
type: 'add', | ||
path: `${rootPath}/.eslintrc`, | ||
templateFile: 'tools/plop-templates/create-package/eslintrc.hbs', | ||
skipIfExists: true, | ||
}, | ||
{ | ||
type: 'add', | ||
path: `${rootPath}/.eslintignore`, | ||
templateFile: 'tools/plop-templates/create-package/eslintignore.hbs', | ||
skipIfExists: true, | ||
}, | ||
function registerPackageInRushJSON(data) { | ||
const packageName = `@bereghici/${data['package-name']}`; | ||
|
||
if (rushJSON.projects.map(p => p.packageName).includes(packageName)) { | ||
console.log('[SKIPPED] Package already registered in rush.json'); | ||
return; | ||
} | ||
|
||
rushJSON.projects.push({ | ||
packageName, | ||
projectFolder: [data['package-type'], data['package-name']] | ||
.join('/') | ||
.replace('.', '/'), | ||
reviewCategory: data['package-type'], | ||
}); | ||
|
||
fs.writeFile('./rush.json', JSON.stringify(rushJSON), err => { | ||
if (err) { | ||
console.log('Error saving rush.json', err); | ||
} else { | ||
console.log('Successfully added package in rush.json'); | ||
} | ||
}); | ||
}, | ||
]; | ||
}, | ||
}; | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ "name": "@bereghici/{{package-name}}", "version": "0.0.1", "description": "{{sentenceCase | ||
package-description | ||
}}", "scripts": { "build": "bereghici-scripts build --bundle cjs,esm", | ||
"lint":"bereghici-scripts lint 'src/**/*.{ts,tsx}'", "pre-commit": | ||
"bereghici-scriptspre-commit", "typecheck": "bereghici-scripts typecheck", | ||
"validate":"bereghici-scripts validate" }, "main": "dist/{{package-name}}.cjs.js", | ||
"module": "dist/{{package-name}}.esm.js", "types": "dist/index.d.ts", | ||
"dependencies": { "@babel/runtime": "^7.14.0" }, "devDependencies": { | ||
"@bereghici/bereghici-scripts": "0.0.1", "@bereghici/eslint-config": "0.0.1", | ||
"typescript": "^4.3.2" }, "peerDependencies": { "typescript": "^4.3.2" } } |
File renamed without changes.