Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过节点自动设置网页包项目_Javascript_Node.js_Terminal - Fatal编程技术网

Javascript 通过节点自动设置网页包项目

Javascript 通过节点自动设置网页包项目,javascript,node.js,terminal,Javascript,Node.js,Terminal,我的目标是通过节点命令crateEntireWebbackProject.js文件设置一个webpack项目 我想从js文件在shell上执行命令,这样我就可以让它们自动运行,以后还可以包含项目的自定义规范 js文件不是来自webpack,而是包含从头开始创建wepback项目并进行安装等的命令。只需键入node createEntireWebpackProject.js,您就不需要从头开始编写它。最佳实践是使用。有很多带有网页包的生成器。例如: const Generator = requir

我的目标是通过节点命令crateEntireWebbackProject.js文件设置一个webpack项目

我想从js文件在shell上执行命令,这样我就可以让它们自动运行,以后还可以包含项目的自定义规范


js文件不是来自webpack,而是包含从头开始创建wepback项目并进行安装等的命令。只需键入
node createEntireWebpackProject.js
,您就不需要从头开始编写它。最佳实践是使用。有很多带有网页包的生成器。例如:

const Generator = require('yeoman-generator');
const mkdirp = require('mkdirp');
const path = require('path');

module.exports = class extends Generator {
  prompting() {
    this.log('Welcome to the classy example generator!');

    const prompts = [
      {
        type: 'input',
        name: 'name',
        message: 'Name?',
        default: this.appname,
      }];

    return this.prompt(prompts).then((props) => {
      this.props = props;
    });
  }

  default() {
    if (path.basename(this.destinationPath()) !== this.props.name) {
      this.log(
        `Your application must be inside a folder named ${this.props.name}`);
      this.log('I\'ll automatically create this folder.');
      mkdirp(this.props.name);
      this.destinationRoot(this.destinationPath(this.props.name));
    }
  }

  writing() {
    this.createPackageJson();
    this.copyFiles();
    this.fillTemplates();
    this.makeCommands();
  }

  install() {
    this.npmInstall(['bunyan', 'dotenv-safe'], { save: true });
    this.npmInstall(['eslint', 'eslint-config-airbnb-base', 'eslint-plugin-import', 'jest'], { 'save-dev': true });
  }

  createPackageJson() {
    this.fs.extendJSON('package.json', {
      name: this.props.name,
      version: '0.1.0',
      main: 'src/app.js',
      scripts: {
        cs: 'eslint src/* __tests__/*',
        'cs:fix': 'eslint src/* __tests__/* --fix',
        start: 'node src/app.js',
        test: 'npm run cs && jest',
      },
      dependencies: {},
      devDependencies: {},
      engines: {
        node: '^8.1.0',
      },
      private: true,
      jest: {
        testEnvironment: 'node',
        transform: {},
        collectCoverage: true,
      },
    });
  }

  copyFiles() {
    [
      '.dockerignore',
      '.eslintrc.json',
      'src/app.js',
    ].forEach(name => this.fs.copy(this.templatePath(name), this.destinationPath(name)));
  }

  fillTemplates() {
    this.fs.copyTpl(
      this.templatePath('README.md'),
      this.destinationPath('README.md'),
      {
        name: this.props.name,
      });
  }
  makeCommands() {
      this.spawnCommandSync('git' ['init']);
      this.spawnCommandSync('git', ['add', '.']);
      this.spawnCommandSync('git', ['commit', '-am', '"yo scaffolded app"']);
  }
};

你需要package.json文件。我指的是一个外部index.js文件,它通过nodet为我设置package.json和所有其他东西。为了设置项目,不需要may命令,所以我想知道如何自己设置它,因为我以后想从photoshop读取文件,创建文件,并用webpack自动设置它们,所以我需要创建自己的代码。但是我需要写什么到js中才能使其成为命令行代码呢?Fabioo Fabiolous,我用一个例子更新了我的答案。在
makeCommands
函数中,您可以找到如何在生成器中运行命令行代码。我明白了,这很好。你认为这个系统会覆盖我的整个过程吗?你在终端上所能做的任何事情都可以由约曼自动化。