platform-colors icon indicating copy to clipboard operation
platform-colors copied to clipboard

Unexpected token '.'

Open a-eid opened this issue 3 years ago • 10 comments

Screen Shot 2021-12-04 at 12 07 56 AM

same issue happens with the example app.

Screen Shot 2021-12-04 at 12 18 03 AM

Screen Shot 2021-12-04 at 12 18 24 AM

STR:

  • init a new react-native project
  • run npx @klarna/platform-colors in the root directory

a-eid avatar Dec 03 '21 22:12 a-eid

Which version of node are you on? I think this is probably too fancy/new syntax @pontusab

oblador avatar Dec 04 '21 08:12 oblador

yeah true, I can have a look

pontusab avatar Dec 04 '21 08:12 pontusab

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.

Screen Shot 2021-12-04 at 12 18 38 PM

I'll add one. and report back

another error

Screen Shot 2021-12-04 at 12 21 43 PM

creating manually ...

awesome, it's working correctly now.

thank you.

a-eid avatar Dec 04 '21 10:12 a-eid

rerunning the command produces this error.

Screen Shot 2021-12-04 at 12 50 15 PM

ios is working perfectly, but have to restart the app on android to get it to work.

a-eid avatar Dec 04 '21 10:12 a-eid

https://user-images.githubusercontent.com/19273413/144706899-59512982-199f-4131-bdff-b1cdf8a4f132.mp4

a-eid avatar Dec 04 '21 10:12 a-eid

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.

yangm97 avatar Jan 11 '22 23:01 yangm97

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.

Screen Shot 2022-01-21 at 2 52 20 PM

a-eid avatar Jan 21 '22 12:01 a-eid

Screen Shot 2022-01-21 at 2 58 53 PM

had to add this line to fix it.

thank you

a-eid avatar Jan 21 '22 12:01 a-eid

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.

a-eid avatar Jan 21 '22 14:01 a-eid

I updated the PR resolving this, also node >= v12 from now on is supported!

pontusab avatar Jan 26 '22 11:01 pontusab