I want to convert json to xml. I already have used https://www.npmjs.com/package/xml-js npm package. Its output like :
<0>
<name>Autofac</name>
<version>
<Version>4.9.0.0</Version>
<SpecialVersion/>
</version>
<ProjectName>PIWorks.Son.UI.Migrations</ProjectName>
<licenseFile>C:\PIWorks\PISon.UI\licenses\NuGet\Autofac#4.9.0LICENSE.txt</licenseFile>
<repository>https://opensource.org/licenses/mit-license.php</repository>
</0>
But I want to use https://www.npmjs.com/package/jsontoxml
When I used this packages output like this:
<System.Threading.Timer/><System.ValueTuple/><System.Xml.ReaderWriter/><System.Xml.XDocument/><WebGrease/><YUICompressor.NET/>
I cannot understand anything what I am wrong.
Its also my json:
{
"name": "Autofac",
"version": {
"Version": "4.9.0.0",
"SpecialVersion": ""
},
"repository": "https://opensource.org/licenses/mit-license.php"
}
I need a help.
Related
I am writing a node script that automates package updates within a package.json by reading the file, selecting the line with the package and giving the version a bump, and writing the new version of the file.
It runs fine when I run the script the first time. On the second run, readFileSync() gives a very different output, making the script break.
Here is the readFileSync function.
const data = fs.readFileSync("./package.json", {
encoding: "utf8",
});
On the first run, data logs like this:
PS C:\Projects\update-version-test> node updateversion.js
Updating package: webpack , version: patch
data {
"name": "update-version-test",
"version": "1.0.0",
"main": "index.js",
"author": "eendkonijn",
"license": "MIT",
"dependencies": {
"webpack": "^5.8.0"
}
}
The script works as expected, and the webpack package is bumped to 5.8.1. If I run the script again, however, the data logs like this:
PS C:\Projects\update-version-test> node updateversion.js
Updating package: webpack , version: patch
} } "webpack": "^5.8.1"",-test",
The package.json file is intact but somehow readFileSync() doesn't seem to pick it up correctly the second run?
When I make a manual change, the script seems to be working again. But only the one time.
I have a reproduction here:
https://github.com/eendkonijn/update-version-test
The problem is that you're trying to parse the json file using .split("\n") and later you assemble the resulting json content using .join(""). In the resulting file there will be no more line-breaks which is why your code does not work the second time.
Instead of manually parsing the json content, just parse it using JSON.parse, manipulate the webpack-property and finally overwrite the file content with the output of JSON.stringify. E.g:
const rawData = fs.readFileSync('./package.json', {
encoding: 'utf8',
});
const parsedData = JSON.parse(rawData);
parsedData.dependencies.webpack = 'callFunctionToManipulateTheVersionHere()';
fs.writeFileSync('./package.json', JSON.stringify(parsedData, null, 4));
I'm developing code in php, in app engine flexible environment. I'm trying to set up the SDK Admin, web version, for Firebase.
Currently, I'm just struggling with the following code:
$.ajax({
type: 'GET',
url: "prueba.js",
dataType: 'json'
}).done(function(res){
console.log("Todo bien!");
}).fail(function(jqXHR,textStatus,err){
console.log(err);
});
Aforementioned code is calling through AJAX the following code (that is, 'prueba.js'):
var admin = require(firebase-admin');
var serviceAccount = require('path/to/json-key.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://<database>.firebaseio.com'
});
These code throws the exception:
SyntaxError: Unexpected token v in JSON at position 0
at JSON.parse (<anonymous>)
at n.parseJSON (jquery.min.js:4)
at ub (jquery.min.js:4)
at x (jquery.min.js:4)
at XMLHttpRequest.<anonymous> (jquery.min.js:4)
...and last but not least, the folder and files organisation:
'node_modules', containing firebase-admin, is located in the root folder ('web'), along with index.js, package.json and package-lock.json
Prueba.html and prueba.js are located in the path 'web/asg/trm/admin'
package.json in the 'web' folder holds the following code:
{
"name": "web",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"firebase-admin": "^6.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
'index.js', on the opposite hand, does not contain any code.
I have tested the following:
In 'require' (in 'prueba.js'), I've been juggling with different locations for the 'node_modules' folder (pointing directly to the 'package.json' comprised in 'firebase-admin' as well).
Due to my short experience in Node.js, I've been spending the last two days trying to make ends meet, with no success. So any kind help would be more than welcome!
Many thanks in advance!
url: "prueba.js",
dataType: 'json'
You're asking for a JavaScript file, but telling jQuery to parse it as JSON.
This is the first line of that JavaScript file:
var admin = require(firebase-admin');
… that the first character in it is the v that is being reported as an unexpected token. JSON cannot start with a v, but as mentioned what you have is not JSON.
It isn't client-side JavaScript either, it looks like it is intended to be part of a server-side program run on Node.js, which you said you were trying to use.
For some reason, you aren't running it using Node.js at all, but are delivering the source code to the web browser.
You could write your server-side program as a web service (the express library is popular for this) and then run it with Node.js. You should then set the url to be the URL of the end point you create with that.
I'm in the process to create my first Node-RED contribution. The node will clean an incoming object based on a sample object provided in the editor. I'm using the RED.editor and the RED.library.
I'm wondering if I need to declare a dependency in my package file. Currently it looks like this:
{
"name" : "node-red-contrib-objectcleaner",
"version" : "0.0.1",
"description" : "Removes properties from incoming (payload) object, that are not in a template object",
"dependencies": { /*Do I need anything here? */
},
"keywords": [ "node-red", "validation", "flow" ],
"node-red" : {
"nodes": {
"objectcleaner": "objectcleaner/objectcleaner.js"
}
}
}
What, if anything, goes into the dependencies? I know I will put node.js dependencies there, but do I need to list the editor/library?
You'll probably do better asking questions like this on the mailing list here:
https://groups.google.com/forum/#!forum/node-red
You shouldn't need to list Node-RED in the dependencies as this will just pull in another copy into the node_modules tree.
You should be fine just using the reference to RED object that is passed in when the node is initialised
Context:
My goal is to pull the tag from a series of git repos and merge it into an existing JSON (that is the satis.JSON file for a private repo).
Example Data
{
"name": "Example",
"homepage": "http://satis.example.ca",
"repositories": [
{ "type": "vcs", "url": "git#repo.example.com:reponame1.git" },
{ "type": "vcs", "url": "git#repo.example.com:reponame2.git"}
]}
These individual commands work:
Retrieve Repo Path from URL in JSON using jq
cat satis.json | jq '.repositories[] | .url'
Retrieve Repo Path from URL in JSON using underscore_cli
underscore -i satis.json select '.repositories .url'
Example return
["git#repo.example.com:reponame1.git","git#repo.example.com:reponame2.git"]
Get Latest Tag From Individual Repo Path
git ls-remote --tags git#repo.example.com:reponame2.git | head -1 | awk '{split($0,array,"tags/")} END{print array[2]}'
Example return: 2.0.7
I'm struggling on combining them into a loop that occurs for each repo to return the tag. Any examples I hit on for while loops don't deal with the JSON array format that I haven't figured out to convert back to bash format yet.
Alternate / Related questions:
I couldn't find any way to do a git command to pull the version via JS otherwise I would have done everything with javascript. Got any specific examples that don't involve adding full JS versions of git to add to project?
If the loop could write the version back into the original data that would be most excellent. The hope is to schedule this script so that it pulls latest from satis repository, checks all the repos for latest version and outputs in a new path.
I've been trying to create a Smart Package for the SkelJS framework.
The file is being loaded by the browser but when I try and access the object it exports it says its undefined. I'm using the following code in package.js:
Package.describe({
summary: "SkelJS for Meteor"
});
Package.on_use(function (api) {
api.use('jquery', 'client');
api.add_files(['skel.js'], 'client');
api.export('skel', 'client');
});
Also trying to access Package.skeljs.skel returns undefined as well.
In smart.json I'm using:
{
"name": "skeljs",
"description": "SkelJS for Meteor",
"homepage": "",
"author": "Giles Butler (http://giles.io)",
"version": "0.1.0",
"git": ""
}
I know SkelJS has been loaded because it logs to the console no configuration detected, waiting for manual init but then when I try and run skel.init() it returns undefined.
Any help or tips would be really appreciated.
Thanks
Giles
You also need to modify the first line of skel.min.js/skel.js
Within packages variable scoping still applies so you have to remove the var keyword if you want the file to let other files (such as package.js for api.export) access its variables.
The fix would be to change:
var skel=function() ....
to
skel=function() ....