Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lucagoslar committed Mar 23, 2022
0 parents commit 4e4f0c5
Show file tree
Hide file tree
Showing 18 changed files with 10,306 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 13,
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "prettier"]
}
42 changes: 42 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: build package and run tests

on:
push:
branches: [main]
paths:
- 'package.json'
- 'tsconfig.json'
- 'tsconfig.build.json'
- 'src/**'
- '.github/workflows/main.yml'
pull_request:
branches: [main]

jobs:
test:
name: main
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install
run: npm install
- name: Test
run: npm run test
- name: Build
run: npm run build
- name: Publish (npm dry run)
run: npm pack --dry-run
27 changes: 27 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# https://github.com/marketplace/actions/npm-publish
name: publish

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
registry-url: https://registry.npmjs.org/

- run: npm ci

- run: npm run build

# - run: npm pack --dry-run

- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
109 changes: 109 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Custom
.husky/_/*
.DS_Store
*.gitignore.*
dist/

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint
npm run test
9 changes: 9 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tabWidth": 2,
"useTabs": true,
"semi": true,
"singleQuote": true,
"bracketSpacing": true,
"bracketSameLine": false,
"arrowParens": "always"
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 lucagoslar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
110 changes: 110 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
## svelte-preprocess-sass-alias-import

🗃 Import external stylesheets with the help of absolute paths.

Though this package might also work in a different environment that uses sass, it should be noted that it serves the [legacy importer](https://sass-lang.com/documentation/js-api/modules#LegacyImporter) used by [svelte-preprocess](https://github.com/sveltejs/svelte-preprocess).

[![build and test](https://github.com/lucagoslar/svelte-preprocess-sass-alias-import/actions/workflows/main.yml/badge.svg)](https://github.com/lucagoslar/svelte-preprocess-sass-alias-import/actions/workflows/main.yml)

## Setup

1. Import `SassAlias` from `svelte-preprocess-sass-alias-import`.

```ts
import { SassAlias } from 'svelte-preprocess-sass-alias-import';
```

2. Instantiate `SassAlias` and pass it an object containing your rules.

```ts
const alias = new SassAlias({
$var: 'src/scss',
@var: ["src", "scss"]
});
```

3. Add and bind the `SassAlias` instance to the project's preprocessor.
(Sample usage with SvelteKit.)

```ts
// svelte.config.js
import preprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: [
preprocess({
sass: {
importer: [alias.resolve.bind(alias)],
},
scss: {
importer: [alias.resolve.bind(alias)],
}, // Use for both sass and or scss
}),
],

kit: {
vite: {
// Only required if you want to import stylesheets into an already imported stylesheet
css: {
preprocessorOptions: {
sass: {
importer: [alias.resolve.bind(alias)],
},
scss: {
importer: [alias.resolve.bind(alias)],
},
},
},
},
},
};

export default config;
```

4. Import files using your predefined aliases.

```svelte
<!-- *.svelte -->
<style lang="scss">
@import "$var/main.scss";
</style>
```

```svelte
<!-- *.svelte -->
<style lang="sass">
@use "@var/main.scss"
</style>
```

```scss
// *.scss
@use '@var/main.scss';
```

## Contribute

Install all (dev-)dependencies by running the following.

```
npm i
```

Make sure [husky](https://github.com/typicode/husky) is being installed too.

```
npm run prepare
```

\
_And off we go …_

Build this project with the following.

```
npm run build
```

Contributions of any kind are very much appreciated.
14 changes: 14 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('./tsconfig');

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
setupFilesAfterEnv: ['jest-extended/all'],
roots: ['./src/'],
testPathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/node_modules/'],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>',
}),
};
Loading

0 comments on commit 4e4f0c5

Please sign in to comment.