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

.move method accept answers only in first arg #10

Open
Akiyamka opened this issue Feb 17, 2020 · 0 comments
Open

.move method accept answers only in first arg #10

Akiyamka opened this issue Feb 17, 2020 · 0 comments

Comments

@Akiyamka
Copy link
Contributor

Akiyamka commented Feb 17, 2020

I mentioned in #9 that the absence of dynamics in the second argument causes some inconvenience.

Current situation

Currently i can't create new folder with variable name.

cliOf('Create module', module)
 .ask({
   name: 'moduleName',
   message: 'How we name it?',
   type: 'input'
 })
 .move(answers => ([
   './template'
 ]), `../src/modules/???`)

And I can't understand how i can rename the newly created folder after creating it with some temporary unique name. For example:

const tempHash = Date.now();

cliOf('Create module', module)
  .ask({
    name: 'moduleName',
    message: 'How we name it?',
    type: 'input'
  })
  .move(answers => ([
    './template'
  ]), `../src/modules/${tempHash}`)
 .rename(`../src/modules/${tempHash}`, (answers) => {
      // how I can rename folder, instead file name?
  })

Workaround (work only for unix systems ⚠️ ):

  .call(async ({ moduleName }) => {
    await childProcess.spawn(
      `cp -r ./generators/module ./k2-packages/${moduleName}/`
    );
  })

Proposed api:

I think a simpler api that will cover most of the use cases will look something like this

Just copy with renaming:

cliOf('Create module', module)
  .copy('./templates/module/index.ts', './src/NewModule/main.ts')

/* result:

ls ./src/NewModule/  ⇐ (NewModule folder is being created if not exist before that)
main.ts

*/
 

Copy by mask:

cliOf('Create module', module)
  .copy('./templates/module/*.ts', './src/NewModule/')

/* result:

ls ./src/NewModule/
index.ts
utils.ts
some.ts

*/

Copy files using answers (in both arguments):

cliOf('Create module', module)
  .ask({
    name: 'type',
    message: 'What type of it?',
    type: 'input'
  })
  .ask({
    name: 'name',
    message: 'How we name it?',
    type: 'input'
  })
  .copy(answers => ([
     `./templates/${answers.type}/*.ts`,
     `./src/${answers.name}/`
   ))

/* result:

ls ./src/myAwesomeModule/
index.ts
utils.ts
some.ts

*/

Copy in place (Optional - just for consistent)

cliOf('Clone module', module)

  .copy(`./src/module/`)
/*
  ls ./src/module_copy/
  index.ts
  utils.ts
  some.ts
*/

  .copy(`./src/module/*`)
/*
  ls ./src/module/
  index.ts
  index_copy.ts
  utils.ts
  utils_copy.ts
  some.ts
  some_copy.ts
*/

  .copy(`./src/module/some.ts*`)
/*
  ls ./src/module/
  index.ts
  index_copy.ts
  utils.ts
  utils_copy.ts
  some.ts
  some_copy.ts
  some_copy_copy.ts
*/
@Akiyamka Akiyamka changed the title move method accept answers only in first arg .move method accept answers only in first arg Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant