outsystems-design-tokens
Version:
Store the Design Tokens used on the Ionic Framework and Widgets Library
52 lines (46 loc) • 2.58 kB
JavaScript
// Import minimist for parsing command line arguments
import minimist from "minimist";
import { generateTokens } from "./generate-tokens.js";
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
// Parse the command line arguments
const args = minimist(process.argv.slice(2));
// Get the directory where this script is located
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const packageRoot = join(__dirname, '..');
// Set the environment variables based on the parsed arguments
// If src is not provided, use the tokens directory from this package
process.env.src = args.src || join(packageRoot, 'tokens/**/*.json');
process.env.dest = args.dest;
process.env.config = args.config || undefined;
process.env.prefix = args.prefix !== undefined ? args.prefix : 'token';
process.env.scssPrefix = args['scss-prefix'] !== undefined ? args['scss-prefix'] : (args.prefix !== undefined ? args.prefix : 'token');
// If root flag is not provided, default to true. Otherwise, use the provided value.
process.env.root = args.root === undefined ? 'true' : String(args.root);
// If scss flag is not provided, default to true. Otherwise, use the provided value.
process.env.scss = args.scss === undefined ? 'true' : String(args.scss);
// If utilities flag is not provided, default to true. Otherwise, use the provided value.
process.env.utilities = args.utilities === undefined ? 'true' : String(args.utilities);
// Set custom file names (with defaults)
process.env.rootFile = args['root-file'] || '_root.scss';
process.env.scssFile = args['scss-file'] || '_variables.scss';
process.env.utilitiesFile = args['utilities-file'] || '_utilities.scss';
console.log('Build started...');
console.log('Configuration:');
console.log(' - src:', process.env.src);
console.log(' - dest:', process.env.dest || 'dist/');
console.log(' - prefix:', process.env.prefix);
if (process.env.scssPrefix !== process.env.prefix) {
console.log(' - scss-prefix:', process.env.scssPrefix);
}
console.log(' - root:', process.env.root, process.env.root === 'true' ? `(${process.env.rootFile})` : '');
console.log(' - scss:', process.env.scss, process.env.scss === 'true' ? `(${process.env.scssFile})` : '');
console.log(' - utilities:', process.env.utilities, process.env.utilities === 'true' ? `(${process.env.utilitiesFile})` : '');
// Call the imported function
(async () => {
await generateTokens();
console.log('\n==============================================');
console.log('\nBuild completed!');
})();