Skip to content

Instantly share code, notes, and snippets.

@chrisvxd
Last active November 10, 2020 14:53
Show Gist options
  • Select an option

  • Save chrisvxd/81137cb29b20a38c438c7918c776af4c to your computer and use it in GitHub Desktop.

Select an option

Save chrisvxd/81137cb29b20a38c438c7918c776af4c to your computer and use it in GitHub Desktop.

Revisions

  1. chrisvxd revised this gist Feb 4, 2020. 1 changed file with 10 additions and 6 deletions.
    16 changes: 10 additions & 6 deletions build-from-yaml.js
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,7 @@ const YAML = require('yamljs');
    const globby = require('globby');
    const fs = require('fs-extra');
    const path = require('path');

    const StyleDictionary = require('style-dictionary').extend('./config.json');
    const styleDictionary = require('style-dictionary');

    const convertStringValues = obj =>
    Object.keys(obj).reduce((acc, key) => {
    @@ -27,6 +26,8 @@ const convertStringValues = obj =>
    }, {});

    (async () => {
    await fs.remove('build');

    await fs.copy('properties', '.properties_json');

    const paths = await globby(['.properties_json/**/*.yml']);
    @@ -35,7 +36,9 @@ const convertStringValues = obj =>
    paths.map(async p => {
    const data = YAML.parse(await fs.readFile(p, 'utf8'));

    // Map value fields to objects
    console.info(`Converting ${p} to JSON...\r`);

    const json = JSON.stringify(convertStringValues(data));

    // Write output
    @@ -52,9 +55,10 @@ const convertStringValues = obj =>

    console.info('Processing style-dictionary...');

    StyleDictionary.buildAllPlatforms();
    const sd = styleDictionary.extend('./config.json');

    sd.buildAllPlatforms();

    // NB Removing this causes StyleDictionary to fail - does StyleDictionary have some hanging processes?
    // console.info('Removing build directory...');
    // await fs.remove('.properties_json');
    console.info('Removing build directory...');
    await fs.remove('.properties_json');
    })();
  2. chrisvxd revised this gist Feb 4, 2020. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions build-from-yaml.js
    Original file line number Diff line number Diff line change
    @@ -35,9 +35,7 @@ const convertStringValues = obj =>
    paths.map(async p => {
    const data = YAML.parse(await fs.readFile(p, 'utf8'));

    // Map value fields to objects
    console.info(`Converting ${p} to JSON...\r`);

    const json = JSON.stringify(convertStringValues(data));

    // Write output
  3. chrisvxd created this gist Feb 4, 2020.
    62 changes: 62 additions & 0 deletions build-from-yaml.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    const YAML = require('yamljs');
    const globby = require('globby');
    const fs = require('fs-extra');
    const path = require('path');

    const StyleDictionary = require('style-dictionary').extend('./config.json');

    const convertStringValues = obj =>
    Object.keys(obj).reduce((acc, key) => {
    const item = obj[key];
    const hasValueKey = !!item.value;

    let resolvedValue;

    if (hasValueKey) {
    resolvedValue = item;
    } else if (typeof item === 'string') {
    resolvedValue = { value: item };
    } else {
    resolvedValue = convertStringValues(item);
    }

    return {
    ...acc,
    [key]: resolvedValue
    };
    }, {});

    (async () => {
    await fs.copy('properties', '.properties_json');

    const paths = await globby(['.properties_json/**/*.yml']);

    await Promise.all(
    paths.map(async p => {
    const data = YAML.parse(await fs.readFile(p, 'utf8'));

    // Map value fields to objects
    console.info(`Converting ${p} to JSON...\r`);

    const json = JSON.stringify(convertStringValues(data));

    // Write output
    const newP = path.join(
    path.dirname(p),
    path.basename(p, '.yml') + '.json'
    );

    console.info(`Writing ${newP}...`);

    await fs.writeFile(newP, json);
    })
    );

    console.info('Processing style-dictionary...');

    StyleDictionary.buildAllPlatforms();

    // NB Removing this causes StyleDictionary to fail - does StyleDictionary have some hanging processes?
    // console.info('Removing build directory...');
    // await fs.remove('.properties_json');
    })();