2
0
mirror of https://github.com/iconify/iconify.git synced 2024-11-17 01:55:09 +00:00

chore: use module as default for svelte component

This commit is contained in:
Vjacheslav Trushkin 2023-12-27 17:21:49 +02:00
parent be70a27dad
commit 7fb8bd2c57
5 changed files with 73 additions and 121 deletions

View File

@ -1,5 +1,5 @@
const fs = require('fs');
const child_process = require('child_process');
import { readFileSync, writeFileSync, readdirSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
// List of commands to run
const commands = [];
@ -47,16 +47,6 @@ process.argv.slice(2).forEach((cmd) => {
}
});
// Check if required modules in same monorepo are available
const fileExists = (file) => {
try {
fs.statSync(file);
} catch (e) {
return false;
}
return true;
};
// Compile packages
Object.keys(compile).forEach((key) => {
if (!compile[key]) {
@ -89,8 +79,7 @@ Object.keys(compile).forEach((key) => {
* Get all api-extractor.*.json files
*/
function apiFiles() {
return fs
.readdirSync(__dirname)
return readdirSync('.')
.map((item) => {
const parts = item.split('.');
if (parts.pop() !== 'json' || parts.shift() !== 'api-extractor') {
@ -117,10 +106,10 @@ function next() {
}
if (item.cwd === void 0) {
item.cwd = __dirname;
item.cwd = '.';
}
const result = child_process.spawnSync(item.cmd, item.args, {
const result = spawnSync(item.cmd, item.args, {
cwd: item.cwd,
stdio: 'inherit',
});
@ -138,13 +127,12 @@ next();
*/
function cleanup() {
// Merge TypeScript files
const sourceDir = __dirname + '/src/';
const distDir = __dirname + '/dist/';
const sourceDir = './src/';
const distDir = './dist/';
function createTypes() {
// Get Svelte file, split it. Import and content should be separated by empty line
const svelteParts = fs
.readFileSync(sourceDir + 'svelte.d.ts', 'utf8')
const svelteParts = readFileSync(sourceDir + 'svelte.d.ts', 'utf8')
.trim()
.replace(/\r/g, '')
.split('\n\n');
@ -179,20 +167,19 @@ function cleanup() {
].forEach((item) => {
const content =
svelteImport +
fs
.readFileSync(distDir + item.source, 'utf8')
readFileSync(distDir + item.source, 'utf8')
.replace('export { }', '')
.trim() +
svelteContent;
fs.writeFileSync(distDir + item.target, content, 'utf8');
writeFileSync(distDir + item.target, content, 'utf8');
console.log(`Created dist/${item.target}`);
});
}
function copyComponents() {
['Icon.svelte', 'OfflineIcon.svelte'].forEach((name) => {
const content = fs.readFileSync(sourceDir + name, 'utf8');
fs.writeFileSync(distDir + name, content, 'utf8');
const content = readFileSync(sourceDir + name, 'utf8');
writeFileSync(distDir + name, content, 'utf8');
console.log(`Copied dist/${name}`);
});
}

View File

@ -2,10 +2,11 @@
"name": "@iconify/svelte",
"description": "Iconify icon component for Svelte.",
"author": "Vjacheslav Trushkin",
"version": "4.0.0-beta.3",
"version": "4.0.0-beta.4",
"publishConfig": {
"tag": "next"
},
"type": "module",
"license": "MIT",
"bugs": "https://github.com/iconify/iconify/issues",
"homepage": "https://github.com/iconify/iconify",
@ -30,6 +31,16 @@
"svelte": "./dist/OfflineIcon.svelte",
"types": "./dist/offline.d.ts"
},
"./dist/functions": {
"types": "./lib/dist/functions.d.ts",
"require": "./lib/dist/functions.cjs",
"import": "./lib/dist/functions.js"
},
"./dist/offline-functions": {
"types": "./lib/dist/offline-functions.d.ts",
"require": "./lib/dist/offline-functions.cjs",
"import": "./lib/dist/offline-functions.js"
},
"./*": "./*"
},
"scripts": {
@ -37,7 +48,7 @@
"prebuild": "pnpm run cleanup",
"build": "node build",
"build:tsc": "tsc -b",
"build:bundles": "rollup -c rollup.config.mjs",
"build:bundles": "rollup -c rollup.config.js",
"build:api": "node build --only-api",
"test": "vitest"
},

View File

@ -0,0 +1,48 @@
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
// Directories
const targetDir = 'dist';
const sourceDir = 'src';
const mjsExt = '.js';
const cjsExt = '.cjs';
const resolveParams = {
extensions: ['.ts', '.mjs', '.js', '.cjs', '.svelte'],
dedupe: ['svelte'],
};
// Create bundle
export default [
// Files included in Icon.svelte as bundle
{
input: `${sourceDir}/functions.ts`,
output: [
{
file: `${targetDir}/functions${mjsExt}`,
format: 'es',
},
{
file: `${targetDir}/functions${cjsExt}`,
format: 'cjs',
},
],
plugins: [resolve(resolveParams), typescript()],
},
// Files included in OfflineIcon.svelte as bundle
{
input: `${sourceDir}/offline-functions.ts`,
output: [
{
file: `${targetDir}/offline-functions${mjsExt}`,
format: 'es',
},
{
file: `${targetDir}/offline-functions${cjsExt}`,
format: 'cjs',
},
],
plugins: [resolve(resolveParams), typescript()],
},
];

View File

@ -1,94 +0,0 @@
import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import sveltePreprocess from 'svelte-preprocess';
// Directories
const targetDir = 'dist';
const sourceDir = 'src';
// Create bundle
export default [
// Bundle everything
/*
{
input: sourceDir + '/Icon.svelte',
output: [
{ file: targetDir + '/index.mjs', format: 'es' },
{ file: targetDir + '/index.js', format: 'cjs' },
],
plugins: [
svelte({
preprocess: sveltePreprocess(),
}),
resolve({
browser: true,
extensions: ['.ts', '.mjs', '.js', '.svelte'],
dedupe: ['svelte'],
}),
typescript(),
],
},
{
input: sourceDir + '/OfflineIcon.svelte',
output: [
{ file: targetDir + '/offline.mjs', format: 'es' },
{ file: targetDir + '/offline.js', format: 'cjs' },
],
plugins: [
svelte({
preprocess: sveltePreprocess(),
}),
resolve({
browser: true,
extensions: ['.ts', '.mjs', '.js', '.svelte'],
dedupe: ['svelte'],
}),
typescript(),
],
},
*/
// Files included in Icon.svelte as bundle
{
input: sourceDir + '/functions.ts',
output: [
{
file: targetDir + '/functions.mjs',
format: 'es',
},
{
file: targetDir + '/functions.js',
format: 'cjs',
},
],
plugins: [
resolve({
extensions: ['.ts', '.mjs', '.js', '.svelte'],
dedupe: ['svelte'],
}),
typescript(),
],
},
// Files included in OfflineIcon.svelte as bundle
{
input: sourceDir + '/offline-functions.ts',
output: [
{
file: targetDir + '/offline-functions.mjs',
format: 'es',
},
{
file: targetDir + '/offline-functions.js',
format: 'cjs',
},
],
plugins: [
resolve({
extensions: ['.ts', '.mjs', '.js', '.svelte'],
dedupe: ['svelte'],
}),
typescript(),
],
},
];