Skip to content

Commit b95d307

Browse files
committed
Initial commit.
0 parents  commit b95d307

15 files changed

+7953
-0
lines changed

.circleci/config.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version: 2
2+
jobs:
3+
build:
4+
working_directory: /usr/src/app
5+
docker:
6+
- image: banian/node
7+
steps:
8+
# Checkout repository
9+
- checkout
10+
11+
# Restore cache
12+
- restore_cache:
13+
key: yarn-{{ checksum "yarn.lock" }}
14+
15+
# Install dependencies
16+
- run:
17+
name: Install Dependencies
18+
command: NODE_ENV=dev yarn
19+
20+
# Install dependencies
21+
- run:
22+
name: Install Python Dependencies
23+
command: pip install -r requirements.txt
24+
25+
# Keep cache
26+
- save_cache:
27+
key: yarn-{{ checksum "yarn.lock" }}
28+
paths:
29+
- "node_modules"
30+
31+
# Test
32+
- run:
33+
name: Tests
34+
command: yarn test
35+
36+
# Coverage
37+
- run:
38+
name: Coverage
39+
command: yarn codecov

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_size = 2
6+
indent_style = space
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.eslintrc.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
root: true,
3+
parserOptions: {
4+
sourceType: 'module'
5+
},
6+
env: {
7+
browser: true,
8+
node: true,
9+
jest: true
10+
},
11+
extends: 'standard',
12+
plugins: [
13+
'jest',
14+
'vue'
15+
],
16+
rules: {
17+
// Allow paren-less arrow functions
18+
'arrow-parens': 0,
19+
// Allow async-await
20+
'generator-star-spacing': 0,
21+
// Allow debugger during development
22+
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
23+
// Do not allow console.logs etc...
24+
'no-console': 2
25+
},
26+
globals: {
27+
'jest/globals': true,
28+
jasmine: true
29+
}
30+
}

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules
2+
*.iml
3+
.idea
4+
*.log*
5+
.nuxt
6+
.vscode
7+
.DS_STORE
8+
coverage
9+
dist

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Sebastian Silva <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# @nuxtjs/python
2+
[![npm (scoped with tag)](https://img.shields.io/npm/v/@nuxtjs/python/latest.svg?style=flat-square)](https://npmjs.com/package/@nuxtjs/python)
3+
[![npm](https://img.shields.io/npm/dt/@nuxtjs/python.svg?style=flat-square)](https://npmjs.com/package/@nuxtjs/python)
4+
[![CircleCI](https://img.shields.io/circleci/project/github/https://github.com/nuxt-community/python-module.svg?style=flat-square)](https://circleci.com/gh/https://github.com/nuxt-community/python-module)
5+
[![Codecov](https://img.shields.io/codecov/c/github/https://github.com/nuxt-community/python-module.svg?style=flat-square)](https://codecov.io/gh/https://github.com/nuxt-community/python-module)
6+
[![Dependencies](https://david-dm.org/https://github.com/nuxt-community/python-module/status.svg?style=flat-square)](https://david-dm.org/https://github.com/nuxt-community/python-module)
7+
[![js-standard-style](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com)
8+
9+
> Write Nuxt.js Apps in Python
10+
11+
[📖 **Release Notes**](./CHANGELOG.md)
12+
13+
## Features
14+
15+
- Write Nuxt.js applications without using Python!
16+
- Currently only supports custom Javascripthon but in the future other compilers will also be expected to work.
17+
18+
## Setup
19+
- Add `@nuxtjs/python` dependency using yarn or npm to your project
20+
- Add `@nuxtjs/python` to `modules` section of `nuxt.config.js`
21+
22+
```js
23+
{
24+
modules: [
25+
// Simple usage
26+
'@nuxtjs/python'
27+
]
28+
}
29+
```
30+
31+
- Install a Python transpiler (e.g. `pip install --user -r requirements.txt`)
32+
33+
## Usage
34+
35+
### Using `.vue` files
36+
**TIP** If you use Vim you can get the full experience with https://github.com/posva/vim-vue/pull/97
37+
38+
`hello.vue`:
39+
```html
40+
<template>
41+
<div>
42+
Nuxt {{ best_lang }}
43+
</div>
44+
</template>
45+
<script lang="py?compiler=pj">
46+
class Component:
47+
48+
def __init__(self):
49+
self['data'] = lambda: { 'best_lang': 'Python' }
50+
51+
__all__ = Component()
52+
</script>
53+
```
54+
Note: This syntax requires a specific branch of Javascripthon until patches get merged https://github.com/icarito/metapensiero.pj/tree/default_import - see alternative with `require` at https://github.com/martim00/python-webpack-loader/pull/8#issuecomment-359280782
55+
56+
### Using `.py` files for other nuxt files
57+
58+
`store/index.py`
59+
```python
60+
from vuex import Vuex
61+
62+
63+
def increment(state):
64+
state.counter = state.counter + 1
65+
66+
67+
def createStore():
68+
return Vuex.Store(state={'counter': 0},
69+
mutations={'increment': increment})
70+
71+
72+
__all__ = createStore
73+
```
74+
75+
`pages/counter.vue`
76+
```html
77+
<template>
78+
<h2>{{ $store.state.counter }}</h2>
79+
<button @click="$store.commit('increment')">+1</button>
80+
</template>
81+
```
82+
83+
## Development
84+
85+
- Clone this repository
86+
- Install dependnecies using `yarn install` or `npm install`
87+
- Start development server using `npm run dev`
88+
89+
## License
90+
91+
[MIT License](./LICENSE)
92+
93+
Copyright (c) Sebastian Silva <[email protected]>

lib/module.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = function PythonModule (moduleOptions) {
2+
this.nuxt.options.extensions.push('py')
3+
4+
this.extendBuild((config, { isClient, isServer }) => {
5+
config.devtool = '#cheap-module-eval-source-map'
6+
config.resolve.extensions.push('.py')
7+
config.module.rules.push({
8+
test: /\.py$/,
9+
loader: 'py-loader',
10+
options: {
11+
compiler: 'pj'
12+
}
13+
})
14+
})
15+
}

package.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "@nuxtjs/python",
3+
"version": "0.0.0",
4+
"description": "Write Nuxt.js Apps in Python",
5+
"license": "MIT",
6+
"contributors": [
7+
{
8+
"name": "Sebastian Silva <[email protected]>"
9+
}
10+
],
11+
"main": "lib/module.js",
12+
"repository": "https://github.com/https://github.com/nuxt-community/python-module",
13+
"publishConfig": {
14+
"access": "public"
15+
},
16+
"scripts": {
17+
"dev": "nuxt test/fixture",
18+
"lint": "eslint lib test",
19+
"test": "npm run lint && jest",
20+
"release": "standard-version && git push --follow-tags && npm publish"
21+
},
22+
"eslintIgnore": ["lib/templates/*.*"],
23+
"files": ["lib"],
24+
"jest": {
25+
"testEnvironment": "node",
26+
"collectCoverage": true
27+
},
28+
"dependencies": {
29+
"py-loader": "martim00/python-webpack-loader"
30+
},
31+
"devDependencies": {
32+
"nuxt": "latest",
33+
"codecov": "latest",
34+
"eslint": "latest",
35+
"eslint-config-standard": "latest",
36+
"eslint-plugin-import": "latest",
37+
"eslint-plugin-jest": "latest",
38+
"eslint-plugin-node": "latest",
39+
"eslint-plugin-promise": "latest",
40+
"eslint-plugin-standard": "latest",
41+
"eslint-plugin-vue": "latest",
42+
"jest": "latest",
43+
"jsdom": "latest",
44+
"standard-version": "latest"
45+
}
46+
}

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-e git+https://github.com/icarito/metapensiero.pj@default_import#egg=javascripthon

test/.module.test.js.swp

12 KB
Binary file not shown.

test/fixture/nuxt.config.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { resolve } = require('path')
2+
3+
module.exports = {
4+
rootDir: resolve(__dirname, '../..'),
5+
srcDir: __dirname,
6+
dev: false,
7+
render: {
8+
resourceHints: false
9+
},
10+
modules: ['@@']
11+
}

test/fixture/pages/.index.vue.swp

12 KB
Binary file not shown.

test/fixture/pages/index.vue

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<div>
3+
{{ py_works }}
4+
</div>
5+
</template>
6+
7+
<script lang="py?compiler=pj">
8+
9+
class Component:
10+
def __init__(self):
11+
self['data'] = lambda: { 'py_works': 'Works!' }
12+
13+
__all__= Component()
14+
</script>

test/module.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const { Nuxt, Builder } = require('nuxt')
2+
const request = require('request-promise-native')
3+
4+
const config = require('./fixture/nuxt.config')
5+
6+
const url = path => `http://localhost:3000${path}`
7+
const get = path => request(url(path))
8+
9+
describe('basic', () => {
10+
let nuxt
11+
12+
beforeAll(async () => {
13+
nuxt = new Nuxt(config)
14+
await new Builder(nuxt).build()
15+
await nuxt.listen(3000)
16+
}, 60000)
17+
18+
afterAll(async () => {
19+
await nuxt.close()
20+
})
21+
22+
test('render', async () => {
23+
let html = await get('/')
24+
expect(html).toContain('Works!')
25+
})
26+
})

0 commit comments

Comments
 (0)