platform-colors
platform-colors copied to clipboard
Unexpected token '.'
same issue happens with the example app.
STR:
- init a new react-native project
- run
npx @klarna/platform-colors
in the root directory
Which version of node are you on? I think this is probably too fancy/new syntax @pontusab
yeah true, I can have a look
Which version of node are you on? I think this is probably too fancy/new syntax @pontusab
v12.22.7
will try the current LTS
version v16.13.1
looks like it's working with the current LTS
version.
actually no, it's failing with a different error,
the colors.xml
is not found, I think RN doesn't generate one automatically.
I'll add one. and report back
another error
creating manually ...
awesome, it's working correctly now.
thank you.
rerunning the command produces this error.
ios is working perfectly, but have to restart the app on android to get it to work.
https://user-images.githubusercontent.com/19273413/144706899-59512982-199f-4131-bdff-b1cdf8a4f132.mp4
The xml parser won't output an array if values.xml
contains only one color, which breaks that filter. As a workaround you can try adding another color there.
diff --git a/node_modules/@klarna/platform-colors/src/templates/android.js b/node_modules/@klarna/platform-colors/src/templates/android.js
index ecdcb6e..599b356 100644
--- a/node_modules/@klarna/platform-colors/src/templates/android.js
+++ b/node_modules/@klarna/platform-colors/src/templates/android.js
@@ -1,7 +1,8 @@
const path = require('path');
const { create, convert } = require('xmlbuilder2');
const fs = require('fs-extra');
-const { formatName } = require('../utils');
+const { formatName, ensureAndoridFiles } = require('../utils');
+
function stringifyColor(color) {
const hex = color.hex();
@@ -16,6 +17,7 @@ const getXmlResources = (config, filename) => {
const outputDirectory = config?.android?.outputDirectory;
if (outputDirectory) {
+ ensureAndoridFiles(outputDirectory);
const xml = fs
.readFileSync(path.resolve(outputDirectory, filename))
.toString();
diff --git a/node_modules/@klarna/platform-colors/src/utils.js b/node_modules/@klarna/platform-colors/src/utils.js
index bdb7cce..3d99317 100644
--- a/node_modules/@klarna/platform-colors/src/utils.js
+++ b/node_modules/@klarna/platform-colors/src/utils.js
@@ -6,10 +6,13 @@ const {
sentenceCase,
} = require('change-case');
+const path = require('path');
+const fs = require('fs-extra');
+
const DEFAULT_PREFIX = 'rnpc';
function formatName(platform, config, name = '') {
- const prefix = config?.prefix || DEFAULT_PREFIX;
+ const prefix = (config && config.prefix) || DEFAULT_PREFIX;
switch (platform) {
case 'android':
@@ -23,6 +26,14 @@ function formatName(platform, config, name = '') {
}
}
+function ensureAndoridFiles(outputDirectory) {
+ fs.ensureFileSync(
+ path.resolve(`${outputDirectory}/values-night/`, 'colors.xml')
+ );
+ fs.ensureFileSync(path.resolve(`${outputDirectory}/values/`, 'colors.xml'));
+}
+
module.exports = {
formatName,
+ ensureAndoridFiles
};
@pontusab I applied both fixes as a patch file and am still getting the following error.
had to add this line to fix it.
thank you
one note is that, you have to have at least 1 color inside of your values-night/colors.xml
file.
I think this is related to the active PR, when creating the file you probably should make 1 dummy color.
I updated the PR resolving this, also node >= v12 from now on is supported!