2

我有一个 python 文件作为我的 grunt 工作流程的一部分。我定义了两个构建任务:

  • 构建:开发
  • 构建:发布

当我编译'build:dev'时,我想将此行添加到我的python文件中:

...
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + dbpath
...

当我编译'build:release'时,我想将此行添加到我的python文件中:

...
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['POSTGRESQL_COLORFUL_URL']
...

编辑:修复了代码和标题中的错字

4

2 回答 2

1

您可以使用grunt-sed.

这是一个非常有用的“查找和替换”系统,内置在 Grunt 中。

从文档:

npm install grunt-sed

将此行添加到项目的 Gruntfile.js 中:

grunt.loadNpmTasks('grunt-sed');

然后在您的 build:dev 和 build:release 任务中具有以下内容:

sed: {
    database_uri: {
      path: 'path_to_your_python.py',
      pattern: '%PATTERN_IN_YOUR_PYTHON_FILE%',
      replacement: '\'sqlite:///\' + dbpath',
    }
  }

在你想要替换的python文件中,你也必须%PATTERN_IN_YOUR_PYTHON_FILE%被替换。

于 2013-08-11T20:46:03.653 回答
0

I've used a plugin called grunt-string-replace that worked very well for what I needed to do. Also, I added some custom code in my Gruntfile.js to read different environment configurations and customize the build output based on that.

I detailed the full deployment script in this post: http://dev-blog.cloud-spinners.com/2014/02/complete-grunt-deployment-workflow-for.html

I hope you find that useful.

于 2014-02-08T00:13:17.810 回答