mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-04 03:43:34 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			70 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
/**
 | 
						|
 * Component Generator
 | 
						|
 */
 | 
						|
 | 
						|
const componentExists = require('../utils/componentExists');
 | 
						|
 | 
						|
module.exports = {
 | 
						|
  description: 'Add an unconnected component',
 | 
						|
  prompts: [{
 | 
						|
    type: 'list',
 | 
						|
    name: 'type',
 | 
						|
    message: 'Select the type of component',
 | 
						|
    default: 'Stateless Function',
 | 
						|
    choices: () => ['ES6 Class', 'Stateless Function'],
 | 
						|
  }, {
 | 
						|
    type: 'input',
 | 
						|
    name: 'name',
 | 
						|
    message: 'What should it be called?',
 | 
						|
    default: 'Button',
 | 
						|
    validate: (value) => {
 | 
						|
      if ((/.+/).test(value)) {
 | 
						|
        return componentExists(value) ? 'A component or container with this name already exists' : true;
 | 
						|
      }
 | 
						|
 | 
						|
      return 'The name is required';
 | 
						|
    },
 | 
						|
  }, {
 | 
						|
    type: 'confirm',
 | 
						|
    name: 'wantCSS',
 | 
						|
    default: true,
 | 
						|
    message: 'Does it have styling?',
 | 
						|
  }],
 | 
						|
  actions: (data) => {
 | 
						|
    // Generate index.js and index.test.js
 | 
						|
    const actions = [{
 | 
						|
      type: 'add',
 | 
						|
      path: '../../../../../admin/src/components/{{properCase name}}/index.js',
 | 
						|
      templateFile: data.type === 'ES6 Class' ? './component/es6.js.hbs' : './component/stateless.js.hbs',
 | 
						|
      abortOnFail: true,
 | 
						|
    }, {
 | 
						|
      type: 'add',
 | 
						|
      path: '../../../../../admin/src/components/{{properCase name}}/tests/index.test.js',
 | 
						|
      templateFile: './component/test.js.hbs',
 | 
						|
      abortOnFail: true,
 | 
						|
    }];
 | 
						|
 | 
						|
    // If they want a SCSS file, add styles.scss
 | 
						|
    if (data.wantCSS) {
 | 
						|
      actions.push({
 | 
						|
        type: 'add',
 | 
						|
        path: '../../../../../admin/src/components/{{properCase name}}/styles.scss',
 | 
						|
        templateFile: './component/styles.scss.hbs',
 | 
						|
        abortOnFail: true,
 | 
						|
      });
 | 
						|
    }
 | 
						|
 | 
						|
    // If they want a i18n messages file
 | 
						|
    if (data.wantMessages) {
 | 
						|
      actions.push({
 | 
						|
        type: 'add',
 | 
						|
        path: '../../../../../admin/src/components/{{properCase name}}/messages.js',
 | 
						|
        templateFile: './component/messages.js.hbs',
 | 
						|
        abortOnFail: true,
 | 
						|
      });
 | 
						|
    }
 | 
						|
 | 
						|
    return actions;
 | 
						|
  },
 | 
						|
};
 |