Skip to content

Commit

Permalink
feat: first release
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Mar 12, 2019
0 parents commit 205f79e
Show file tree
Hide file tree
Showing 15 changed files with 4,158 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
*.log
out
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"ms-vscode.vscode-typescript-tslint-plugin"
]
}
35 changes: 35 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm: watch"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "npm: watch"
}
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}
20 changes: 20 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
10 changes: 10 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.vscode/**
.vscode-test/**
out/test/**
src/**
.gitignore
vsc-extension-quickstart.md
**/tsconfig.json
**/tslint.json
**/*.map
**/*.ts
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) 2018 Jay Fong <fjc0kb@gmail.com>

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 @@
# Generate Index

Generating file indexes easily.

## Wherever

In any file, simply invoke command `Generate Index` to generate a file list.

- Example 1: `src/index.js`

```js
export { default as module1 } from './module1'
export { default as module2 } from './module2'
```

- Example 2: `utils.ts`

```js
// @index('../utils/*.ts')
export { default as util1 } from '../utils/util1'
export { default as util2 } from '../utils/util1'
```

- Example 3: `styles/components.scss`

```scss
// @index('./components/*.scss', pp => `@import '${pp.path}';`)
@import './components/component1';
@import './components/component2';
```

- Example 4: `assets/index.ts`

```js
// @index('./*.{png,jpg,svg}', pp => `export { default as ${pp.name} } from '${pp.path}${pp.extension}'`)
export { default as image1 } from './image1.png'
export { default as image2 } from './image2.jpg'
export { default as image3 } from './image3.svg'
```

## Markers

You can use markers (`@index()` and `@endindex`) to tell where the index should be built, instead of replacing the entire file:

```js
// This line will remain in the file.

// @index()

// ... The index will be (re)placed here.

// @endindex

// This line will remain in the file.
```

## @index()

`index` is a function (type: `Index`):

```ts
import * as lodash from 'lodash'

interface ParsedPath {
/** The relative file path without extension, such as `./api` */
path: string,
/** The file name without extension, such as `api` */
name: string,
/** The file extension, such as `.js`*/
extension: string,
}

type Pattern = string

type CodeGenerator = (
parsedPath: ParsedPath,
lodash: lodash.LoDashStatic,
) => string

type Index = (
patterns: Pattern | Pattern[],
codeGenerator: CodeGenerator,
) => string
```
## Patterns
See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage).
## Indentation
You can make an index indented by indenting the start marker, e.g.
```js
module.exports = {
// @index('./*.js', pp => `${pp.name}: require('${pp.path}'),`)
// @endindex
}
```

The produced index like as:

```js
module.exports = {
// @index('./*.js', pp => `${pp.name}: require('${pp.path}'),`)
module1: require('./module1'),
module2: require('./module2'),
// @endindex
}
```
84 changes: 84 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"name": "generate-index",
"displayName": "Generate Index",
"description": "Generating file indexes easily.",
"version": "0.0.1",
"license": "MIT",
"publisher": "JayFong",
"engines": {
"vscode": "^1.32.0"
},
"categories": [
"Other"
],
"repository": {
"type": "git",
"url": "https://github.com/fjc0k/vscode-generate-index"
},
"activationEvents": [
"onCommand:extension.generateIndex"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "extension.generateIndex",
"title": "Generate Index"
}
],
"configuration": {
"title": "Generate Index",
"properties": {
"generateIndex.defaultPatterns": {
"type": "string",
"default": "['./*.{js,jsx,ts,tsx}']",
"description": "<Array> The default patterns to use when exporting files."
},
"generateIndex.defaultCodeGenerator": {
"type": "string",
"default": "(parsedPath, lodash) => `export { default as ${parsedPath.name} } from '${parsedPath.path}'`",
"description": "<Function> The default code generator to use when generating indexes."
}
}
}
},
"scripts": {
"vscode:prepublish": "yarn run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "yarn run compile && node ./node_modules/vscode/bin/test",
"release": "standard-version -a && git push --follow-tags origin master && vsce publish"
},
"eslintConfig": {
"root": true,
"extends": "io",
"rules": {
"import/no-unresolved": [
2,
{
"ignore": [
"vscode"
]
}
]
}
},
"eslintIgnore": [
"out"
],
"devDependencies": {
"@types/lodash": "^4.14.123",
"@types/mocha": "^2.2.42",
"@types/node": "^10.12.21",
"eslint": "^5.15.1",
"eslint-config-io": "^0.1.1",
"standard-version": "^5.0.1",
"typescript": "^3.3.1",
"vscode": "^1.1.28"
},
"dependencies": {
"globby": "^9.1.0",
"lodash": "^4.17.11"
}
}

0 comments on commit 205f79e

Please sign in to comment.