How to use - 'deno fmt' in denon - deno

I am adding "fmt": true to the denon.json file so that auto formatting is run when saving the file. But this is not working. How do I get auto formatting to run when the file is saved?

Based on the documentation of Denon the fmt option is not present, so it does nothing.
You may add a separate script to denon.json for this and run it simultaneously with your other scripts. The allow flags needs to be nulled, use it as denon format:
"scripts": {
"format": {
"cmd": "deno fmt",
"desc": "Format the code.",
"allow": []
}
...
}

Currently, it seems that you can't have the watch option for when running deno fmt, so I have the following:
{
"$schema": "https://deno.land/x/denon#2.4.7/schema.json",
"scripts": {
"start": {
"cmd": "deno run app.ts"
},
"format": {
"cmd": "deno fmt",
"watch": false
}
}
}
Of course, now I need to run denon format manually :(

Related

Behavior change in speech-rule-engine 3.2?

I'm using the speech-rule-engine to generate English text from MathML. When trying to upgrade from v3.1.1 to v3.2.0 I'm seeing tests fail for reasons I don't understand.
I created a simple two file project that illustrates the issue:
package.json
{
"name": "failure-example",
"license": "UNLICENSED",
"private": true,
"engines": {
"node": "14.15.5",
"npm": "6.14.11"
},
"scripts": {
"test": "jest"
},
"dependencies": {
"speech-rule-engine": "3.2.0"
},
"devDependencies": {
"jest": "^26.6.3"
},
"jest": {
"notify": false,
"silent": true,
"verbose": true
}
}
example.test.js
const sre = require('speech-rule-engine');
beforeAll(() => {
sre.setupEngine({
domain: 'mathspeak'
});
});
test('simple single math', () => {
expect(JSON.parse(JSON.stringify(sre.engineSetup(), ['domain', 'locale', 'speech', 'style'])))
.toEqual({
locale: 'en',
speech: 'none',
style: 'default',
domain: 'mathspeak',
});
expect(sre.engineReady())
.toBeTruthy();
expect(sre.toSpeech('<math><mrow><msup><mn>3</mn><mn>7</mn></msup></mrow></math>'))
.toBe('3 Superscript 7');
});
Running npm install and npm run test results in a failure because SRE is returning 37 instead of 3 Superscript 7. Editing package.json to use v3.1.1 of the engine and rerunning results in a passing test.
Obviously something has changed, but I'm totally missing what I need to do to adapt. Has anyone else encountered this, or see what I clearly do not?
Problem solved, with the help of the maintainer of SRE. The problem is not in 3.2.0, but that jest does not wait for sre to be ready. The test was only correct by a fluke in 3.1.1 as the rules were compiled into the core. The following test fails with the above setup in 3.1.1 as well as the locale is not loaded:
expect(sre.toSpeech('<math><mo>=</mo></math>'))
.toBe('equals');
Expected: "equals"
Received: "="
The main reason is that jest fails to load the locale file. Setting "silent": false will show the error:
Unable to load file: /tmp/tests/node_modules/speech-rule-engine/lib/mathmaps/en.js
TypeError: Cannot read property 'readFileSync' of null
The reason for this error is that jest does not know that it runs in node. Adding:
"testEnvironment": "node",
to the jest configuration in package.json causes the expected behavior.

How can I create an environment file during a cloud build process

How can I pass environment variables to a Gatsby build task in a Google Cloud Build CI process? Using the substitution variables I can make variables available in the cloudbuild.json file but these then need to be available in the build task.
Gatsby uses a .env.production file to hold the environment variables which are then available using the dotenv package. At the top of my gatsby-config.js file I set the path to the environment file as follows:
require("dotenv").config({
path: `.env.${process.env.NODE_ENV}`,
})
Further down the file I use these variables to configure the gatsby-plugin-firebase plugin for Firebase. Given that I need an environment file, I have tried to create one in the cloudbuild.json file before running the build step.
{
"steps": [
{
"name": "ubuntu",
"args": ["echo", "FIREBASE_API_KEY=$_FIREBASE_API_KEY\\nFIREBASE_AUTH_DOMAIN=$_FIREBASE_AUTH_DOMAIN\\nFIREBASE_DATABASE_URL=$_FIREBASE_DATABASE_URL\\nFIREBASE_PROJECT_ID=$_FIREBASE_PROJECT_ID\\nFIREBASE_STORAGE_BUCKET=$_FIREBASE_STORAGE_BUCKET\\nFIREBASE_MESSAGING_SENDER_ID=$_FIREBASE_MESSAGING_SENDER_ID\\nFIREBASE_APP_ID=$_FIREBASE_APP_ID\\nFIREBASE_MEASUREMENT_ID=$_FIREBASE_MEASUREMENT_ID", ">", ".env.production"]
},
...More steps here...
{
"name": "node:14.4.0",
"entrypoint": "npm",
"args": ["run", "build"]
},
{
"name": "node:14.4.0",
"entrypoint": "./node_modules/.bin/firebase",
"args": ["deploy", "--project", "$PROJECT_ID", "--token", "$_FIREBASE_TOKEN"]
}
The .env.production file does not exist when I get to the build step, which I think is because it has been created in the ubuntu container. How can I create an environment file that can be read by the build step. Or is there a better way of passing the variables?
Thanks,
Your first step is wrong, you only echo the command, not execute it. Change it like this
{
"steps": [
{
"name": "ubuntu",
"entrypoint": "bash",
"args": ["-c", "echo FIREBASE_API_KEY=$_FIREBASE_API_KEY\\nFIREBASE_AUTH_DOMAIN=$_FIREBASE_AUTH_DOMAIN\\nFIREBASE_DATABASE_URL=$_FIREBASE_DATABASE_URL\\nFIREBASE_PROJECT_ID=$_FIREBASE_PROJECT_ID\\nFIREBASE_STORAGE_BUCKET=$_FIREBASE_STORAGE_BUCKET\\nFIREBASE_MESSAGING_SENDER_ID=$_FIREBASE_MESSAGING_SENDER_ID\\nFIREBASE_APP_ID=$_FIREBASE_APP_ID\\nFIREBASE_MEASUREMENT_ID=$_FIREBASE_MEASUREMENT_ID > .env.production"]
},

Sinon cannot find module '#sinonjs/referee-sinon' when simple use it

I am a beginner of SinonJs, When I try to write some demo code, it cannot work, I don't know why.
app.js
const db = require('./db');
module.exports.signUpUser = (user) => {
db.saveUser(user.email, user.password);
}
app.test.js
const sinon = require('sinon');
// without any other codes, it will throw Error: Cannot find module '#sinonjs/referee-sinon'
I user mocha to run the tests.
package.json
{
"name": "sinon-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha **/*.test.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"mocha": "^5.2.0",
"sinon": "^7.2.3"
}
}
I need to see the whole directory structure, but it's probably because
"scripts": {
"test": "mocha **/*.test.js"
}
is picking up unintended test files in './node_modules/#sinonjs/'.
Change the test script so that the tests only in your source directory are included. E.g.
"test": "mocha './src/**/*.test.js'"
or
"test": "mocha './{,!(node_modules)/**}/*.test.js'"
Most likely mocha is not finding your test files. Without knowing your folder structure it's hard to tell. However, you should always quote your globs in npm scripts. Not sure that will solve your problem here, though. I think it depends on where your *.test.js files live. Try simplifying and not using the glob to start. Just specify the folder. For example, if your test file lives in your src directory use
"test": "mocha './src/*.test.js'"
If you're going to have subdirectories under src you can use
"test": "mocha './src/**/*.test.js'"
If you don't want to use single quotes you can escape the quotes like this
"test": "mocha \"./src/**/*.test.js\""
Penultimately, when I have test files at the root of the project and in subfolders I just specify both like this:
"test": "mocha *.test.js './src/**/*.test.js'"
Ultimately, I like running all my tests in strict mode so my test command would look like this:
"test": "mocha --use_strict *.test.js './src/**/*.test.js'"
Adding to #Tod's answer, If you've got a mocharc.js file at the root of project, I'd adives to change it to something like:
module.exports = {
...
spec: ["!(node_modules)/**/**.test.js"],
};

Files generated with precompile are not compiled

During dotnet build, it seems that generated files created during the precompile tasks are not used and the build failed.
precompile cannot be used for files generation? The documention is pretty light about it.
or do I have to deal with a delay to be sure that files are correctly writed on disk ?
Project.json:
{
"name": "Service",
"version": "0.0.1",
"dependencies": {
...
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
},
"scripts": {
"precompile": "%project:Directory%/protogen.bat"
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
}
}
Thanks
I assume you don't have this problem anymore, but to save time for anyone running into this issue, here is what is going on:
The problem is a bug in the dotnet tool where source files generated by a precompile command aren't included in the list of files to compile. See #1475 and #3807.
It was fixed by PR#4680. Upgrading to a newer version of .NET Core should fix it.

Wrap PHPWord on bundle

I just want to use PHPWord for Symfony 2. But Im new on Symfony 2.
I paste PHPWord source into my util folder bundle but there is an error loading autoloader class from PHPWord...
Question is simple, How can I "wrap" code (in this case PHPWord) in to bundle? or someway I can use it.
Any solution?
Thanks for answering, that gives me some light. Altough, This doen't work for me.
I download composer.phar and I edit my composer.json as you say: adding in my require region "phpword/phpword": "0.6.2" and creating new repository phpword...
Doesn't work, I run "php composer.phar" command but It doesn't download anything...
Any tutorial or tip to make this work?
Thank you
composer require phpoffice/phpword dev-master did the work for me.
It should download and place install PhpOffice\PHPWord under the vendor folder in your Symfony2 installation (besides modifying your composer.json automatically).
In the controller you are about to use PhpWord:
use PhpOffice\PhpWord\PhpWord;
And inside the action, you can create a new instance as follows:
$doc = new PhpWord();
You shouldn't be copying the source code yourself. Use composer to install PHPWord.
Since PHPWord doesn't use composer (yet), you'll need to define a repository in your composer.json:
{
"require": {
"phpword/phpword": "0.6.2"
},
"repositories": [
{
"type": "package",
"package": {
"name": "phpword/phpword",
"version": "0.6.2",
"dist": {
"url": "http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=phpword&DownloadId=138035&FileTime=129545976016270000&Build=19692",
"type": "zip"
},
"autoload": {
"classmap": ["."]
}
}
}
]
}
Than you'll be able to use PHPWord in your Symfony project (any PHP project in fact):
$word = new PHPWord();
$writer = new PHPWord_Writer_Word2007($word);
$writer->save('test.doc');
Update: I just realized the URL to download changes with time. It'd be better to replace it with something that doesn't change (if possible, otherwise host it somewhere yourself).
As the URL changes, you can use the github repository if you've no problem with the dev version :
{
"require": {
"phpword/phpword": "dev"
},
"repositories": [
{
"type": "package",
"package": {
"name": "phpword/phpword",
"version": "dev",
"dist": {
"url": "https://github.com/PHPOffice/PHPWord/archive/develop.zip",
"type": "zip"
},
"autoload": {
"classmap": ["."]
}
}
}
]
}
You can use this simple bundle as wrapper for PhpWord:
https://packagist.org/packages/ggggino/wordbundle

Resources