diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 00000000..51878cea --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,18 @@ +{ + "printWidth": 100, + "tabWidth": 2, + "useTabs": false, + "semi": true, + "singleQuote": true, + "quoteProps": "as-needed", + "jsxSingleQuote": false, + "trailingComma": "all", + "bracketSpacing": true, + "bracketSameLine": false, + "arrowParens": "always", + "proseWrap": "preserve", + "htmlWhitespaceSensitivity": "ignore", + "vueIndentScriptAndStyle": false, + "endOfLine": "auto", + "singleAttributePerLine": true +} diff --git a/package-lock.json b/package-lock.json index 615a63e0..1081b2cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@divriots/style-dictionary-to-figma": "^0.4.0", "concat": "^1.0.3", "cross-env": "^7.0.3", + "dir-to-json": "^1.0.0", "fs-extra": "^10.1.0", "glob": "^7.1.6", "json5": "^2.2.0", @@ -219,6 +220,15 @@ "node": ">=0.10" } }, + "node_modules/dir-to-json": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/dir-to-json/-/dir-to-json-1.0.0.tgz", + "integrity": "sha512-yDfgiqPrKf4Qje1CgsFRB1Dl1TjV9U8YVo6ykIR1gbRf4E/7ErmrhP1FbUfSccs6hojSgEkLWd7xO6XY7ioplg==", + "dev": true, + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/dot-case": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/dot-case/-/dot-case-3.0.4.tgz", @@ -836,6 +846,12 @@ "integrity": "sha512-FqUYQ+8o158GyGTrMFJms9qh3CqTKvAqgqsTnkLI8sKu0028orqBhxNMFkFen0zGyg6epACD32pjVk58ngIErQ==", "dev": true }, + "dir-to-json": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/dir-to-json/-/dir-to-json-1.0.0.tgz", + "integrity": "sha512-yDfgiqPrKf4Qje1CgsFRB1Dl1TjV9U8YVo6ykIR1gbRf4E/7ErmrhP1FbUfSccs6hojSgEkLWd7xO6XY7ioplg==", + "dev": true + }, "dot-case": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/dot-case/-/dot-case-3.0.4.tgz", diff --git a/package.json b/package.json index d9926109..013a5524 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "@divriots/style-dictionary-to-figma": "^0.4.0", "concat": "^1.0.3", "cross-env": "^7.0.3", + "dir-to-json": "^1.0.0", "fs-extra": "^10.1.0", "glob": "^7.1.6", "json5": "^2.2.0", diff --git a/validate-structure.json b/validate-structure.json new file mode 100644 index 00000000..df934fa5 --- /dev/null +++ b/validate-structure.json @@ -0,0 +1 @@ +{"parent":"..","path":"","name":"dist","type":"directory","children":[{"parent":"","path":"docsite","name":"docsite","type":"directory","children":[{"parent":"docsite","path":"docsite/android","name":"android","type":"directory","children":[{"parent":"docsite/android","path":"docsite/android/colors.xml","name":"colors.xml","type":"file"},{"parent":"docsite/android","path":"docsite/android/dimens.xml","name":"dimens.xml","type":"file"},{"parent":"docsite/android","path":"docsite/android/font_dimens.xml","name":"font_dimens.xml","type":"file"}]},{"parent":"docsite","path":"docsite/css","name":"css","type":"directory","children":[{"parent":"docsite/css","path":"docsite/css/cdr-tokens.css","name":"cdr-tokens.css","type":"file"}]},{"parent":"docsite","path":"docsite/figma","name":"figma","type":"directory","children":[{"parent":"docsite/figma","path":"docsite/figma/figma.json","name":"figma.json","type":"file"}]},{"parent":"docsite","path":"docsite/ios","name":"ios","type":"directory","children":[{"parent":"docsite/ios","path":"docsite/ios/CdrColor.h","name":"CdrColor.h","type":"file"},{"parent":"docsite/ios","path":"docsite/ios/CdrColor.m","name":"CdrColor.m","type":"file"},{"parent":"docsite/ios","path":"docsite/ios/CdrSize.h","name":"CdrSize.h","type":"file"},{"parent":"docsite/ios","path":"docsite/ios/CdrSize.m","name":"CdrSize.m","type":"file"}]},{"parent":"docsite","path":"docsite/js","name":"js","type":"directory","children":[{"parent":"docsite/js","path":"docsite/js/cdr-tokens.cjs","name":"cdr-tokens.cjs","type":"file"},{"parent":"docsite/js","path":"docsite/js/cdr-tokens.d.mts","name":"cdr-tokens.d.mts","type":"file"},{"parent":"docsite/js","path":"docsite/js/cdr-tokens.mjs","name":"cdr-tokens.mjs","type":"file"}]},{"parent":"docsite","path":"docsite/json","name":"json","type":"directory","children":[{"parent":"docsite/json","path":"docsite/json/android.json","name":"android.json","type":"file"},{"parent":"docsite/json","path":"docsite/json/global.json","name":"global.json","type":"file"},{"parent":"docsite/json","path":"docsite/json/ios.json","name":"ios.json","type":"file"},{"parent":"docsite/json","path":"docsite/json/platform-tokens.json","name":"platform-tokens.json","type":"file"},{"parent":"docsite/json","path":"docsite/json/web.json","name":"web.json","type":"file"}]},{"parent":"docsite","path":"docsite/less","name":"less","type":"directory","children":[{"parent":"docsite/less","path":"docsite/less/cdr-tokens.less","name":"cdr-tokens.less","type":"file"}]},{"parent":"docsite","path":"docsite/scss","name":"scss","type":"directory","children":[{"parent":"docsite/scss","path":"docsite/scss/cdr-tokens.scss","name":"cdr-tokens.scss","type":"file"},{"parent":"docsite/scss","path":"docsite/scss/deprecate.scss","name":"deprecate.scss","type":"file"},{"parent":"docsite/scss","path":"docsite/scss/utility-map.scss","name":"utility-map.scss","type":"file"}]}]},{"parent":"","path":"rei-dot-com","name":"rei-dot-com","type":"directory","children":[{"parent":"rei-dot-com","path":"rei-dot-com/android","name":"android","type":"directory","children":[{"parent":"rei-dot-com/android","path":"rei-dot-com/android/colors.xml","name":"colors.xml","type":"file"},{"parent":"rei-dot-com/android","path":"rei-dot-com/android/dimens.xml","name":"dimens.xml","type":"file"},{"parent":"rei-dot-com/android","path":"rei-dot-com/android/font_dimens.xml","name":"font_dimens.xml","type":"file"}]},{"parent":"rei-dot-com","path":"rei-dot-com/css","name":"css","type":"directory","children":[{"parent":"rei-dot-com/css","path":"rei-dot-com/css/cdr-tokens.css","name":"cdr-tokens.css","type":"file"}]},{"parent":"rei-dot-com","path":"rei-dot-com/figma","name":"figma","type":"directory","children":[{"parent":"rei-dot-com/figma","path":"rei-dot-com/figma/figma.json","name":"figma.json","type":"file"}]},{"parent":"rei-dot-com","path":"rei-dot-com/ios","name":"ios","type":"directory","children":[{"parent":"rei-dot-com/ios","path":"rei-dot-com/ios/CdrColor.h","name":"CdrColor.h","type":"file"},{"parent":"rei-dot-com/ios","path":"rei-dot-com/ios/CdrColor.m","name":"CdrColor.m","type":"file"},{"parent":"rei-dot-com/ios","path":"rei-dot-com/ios/CdrSize.h","name":"CdrSize.h","type":"file"},{"parent":"rei-dot-com/ios","path":"rei-dot-com/ios/CdrSize.m","name":"CdrSize.m","type":"file"}]},{"parent":"rei-dot-com","path":"rei-dot-com/js","name":"js","type":"directory","children":[{"parent":"rei-dot-com/js","path":"rei-dot-com/js/cdr-tokens.cjs","name":"cdr-tokens.cjs","type":"file"},{"parent":"rei-dot-com/js","path":"rei-dot-com/js/cdr-tokens.d.mts","name":"cdr-tokens.d.mts","type":"file"},{"parent":"rei-dot-com/js","path":"rei-dot-com/js/cdr-tokens.mjs","name":"cdr-tokens.mjs","type":"file"}]},{"parent":"rei-dot-com","path":"rei-dot-com/json","name":"json","type":"directory","children":[{"parent":"rei-dot-com/json","path":"rei-dot-com/json/android.json","name":"android.json","type":"file"},{"parent":"rei-dot-com/json","path":"rei-dot-com/json/global.json","name":"global.json","type":"file"},{"parent":"rei-dot-com/json","path":"rei-dot-com/json/ios.json","name":"ios.json","type":"file"},{"parent":"rei-dot-com/json","path":"rei-dot-com/json/platform-tokens.json","name":"platform-tokens.json","type":"file"},{"parent":"rei-dot-com/json","path":"rei-dot-com/json/web.json","name":"web.json","type":"file"}]},{"parent":"rei-dot-com","path":"rei-dot-com/less","name":"less","type":"directory","children":[{"parent":"rei-dot-com/less","path":"rei-dot-com/less/cdr-tokens.less","name":"cdr-tokens.less","type":"file"}]},{"parent":"rei-dot-com","path":"rei-dot-com/scss","name":"scss","type":"directory","children":[{"parent":"rei-dot-com/scss","path":"rei-dot-com/scss/cdr-tokens.scss","name":"cdr-tokens.scss","type":"file"},{"parent":"rei-dot-com/scss","path":"rei-dot-com/scss/deprecate.scss","name":"deprecate.scss","type":"file"},{"parent":"rei-dot-com/scss","path":"rei-dot-com/scss/utility-map.scss","name":"utility-map.scss","type":"file"}]}]}]} \ No newline at end of file diff --git a/validate.js b/validate.js index 6e339830..af372887 100644 --- a/validate.js +++ b/validate.js @@ -2,15 +2,17 @@ const glob = require('glob'); const requireJSON5 = require('require-json5'); const _ = require('lodash'); const process = require('process'); +const dirToJson = require('dir-to-json'); +const fs = require('fs'); const files = glob.sync('./tokens/**/*.json5'); const results = []; -const addDelimiter = (a, b) => a ? `${a}-${b}` : b; +const addDelimiter = (a, b) => (a ? `${a}-${b}` : b); -// check if object has a `value` property and if any children also have `value` (style dictionary +// check if object has a `value` property and if any children also have `value` (style dictionary // will only process the topmost object with `value`) -const validate = (obj, path='', to_ret=[]) => { +const validate = (obj, path = '', to_ret = []) => { const hasValue = _.has(obj, 'value'); for (const key in obj) { @@ -33,8 +35,8 @@ files.forEach((file) => { const response = validate(requireJSON5(file)); if (response.length > 0) { - results.push(` In ${file}:`) - results.push(` ${response.join('\r\n ')}`) + results.push(` In ${file}:`); + results.push(` ${response.join('\r\n ')}`); } }); @@ -43,5 +45,34 @@ if (results.length > 0) { console.log(results.join('\r\n')); process.exitCode = 1; } else { - console.log('All files successfully validated'); -} \ No newline at end of file + console.log('Files successfully validated'); +} + +// Check if file structure is the same +const validateStructure = async () => { + const validationFile = 'validate-structure.json'; + const newData = await dirToJson('./dist', { sortType: true }); + let existingData; + + try { + const raw = fs.readFileSync(validationFile, 'utf8'); + existingData = JSON.parse(raw); + } catch (err) { + existingData = null; + } + + // If no existing data found, create it + if (!existingData) { + fs.writeFileSync(validationFile, JSON.stringify(currentData)); + console.log('Created new validation data'); + return; + } + + if (!_.isEqual(existingData, newData)) { + throw new Error('Structure in dist folder has changed!'); + } + + console.log('Dist data structure has not changed'); +}; + +validateStructure();