This commit is contained in:
Valentin Silytuin 2022-02-01 20:07:08 +04:00
parent b0767cb34b
commit 96e24c8e19
11 changed files with 1286 additions and 184 deletions

View File

@ -1,7 +1,7 @@
root = true root = true
[*] [*]
indent_style = tab indent_style = space
indent_size = 4 indent_size = 4
end_of_line = lf end_of_line = lf
trim_trailing_whitespace = true trim_trailing_whitespace = true

97
.gitignore vendored Normal file → Executable file
View File

@ -53,6 +53,7 @@ Temporary Items
# Windows thumbnail cache files # Windows thumbnail cache files
Thumbs.db Thumbs.db
Thumbs.db:encryptable
ehthumbs.db ehthumbs.db
ehthumbs_vista.db ehthumbs_vista.db
@ -84,12 +85,15 @@ $RECYCLE.BIN/
*.rar *.rar
*.zip *.zip
*.gz *.gz
*.gzip
*.tgz *.tgz
*.bzip *.bzip
*.bzip2
*.bz2 *.bz2
*.xz *.xz
*.lzma *.lzma
*.cab *.cab
*.xar
# Packing-only formats # Packing-only formats
*.iso *.iso
@ -105,6 +109,7 @@ $RECYCLE.BIN/
*.msi *.msi
*.msm *.msm
*.msp *.msp
*.txz
# https://github.com/github/gitignore/blob/master/Global/Backup.gitignore # https://github.com/github/gitignore/blob/master/Global/Backup.gitignore
@ -114,88 +119,22 @@ $RECYCLE.BIN/
*.orig *.orig
*.tmp *.tmp
# https://github.com/github/gitignore/blob/master/Node.gitignore # Node
# Logs node_modules
logs npm-*.log
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data # Yarn
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover yarn-*.log
lib-cov .pnp.*
.yarn/*
# Coverage directory used by tools like istanbul !.yarn/patches
coverage !.yarn/plugins
!.yarn/releases
# nyc test coverage !.yarn/sdks
.nyc_output !.yarn/versions
# 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/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# 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 output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# Composer # Composer
vendor vendor

1
.nvmrc Normal file
View File

@ -0,0 +1 @@
16

View File

@ -1,15 +1,6 @@
{ {
"printWidth": 120, "printWidth": 120,
"tabWidth": 4, "tabWidth": 4,
"useTabs": true, "singleQuote": true,
"semi": true, "bracketSpacing": false
"singleQuote": true,
"quoteProps": "as-needed",
"trailingComma": "es5",
"bracketSpacing": false,
"arrowParens": "always",
"proseWrap": "preserve",
"htmlWhitespaceSensitivity": "css",
"vueIndentScriptAndStyle": false,
"endOfLine": "lf"
} }

File diff suppressed because one or more lines are too long

768
.yarn/releases/yarn-3.1.1.cjs vendored Executable file

File diff suppressed because one or more lines are too long

7
.yarnrc.yml Normal file
View File

@ -0,0 +1,7 @@
nodeLinker: node-modules
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
yarnPath: .yarn/releases/yarn-3.1.1.cjs

View File

@ -28,38 +28,38 @@ const nunjucksTemplate = `
```js ```js
[ [
{ {
test: /\.js$/, test: /\.js$/,
exclude: [/mocks\.js$/], exclude: [/mocks\.js$/],
use: [ use: [
{ {
loader: 'babel-loader', loader: 'babel-loader',
options: { options: {
cacheDirectory: true, cacheDirectory: true,
}, },
}, },
], ],
}, },
{ {
test: /mocks\.js$/, test: /mocks\.js$/,
use: [ use: [
{ {
loader: 'babel-loader', loader: 'babel-loader',
options: { options: {
compact: false, compact: false,
plugins: [ plugins: [
[ [
'@advdominion/babel-plugin-nunjucks', '@advdominion/babel-plugin-nunjucks',
{ {
templatesFolder: 'src/templates/', templatesFolder: 'src/templates/',
varNames: ['nunjucksTemplate'], varNames: ['nunjucksTemplate'],
}, },
], ],
], ],
}, },
}, },
], ],
}, },
]; ];
``` ```

View File

@ -1,23 +1,23 @@
const nunjucks = require('nunjucks'); import nunjucks from 'nunjucks';
module.exports = ({types: t}) => { export default ({types: t}) => {
return { return {
visitor: { visitor: {
Identifier(path, state) { Identifier(path, state) {
for (let i = 0; i < state.opts.varNames.length; i += 1) { for (let i = 0; i < state.opts.varNames.length; i += 1) {
if ( if (
path.parentPath.type === 'VariableDeclarator' && path.parentPath.type === 'VariableDeclarator' &&
path.isIdentifier({name: state.opts.varNames[i]}) path.isIdentifier({name: state.opts.varNames[i]})
) { ) {
const templatesFolder = state.opts.templatesFolder; const templatesFolder = state.opts.templatesFolder;
const value = path.parentPath.get('init').node.quasis[0].value.raw; const value = path.parentPath.get('init').node.quasis[0].value.raw;
const env = new nunjucks.Environment(new nunjucks.FileSystemLoader(templatesFolder)); const env = new nunjucks.Environment(new nunjucks.FileSystemLoader(templatesFolder));
const render = env.renderString(value); const render = env.renderString(value);
path.parentPath.get('init').node.quasis = [t.templateElement({cooked: render, raw: render})]; path.parentPath.get('init').node.quasis = [t.templateElement({cooked: render, raw: render})];
break; break;
} }
} }
}, },
}, },
}; };
}; };

View File

@ -1,16 +1,21 @@
{ {
"name": "@advdominion/babel-plugin-nunjucks", "name": "@advdominion/babel-plugin-nunjucks",
"version": "1.10.0", "version": "2.0.0",
"main": "index.js", "type": "module",
"repository": { "engines": {
"type": "git", "node": "^16.0.0"
"url": "https://bitbucket.org/advdominion/babel-plugin-nunjucks" },
}, "packageManager": "yarn@3.1.1",
"license": "MIT", "main": "index.js",
"peerDependencies": { "repository": {
"@babel/core": "7.x" "type": "git",
}, "url": "https://bitbucket.org/advdominion/babel-plugin-nunjucks"
"dependencies": { },
"nunjucks": "^3.2.3" "license": "MIT",
} "peerDependencies": {
"@babel/core": "7.x"
},
"dependencies": {
"nunjucks": "^3.2.3"
}
} }

View File

@ -1,27 +1,55 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # This file is generated by running "yarn install" inside your project.
# yarn lockfile v1 # Manual changes might be lost - proceed with caution!
__metadata:
version: 5
cacheKey: 8
a-sync-waterfall@^1.0.0: "@advdominion/babel-plugin-nunjucks@workspace:.":
version "1.0.1" version: 0.0.0-use.local
resolved "https://registry.yarnpkg.com/a-sync-waterfall/-/a-sync-waterfall-1.0.1.tgz#75b6b6aa72598b497a125e7a2770f14f4c8a1fa7" resolution: "@advdominion/babel-plugin-nunjucks@workspace:."
integrity sha512-RYTOHHdWipFUliRFMCS4X2Yn2X8M87V/OpSqWzKKOGhzqyUxzyVmhHDH9sAvG+ZuQf/TAOFsLCpMw09I1ufUnA==
asap@^2.0.3:
version "2.0.6"
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"
integrity sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=
commander@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae"
integrity sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==
nunjucks@^3.2.3:
version "3.2.3"
resolved "https://registry.yarnpkg.com/nunjucks/-/nunjucks-3.2.3.tgz#1b33615247290e94e28263b5d855ece765648a31"
integrity sha512-psb6xjLj47+fE76JdZwskvwG4MYsQKXUtMsPh6U0YMvmyjRtKRFcxnlXGWglNybtNTNVmGdp94K62/+NjF5FDQ==
dependencies: dependencies:
a-sync-waterfall "^1.0.0" nunjucks: ^3.2.3
asap "^2.0.3" peerDependencies:
commander "^5.1.0" "@babel/core": 7.x
languageName: unknown
linkType: soft
"a-sync-waterfall@npm:^1.0.0":
version: 1.0.1
resolution: "a-sync-waterfall@npm:1.0.1"
checksum: 534948b50d6787c2dd5b7e89179b30c0fd96ac80a662d0f92eaa568cfffb36f1eea4aa720e3a21572d8b5f8686940954ac9d8c7667bcc719c1317ae3bdf86fe0
languageName: node
linkType: hard
"asap@npm:^2.0.3":
version: 2.0.6
resolution: "asap@npm:2.0.6"
checksum: b296c92c4b969e973260e47523207cd5769abd27c245a68c26dc7a0fe8053c55bb04360237cb51cab1df52be939da77150ace99ad331fb7fb13b3423ed73ff3d
languageName: node
linkType: hard
"commander@npm:^5.1.0":
version: 5.1.0
resolution: "commander@npm:5.1.0"
checksum: 0b7fec1712fbcc6230fcb161d8d73b4730fa91a21dc089515489402ad78810547683f058e2a9835929c212fead1d6a6ade70db28bbb03edbc2829a9ab7d69447
languageName: node
linkType: hard
"nunjucks@npm:^3.2.3":
version: 3.2.3
resolution: "nunjucks@npm:3.2.3"
dependencies:
a-sync-waterfall: ^1.0.0
asap: ^2.0.3
commander: ^5.1.0
peerDependencies:
chokidar: ^3.3.0
peerDependenciesMeta:
chokidar:
optional: true
bin:
nunjucks-precompile: bin/precompile
checksum: 9d0125acf917166675af2d9b5d525b6d3edaba68ec6f8c92edee8ad05140cfa8aef12feb46f4c3da52ed2836cadfb9d26fbf1fa9d9be6bef4660d03ce1e89dbe
languageName: node
linkType: hard