Update configuration file with Ant - javascript

I'm not looking for a full working solution for my question, but for a recommendation on how to achieve something.
I have a web application with a javascript file which contains some constants and default values.
I'm using ant to build and package the application, so I have 2 targets, one for development and another one for production. The thing is, in my configuration file some constants have a default value for production but another one in development.
Right now, if I'm developing and I want to prepare a delivery for production I have to:
- manually edit configuration file to set right values (comment some lines and uncomment some others)
- run ant production target
I'd like to automate this, so when I run my ant target for production, the correct default values are used in my configuration javascript file. Can ant achieve this (search for some lines in a javascript file and edit that file)? is this a bad practice? any other way to do this?

As a suggestion, I would have two configuration files -dev and -prod and then use ant to move the right file to the build dir, renaming it if needed
You can write to a file using the echo task
https://ant.apache.org/manual/Tasks/echo.html
Replace Task is a directory based task for replacing the occurrence of a given string with another string in selected file.
https://ant.apache.org/manual/Tasks/replace.html

Related

Bazel auto generate dependencies for ts_library

Is it possible to auto-generate the dependencies of a bazel target? It seems like there should be a way to look at the imports of the module and know which bazel dependencies are needed at least in a lot of cases common cases. This could save a lot of boilerplate code.
load("#npm_bazel_typescript//:index.bzl", "ts_library")
ts_library(
name = "lib",
srcs = glob(include = ["**/*.ts"]),
# Is there any easy way to generate this list?
deps = [],
)
I know there are packages for Java that do this. https://github.com/johnynek/bazel-dep. I haven't been able to find anything for any other languages.
If it doesn't exist I think it could be pretty straightforward to write. Create a template file for you to work off of creating the real BUILD file. Then run typescript to pull the AST of the module. Look through the imports. The 3rd part imports will be easier since they should resolve to an npm module.
For other files that may or may not be in this library then there might be a way to query what package they live int. That could probably work. Any pointers would be very much appreciated.
Disclosure: I am one of the authors of this library.
https://github.com/evertz/bzlgen
It can generate BUILD files (or, more precisely it generates buildozer commands) for Angular (ng_module) and SCSS (scss_library and scss_binary) libs.
I've just moved this in to opensource from our internal repo. It works in a similar way to what you suggest, however it doesn't query for labels. It uses a file or directory as a starting point, parse into an AST, query the AST to fetch imports and reexports, convert the paths into labels.
Adding ts_library support is a logical next step.
It doesn't always get you a 100% working BUILD file currently, but it will get you ~80-90% of the way there, and do the boilerplate parts for you.
Another approach would be to interact with the Gazelle API, and manipulate the BUILD files directly.
A previous version of this tool generated the BUILD files from a string and it got difficult to work with when manipulating the files in other ways.

Azure DevOps Update Variable Inside Code Before Deploy

Is it possible for Azure DevOps to update part of my code when release kicks in?
For example, I have a setting file inside my react app. This setting file has export const ISPROD = false in it. I need Azure DevOps to change this false value to true before it builds the react app and deploys it. Is that possible?
Note: My Server build is Linux.
You could update your code in your javascript files using the "Replace Tokens" task e.g.
- task: replacetokens#3
inputs:
targetFiles: "yourJavascriptFile.js"
encoding: "auto"
writeBOM: true
verbosity: "detailed"
actionOnMissing: "warn"
keepToken: false
tokenPrefix: "#{"
tokenSuffix: "}#"
displayName: Perform variable substitution in javascript file file
You'd add this task before the task you use to build your application.
In your javascript file you would write the variables to be replaced as e.g.
export const ISPROD = #{IS_PROD}#
This task when run would then replace "#{IS_PROD}#" with your Azure Devops variable named "IS_PROD" with it's value set as true.
Since you're on linux you can just add the bash task or shell script task to your build and add an inline script or path to a script in your repo that does the setting update.
You'll need to take a look at the available environment variables in your pipeline that you can use in your script to access the working directory of your code.
You can optionally specify conditions under which the task runs. For example, I do something very similar when versioning our components for release, which are only done during builds triggered by a git tag.
Here's a free Visual Studio Marketplace Pipeline task that will do the trick: Replace Text in Source Files
This one will also work: RegexReplace Build Task
If you want to make a custom solution following might help full to you
Go with Bash Task in azure pipeline
In Yaml steps define inline Ex:
steps:
task: Bash#ReplaceTextInFile
inputs:
targetType: 'inline'
script: bashscript
use sed command to replace text in your file.

How to import Parcel JS generated bundles into "legacy" application?

I'm working with an application with a front end built using old school techniques (jQuery and direct DOM manipulation) and I would like to move it over to ES8 and React. Since this is a rather large and complex application, this move will have to be gradual, meaning both the legacy code and React code will have to live side by side for some time.
The legacy code uses a home brew "module loader", which need to keep working. I've been looking at using Webpack and its configuration option libraryTarget: 'var', which basically outputs each entry point into a global variable. This works but the performance (build time) of Webpack isn't good enough so I have been looking at using ParcelJS instead.
Is it possible to achive something similar as Webpack's libraryTarget: 'var' with ParcelJS? Basically, in a "legacy HTML file" (which often times is server generated and may contain data I need to pass on to the ES8 modules), I would like to be able to do somethings along lines of
<script src="dist/js/ABundle.js"></script> <!-- Bundle created by ParceJS -->
<script>
var data = {/* JSON generated by server */};
var ABundle = require('ABundle'); // Export defined in ABundle.js.
ABundle.render(data); // Function exported in ABundle.
</script>
Note that i cannot pass my HTML files as entry points to ParcelJS as they contain references to Javascript files using the homebrew module loader which won't play nice with ParcelJS. I only want to pass the ES8 modules as entry points to ParcelJS and use them side by side with the home brew module loader.
EDIT: Clarified that legacy HTML is in fact server generated.

not to minify the js when degugging the code minify-maven-plugin samaxes

I am using minify-maven-plugin of com.samaxes.maven to minify my js files and to make package into a single file. But during the development/debugging i need to set a configuration so that it does not minify the js but still packages the js in a single file. Please help me.
According to the documentation as of 1.5.2 you can specify
<skipMinify>true</skipMinify>
If you use a property then you can provide a default value in the pom and override it on the command line. Or you could use a clever combination of profiles and their activations to automatically set it depending on your environment (for example, CI vs development).

What is the proper way to set up a jsbindings class with cocos2d-js?

The documentation explains how to generates jsbindings, but it does not tell the proper way to integrate it into a project. What steps do I must follow? Where should I store my manually written C++ files? Where should I store the generated js and c++ files? What CMakeList.txt files should I edit?
I believe I found some way to do this.
Please confirm me I don't do anything wrong (I copied this message on the official forum).
Let's integrate the js-bindings test samples in a cocos2d-js project.
First generate the tests : cd tools/bindings-generator/test && ./test.sh && cd ../../.. (that may need some configuration). At the moment it fails on Linux because of missing headers but I submited a merge request.
Copy files into the project
cp -R tools/bindings-generator/test/simple_test/ frameworks/runtime-src/Classes
cp -R tools/bindings-generator/test/simple_test_bindings/ frameworks/runtime-src/Classes
Update CMakeLists.txt and frameworks/runtime-src/proj.android/jni/Android.mk and add the added files autogentestbindings.cpp and simple_class.cpp to the target lists.
Register the jsb functions in the runtime sources in frameworks/runtime-src/Classes/AppDelegate.cpp by adding sc->addRegisterCallback(register_all_autogentestbindings); in AppDelegate::applicationDidFinishLaunching
Then classes defined in simple_class.h are available in Javascript. The following JS code should display 1337.
console.log((new SimpleNativeClass(1337)).getSomeField())

Categories

Resources