Skip to content

Commit

Permalink
fix: move dayjs and just-throttle to dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
6eDesign committed Sep 18, 2021
1 parent 0d74e75 commit 6dee7b3
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 57 deletions.
21 changes: 0 additions & 21 deletions index.js

This file was deleted.

21 changes: 17 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"name": "svelte-calendar",
"version": "3.0.17",
"main": "index.js",
"main": "src/lib/index.js",
"scripts": {
"dev": "svelte-kit dev",
"package": "svelte-kit package",
"postpackage": "node scripts/postpackage",
"prebuild": "rm -rf build",
"build": "svelte-kit build",
"postbuild": "touch docs/.nojekyll",
Expand All @@ -14,17 +13,20 @@
"lint": "prettier --check --plugin-search-dir=. . && eslint --ignore-path .gitignore .",
"format": "prettier --write --plugin-search-dir=. ."
},
"dependencies": {
"dayjs": "^1.10.6",
"just-throttle": "^2.3.1"
},
"devDependencies": {
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.1",
"@semantic-release/npm": "^7.1.3",
"@sveltejs/adapter-static": "^1.0.0-next.19",
"@sveltejs/kit": "^1.0.0-next.147",
"dayjs": "^1.10.6",
"eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-svelte3": "^3.2.0",
"just-throttle": "^2.3.1",
"p-limit": "^4.0.0",
"prettier": "~2.2.1",
"prettier-plugin-svelte": "^2.2.0",
"prism-svelte": "^0.4.7",
Expand Down
38 changes: 19 additions & 19 deletions scripts/postpackage.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { promises as fs } from 'fs';
import path from 'path';
import pLimit from 'p-limit';
import { promises as fs } from 'fs';

const PACKAGE_FOLDER = process.env.PACKAGE_FOLDER || 'package';
const CWD = process.cwd();

const limit = pLimit(10);

const getFolder = async (folder, depth = 0) => {
const contents = await fs.readdir(path.join(CWD, folder), {
withFileTypes: true
Expand All @@ -14,31 +17,28 @@ const getFolder = async (folder, depth = 0) => {
folders: await Promise.all(
contents
.filter((f) => f.isDirectory())
.map((dir) => getFolder(`${folder}/${dir.name}`, depth + 1))
.map((dir) => limit(() => getFolder(`${folder}/${dir.name}`, depth + 1)))
),
files: contents.filter((f) => !f.isDirectory()).map(({ name }) => `${folder}/${name}`)
};
};

const transformFolder = async ({ folders, files, depth }) => {
await Promise.all(
files.map(async (f) => {
const filepath = path.join(CWD, f);
const contents = await fs.readFile(filepath, 'utf-8');
const base = depth ? [...Array(depth).fill('..')].join('/') : './';
const updated = contents
.replace(/from '\$lib(.*)'/g, `from '${base}$1'`)
.replace(/src\/lib\//g, '');
await Promise.all(
[
updated === contents ? null : fs.writeFile(filepath, updated),
...folders.map(transformFolder)
].filter(Boolean)
);
})
);
const transformFile = async (file, depth) => {
const filepath = path.join(CWD, file);
const contents = await fs.readFile(filepath, 'utf-8');
const base = depth ? [...Array(depth).fill('..')].join('/') : './';
const updated = contents
.replace(/from '\$lib(.*)'/g, `from '${base}$1'`)
.replace(/src\/lib\//g, '');
await fs.writeFile(filepath, updated);
};

const transformFolder = ({ folders, files, depth }) =>
Promise.all([
...files.map((f) => limit(() => transformFile(f, depth))),
...folders.map((f) => limit(() => transformFolder(f)))
]);

getFolder(PACKAGE_FOLDER)
.then(transformFolder)
.catch(console.error)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/docs/examples/CustomTheme.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { InlineCalendar } from '../../../../index';
import { InlineCalendar } from '../../index';
import { base } from '$app/paths';
const theme = {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/docs/examples/CustomTrigger.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import dayjs from 'dayjs';
import { Datepicker } from '../../../../index';
import { Datepicker } from '../../index';
let store;
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/docs/examples/DarkTheme.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import { base } from '$app/paths';
import { InlineCalendar, themes } from '../../../../index';
import { InlineCalendar, themes } from '../../index';
const { dark: theme } = themes;
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/lib/docs/examples/Formatting.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { Datepicker } from '../../../../index';
import { Datepicker } from '../../index';
let format = 'dddd, MMMM D, YYYY';
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/docs/examples/InlineCalendar.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { InlineCalendar } from '../../../../index';
import { InlineCalendar } from '../../index';
const theme = {
calendar: {
width: '600px',
Expand Down
2 changes: 1 addition & 1 deletion src/lib/docs/examples/Locale.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import 'dayjs/locale/ar-dz.js';
import 'dayjs/locale/he.js';
import dayjs from 'dayjs';
import { InlineCalendar, Swappable, themes } from '../../../../index.js';
import { InlineCalendar, Swappable, themes } from '../../index.js';
import { onDestroy } from 'svelte';
const locales = ['en', 'es', 'zh-cn', 'ar-dz', 'he'];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/docs/examples/QuickStart.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { Datepicker } from '../../../../index';
import { Datepicker } from '../../index';
</script>

<Datepicker />
2 changes: 1 addition & 1 deletion src/lib/docs/examples/StartAndEnd.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import dayjs from 'dayjs';
import { Datepicker } from '../../../../index';
import { Datepicker } from '../../index';
const today = new Date();
const tomorrow = dayjs().add(1, 'day').toDate();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/docs/examples/Store.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { InlineCalendar } from '../../../../index';
import { InlineCalendar } from '../../index';
import dayjs from 'dayjs';
const theme = {
Expand Down
21 changes: 21 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Datepicker from './components/Datepicker.svelte';
import InlineCalendar from './components/InlineCalendar.svelte';
import Popover from './components/Popover.svelte';
import Calendar from './components/calendar/Calendar.svelte';
import Crossfade from './components/generic/crossfade/Crossfade.svelte';
import CrossfadeProvider from './components/generic/crossfade/CrossfadeProvider.svelte';
import Swappable from './components/generic/Swappable.svelte';
import Scrollable from './components/generic/Scrollable.svelte';
import * as themes from './config/theme';

export {
Datepicker,
InlineCalendar,
Popover,
Calendar,
Crossfade,
CrossfadeProvider,
Scrollable,
Swappable,
themes
};

0 comments on commit 6dee7b3

Please sign in to comment.