Skip to content

Commit

Permalink
feat: add access level and rename owner to org name (#44)
Browse files Browse the repository at this point in the history
affects: @medly/create-component, @medly/create-module, @medly/starter-shared
  • Loading branch information
gmukul01 authored Sep 1, 2021
1 parent 994c441 commit 3b6289b
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 30 deletions.
15 changes: 9 additions & 6 deletions packages/component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ Then follow the prompts or you can run command `yarn create @medly/component <pr

### Options

| Flags | Description | Choices | Default |
| ----------------------------------------- | ------------------------------ | --------------------- | ------- |
| `-V, --version` | output the version number | | |
| `-p, --package-manager <package-manager>` | package manager | `npm`, `yarn`, `pnpm` | `yarn` |
| `-i, --interactive` | show interactive questionnaire | | |
| `-h, --help` | display help for command | | |
| Flags | Description | Choices | Default |
| ----------------------------------------- | ------------------------------ | ---------------------- | -------- |
| `-V, --version` | output the version number | | |
| `-o, --org <org>` | name of the organization | | |
| `-r, --registry <registry>` | registry to publish the module | `npm`, `github` | `npm` |
| `-p, --package-manager <package-manager>` | package manager | `npm`, `yarn`, `pnpm` | `yarn` |
| `-a, --access <access>` | access level of the component | `public`, `restricted` | `public` |
| `-i, --interactive` | show interactive questionnaire | | |
| `-h, --help` | display help for command | | |

## Features

Expand Down
5 changes: 4 additions & 1 deletion packages/component/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ async function init() {
const program = new commander.Command(packageJson.name)
.version(packageJson.version)
.arguments('[project-name]')
.option('-o, --owner <owner>', 'owner of the package')
.option('-o, --org <org>', 'name of the organization')
.addOption(new Option('-r, --registry <registry>', 'registry to publish the module').choices(['npm', 'github']).default('npm'))
.addOption(
new Option('-p, --package-manager <package-manager>', 'package manager').choices(['npm', 'yarn', 'pnpm']).default('yarn')
)
.addOption(
new Option('-a, --access <access>', 'Access level of the component').choices(['public', 'restricted']).default('public')
)
.option('-i, --interactive', 'show interactive questionnaire')
.description('An application for creating scaffolding for react component')
.usage(`${chalk.green('<project-name>')} [options]`)
Expand Down
17 changes: 14 additions & 3 deletions packages/component/bin/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const questions = cmdOptions => [
},
{
type: 'input',
name: 'owner',
message: 'Owner of the package',
when: () => !cmdOptions.owner || !cmdOptions.interactive
name: 'org',
message: 'Name of the organization',
when: () => !cmdOptions.org || !cmdOptions.interactive
},
{
type: 'list',
Expand All @@ -34,6 +34,17 @@ const questions = cmdOptions => [
],
default: 'yarn',
when: () => !cmdOptions.projectName || cmdOptions.interactive
},
{
type: 'list',
name: 'access',
message: 'Access level of the component',
choices: [
{ name: chalk.hex('#00FF00')('Public'), value: 'public' },
{ name: chalk.hex('#FFFF00')('Restricted'), value: 'restricted' }
],
default: cmdOptions.access,
when: () => !cmdOptions.projectName || cmdOptions.interactive
}
];

Expand Down
2 changes: 1 addition & 1 deletion packages/component/template/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"types": "dist/es/index.d.ts",
"files": ["dist"],
"publishConfig": {
"registry": "https://registry.npmjs.org/medly"
"registry": "https://registry.npmjs.org"
},
"scripts": {
"prepare": "husky install",
Expand Down
6 changes: 3 additions & 3 deletions packages/module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ Then follow the prompts or you can run command `yarn create @medly/module <proje
| Flags | Description | Choices | Default |
| ----------------------------------------- | ------------------------------ | -------------------------- | ------------ |
| `-V, --version` | output the version number | | |
| `-o, --owner <owner>` | owner of the package | | |
| `-r, --registry <registry>` | registry to publish the module | `npm`, `github` | |
| `-o, --org <org>` | name of the organization | | |
| `-r, --registry <registry>` | registry to publish the module | `npm`, `github`, `none` | `none` |
| `-p, --package-manager <package-manager>` | package manager | `npm`, `yarn`, `pnpm` | `yarn` |
| `-a, --access <access>` | access level of the module | `public`, `restricted` | `public` |
| `-l, --language <language>` | language | `typescript`, `javascript` | `typescript` |
| `-i, --interactive` | show interactive questionnaire | | |
| `-h, --help` | display help for command | | |
Expand All @@ -40,5 +41,4 @@ It sets up the following:
8. `semantic-release` to bump the version and update the `CHANGELOG`.
9. `typescript` also, if you choose `typescript` as language option.


![create-module](https://user-images.githubusercontent.com/3636885/123096440-bab59f00-d44c-11eb-9df0-412145d21abc.gif)
11 changes: 7 additions & 4 deletions packages/module/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ async function init() {
const program = new commander.Command(packageJson.name)
.version(packageJson.version)
.arguments('[project-name]')
.option('-o, --owner <owner>', 'owner of the package')
.option('-o, --org <org>', 'name of the organization')
.addOption(
new Option('-r, --registry <registry>', 'registry to publish the module').choices(['none', 'npm', 'github']).default('none')
)
.addOption(
new Option('-p, --package-manager <package-manager>', 'package manager').choices(['npm', 'yarn', 'pnpm']).default('yarn')
)
.addOption(
new Option('-a, --access <access>', 'Access level of the module').choices(['public', 'restricted']).default('public')
)
.addOption(new Option('-l, --language <language>', 'language').choices(['typescript', 'javascript']).default('typescript'))
.option('-i, --interactive', 'show interactive questionnaire')
.description('An application for generating either ts module or simple ts app')
.usage(`${chalk.green('<project-name>')} [options]`)
.action((name, options) => {
if (options.registry && options.registry !== 'none' && !options.owner) {
console.error(chalk.red('Error: ') + '-o, --owner <owner> required when you have added registry option');
if (options.registry && options.registry !== 'none' && !options.org) {
console.error(chalk.red('Error: ') + '-o, --org <org> required when you have added registry option');
process.exit(1);
}
cmdProjectName = name;
Expand Down Expand Up @@ -87,7 +90,7 @@ async function init() {
]);

if (registry && registry !== 'none') {
updateTokensInGithubWorkflow();
registry === 'github' && updateTokensInGithubWorkflow();
console.log(
chalk.bold('\nNote: ') +
'Add ' +
Expand Down
17 changes: 14 additions & 3 deletions packages/module/bin/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const questions = cmdOptions => [
},
{
type: 'input',
name: 'owner',
message: 'Owner of the package',
when: answers => !cmdOptions.owner && answers.registry && answers.registry !== 'none'
name: 'org',
message: 'Name of the organization',
when: answers => !cmdOptions.org && answers.registry && answers.registry !== 'none'
},
{
type: 'list',
Expand All @@ -45,6 +45,17 @@ const questions = cmdOptions => [
],
default: cmdOptions.packageManager,
when: () => !cmdOptions.projectName || cmdOptions.interactive
},
{
type: 'list',
name: 'access',
message: 'Access level of the module',
choices: [
{ name: chalk.hex('#00FF00')('Public'), value: 'public' },
{ name: chalk.hex('#FFFF00')('Restricted'), value: 'restricted' }
],
default: cmdOptions.access,
when: () => !cmdOptions.projectName || cmdOptions.interactive
}
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "ISC",
"type": "module",
"publishConfig": {
"registry": "https://registry.npmjs.org/medly"
"registry": "https://registry.npmjs.org"
},
"scripts": {
"prepare": "husky install",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "Medly",
"license": "ISC",
"publishConfig": {
"registry": "https://registry.npmjs.org/medly"
"registry": "https://registry.npmjs.org"
},
"scripts": {
"prepare": "husky install",
Expand Down
15 changes: 8 additions & 7 deletions packages/shared/src/addProjectDetails.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
const fs = require('fs-extra');
const path = require('path');

module.exports = ({ projectName, registry, owner }) => {
module.exports = ({ projectName, registry, org, access }) => {
const projectRoot = path.resolve(projectName),
package = fs.readJSONSync(path.join(projectRoot, 'template.json'));

// Delete template.json file
fs.removeSync(path.join(projectRoot, 'template.json'));

// Update basic details based on the options chosen
package.author = owner || '';
package.author = org || '';
if (registry && registry !== `none`) {
package.name = `@${owner}/${projectName}`;
package.name = `@${org}/${projectName}`;
package.repository = {
type: 'git',
url: `git://github.com/${owner}/${projectName}.git`
url: `git://github.com/${org}/${projectName}.git`
};
package.homepage = `https://github.com/${owner}/${projectName}#readme`;
package.bugs = `https://github.com/${owner}/${projectName}/issues`;
package.publishConfig.registry = `${registry === 'github' ? 'https://npm.pkg.github.com' : 'https://registry.npmjs.org'}/${owner}`;
package.homepage = `https://github.com/${org}/${projectName}#readme`;
package.bugs = `https://github.com/${org}/${projectName}/issues`;
package.publishConfig.registry = `${registry === 'github' ? 'https://npm.pkg.github.com' : 'https://registry.npmjs.org'}`;
package.publishConfig.access = access;
} else {
package.name = projectName;
}
Expand Down

0 comments on commit 3b6289b

Please sign in to comment.