Skip to content

Commit

Permalink
Initial glob-modules release
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronccasanova committed Jan 15, 2023
1 parent d7797aa commit 6394865
Show file tree
Hide file tree
Showing 21 changed files with 436 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-scissors-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'glob-modules': patch
---

Initial release
87 changes: 80 additions & 7 deletions package-lock.json

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

1 change: 1 addition & 0 deletions packages/design-tokens/scripts/themesToThemeObjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type * as tf from 'type-fest'

// eslint-disable-next-line import/no-extraneous-dependencies
import * as ts from 'typescript'
// @ts-ignore
import set from 'just-safe-set'
import * as dt from 'designtokens.io'

Expand Down
10 changes: 10 additions & 0 deletions packages/glob-modules/.babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@aacc/babel-preset",
{
"typescript": true
}
]
]
}
12 changes: 12 additions & 0 deletions packages/glob-modules/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @type {import('eslint').Linter.Config}
*/
module.exports = {
root: true,
extends: ['@aacc/eslint-config/typescript'],
parserOptions: {
tsconfigRootDir: __dirname,
project: 'tsconfig.eslint.json',
},
ignorePatterns: ['node_modules', 'dist', 'playground'],
}
50 changes: 50 additions & 0 deletions packages/glob-modules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# glob-modules

Glob modules resolver for file convention based systems.

## Installation

```sh
npm install glob-modules
```

## Usage

**Example directory structure:**

```
src/
|-- main.js
|__ commands/
|-- foo.js
|-- bar.js
|__ baz.txt
```

```js
// src/commands/foo.js
export default 'foo'

// src/commands/bar.js
export default 'bar'
export const baz = 'baz'

// src/main.js
import { globModules } from 'glob-modules'

const { commands } = await globModules('./commands/*.js', {
importMeta: import.meta,
})
/*
commands === {
foo: {
default: 'foo',
},
bar: {
default: 'bar',
baz: 'baz',
},
}
*/

```
61 changes: 61 additions & 0 deletions packages/glob-modules/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "glob-modules",
"version": "0.0.0",
"description": "Glob modules resolver for file convention based systems",
"author": "Aaron Casanova <aaronccasanova@gmail.com>",
"license": "MIT",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.mjs",
"types": "dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.mjs",
"require": "./dist/cjs/index.js"
}
},
"scripts": {
"dev": "npm-run-all --parallel 'build:* -- --watch'",
"build": "npm-run-all --parallel build:*",
"build:js": "rollup -c",
"build:types": "tsc --emitDeclarationOnly",
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"lint": "TIMING=1 eslint . --ext .js,.ts --cache",
"prepublishOnly": "npm run build"
},
"files": [
"dist"
],
"dependencies": {
"globby": "^11.1.0",
"just-safe-set": "^4.2.0"
},
"devDependencies": {
"@aacc/babel-preset": "*",
"@aacc/browserslist-config": "*",
"@aacc/eslint-config": "*",
"@aacc/tsconfigs": "*",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^21.1.0",
"@rollup/plugin-node-resolve": "^13.2.1",
"rollup": "^2.70.2",
"typescript": "^4.7.3"
},
"browserslist": [
"extends @aacc/browserslist-config"
],
"publishConfig": {
"access": "public",
"@aacc:registry": "https://registry.npmjs.org"
},
"repository": {
"type": "git",
"url": "git+https://github.com/aaronccasanova/aacc.git",
"directory": "packages/glob-modules"
},
"bugs": {
"url": "https://github.com/aaronccasanova/aacc/issues"
},
"homepage": "https://github.com/aaronccasanova/aacc/blob/main/packages/glob-modules/README.md"
}
1 change: 1 addition & 0 deletions packages/glob-modules/playground/modules/four.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default 5

export const five = 'five'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 6
3 changes: 3 additions & 0 deletions packages/glob-modules/playground/modules/one.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default 1

export const one = 'one'
1 change: 1 addition & 0 deletions packages/glob-modules/playground/modules/three.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 3
1 change: 1 addition & 0 deletions packages/glob-modules/playground/modules/two.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 2
63 changes: 63 additions & 0 deletions packages/glob-modules/playground/playground.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as path from 'node:path'
import * as url from 'node:url'
import { globModules as globModulesRaw } from '../dist/esm/index.mjs'

/** @type {import('../dist/types/index.js').globModules} */
// @ts-ignore
const globModules = globModulesRaw

const __dirname = path.dirname(url.fileURLToPath(import.meta.url))

const modules = await globModules('./modules/*.mjs', {
importMeta: import.meta,
})
/* {
modules: {
one: { default: 1, one: 'one' },
two: { default: 2 },
four: { default: 4 },
},
} */

const nestedModules = await globModules('./modules/nested-modules/*.mjs', {
importMeta: import.meta,
})
/* {
modules: {
'nested-modules': {
five: 5,
six: 6,
eight: 8,
},
},
} */

const allModules = await globModules('./modules/**/*.mjs', {
cwd: __dirname,
})
/* {
modules: {
one: { default: 1 },
two: { default: 2 },
four: { default: 4 },
'nested-modules': {
five: 5,
six: 6,
eight: 8,
},
},
} */

const cjsModules = await globModules('./modules/**/*.js', {
cwd: __dirname,
})
/* {
modules: {
three: { default: 3 },
'nested-modules': {
seven: 8,
},
},
} */

console.log('allModules:', JSON.stringify(allModules, null, 2))

3 comments on commit 6394865

@vercel
Copy link

@vercel vercel bot commented on 6394865 Jan 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

aacc-scales – ./apps/scales

aacc-scales.vercel.app
aacc-scales-git-main-aaronccasanova.vercel.app
aacc-scales-aaronccasanova.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 6394865 Jan 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

aacc-next-ts-styled-comps – ./recipes/next-ts-styled-comps

aacc-next-ts-styled-comps.vercel.app
aacc-next-ts-styled-comps-aaronccasanova.vercel.app
aacc-next-ts-styled-comps-git-main-aaronccasanova.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 6394865 Jan 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

aacc-next-ts – ./recipes/next-ts

aacc-next-ts.vercel.app
aacc-next-ts-git-main-aaronccasanova.vercel.app
aacc-next-ts-aaronccasanova.vercel.app

Please sign in to comment.