4.0.1 • Published 2 years ago

letsrock v4.0.1

Weekly downloads
7
License
ISC
Repository
github
Last release
2 years ago

Install

npm install letsrock -g

Start

letsrock init your_project
cd your_project
letsrock dev

Config

You can add a .rcrc file to indicate you config.

{
  "autoMount": true, // true to auto mount page for specific urls, it will bypass your custom controller
  "port": 9988  // port to listen
}

Server Code

Add the following 3 folders to enable server side logic.

middleware
service
controller

if you wanna run some code at startup, please add a file named _startup.js under your project root folder. If _startup.js exports a promise, the bootstrap will wait for the promise resolved.

Builtin Injectors

request
 - request.getBody
response
 - response.render(data, tpl, opts)
context
app

FAQ

How to specify css style for a particular page?

letsrock use webpack to pack your stylesheet so it is safe to call import "./index.css" under a jsx file.

Where to put static files?

create a folder named "/_res" and put your files under this file.

<img src={$res("/head.png")} />

How to config head metas?

edit .rcrc.

{
  "metas": `
    <meta name="viewport" content="width=device-width, initial-scale=1">
  `
}

If you only want your current page use the meta, you can create a file "meta.js" under your page folder.

module.exports = {
  metas: `
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
    .good {
      color: red;
    }
    </style>
  `
};

How to get project root dir?

this.config.base

How to get request body?

inject request object in your controller.

async function (request, response) {
  var body = await request.getBody();
}

How to response in JSON?

response.ok({
  name: 'jack',
  age: 18
});
// will get: {status: 0, data: {name: 'jack', age: 18}}
response.fail({
  msg: 'you do not have the right to do it'
});
// will get: {status: 1, msg: 'you do not have the right to do it'}
response.fail({
  status: 9,
  msg: 'internal error'
});
// will get: {status: 9, msg: 'internal error'}
response.json({
  name: 'jack',
  age: 18
});
// will get: {name: 'jack', age: 18}

How to get render data in client?

look for "window._STATE" variable.

How to setup favicon?

Create a file named either favicon.ico, favicon.png or favicon.jpg under your project root.

How can I know if it is ran by letsrock dev?

check if global.__IS_DEV__ is true.

How to get unminified file online?

simply add a query "?debug=1" with your url. If you dont like debug=1 and can debug your own flag under .rcrc.

{
  debug_flag: 3
}

In such case, you should query ?debug=3.

Can I use handlebars as template engine for lightweight pages?

Yes. Simply put a file name "index.hbs" instead of "index.jsx". If an index.jsx or index.jsx being presented, it will be compiled but will not be auto-included by the page. In this case, you need to manually declare it via js helper.

Here is some useful builtin helpers.

{{js "name/path.js"}}
{{css "name/path.css"}}

Also, you can declare two files inline.js and inline.css under the same folder, they will be automatically included into the page.

warning: the inline.js will not be compiled, be carefully!!

Can I add something to the built-in webpack config?

Not recommended. However, you can still make it. Edit your .rcrc file like following:

{
  processWebpackConfig: function (webpackConfig) {
    webpackConfig.plugins = ....
    return webpackConfig;  // do not forget this line
  }
}

How to enable ssr?

ssr is by default disabled. You should enable it page by page. In your metas.js, add:

{
  ssr: true,
  skipHydrate: false, // if you don't want client to hydrate, mark it ture.
}

How to write unit test cases?

In any folder, create files that contains spec.js. These files will be automatically loaded when run letsrock test. Please follow the mocha pattern to write test cases;

License

MIT

4.0.1

2 years ago

4.0.0

2 years ago

3.5.3

2 years ago

3.5.1

2 years ago

3.4.6

2 years ago

3.4.4

2 years ago

3.4.3

2 years ago

3.4.2

2 years ago

3.4.5

2 years ago

3.4.1

3 years ago

3.4.0

3 years ago

3.3.15

4 years ago

3.3.14

4 years ago

3.3.13

4 years ago

3.3.12

4 years ago

3.3.10

4 years ago

3.3.11

4 years ago

3.3.9

4 years ago

3.3.7

4 years ago

3.3.6

4 years ago

3.3.5

4 years ago

3.3.4

4 years ago

3.3.3

4 years ago

3.3.2

4 years ago

3.3.1

4 years ago

3.3.0

4 years ago

3.2.9

4 years ago

3.2.10

4 years ago

3.2.8

4 years ago

3.2.7

4 years ago

3.2.6

4 years ago

3.2.5

4 years ago

3.2.4

4 years ago

3.2.3

4 years ago

3.2.2

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.0

4 years ago

2.1.6

4 years ago

2.1.5

4 years ago

2.1.4

4 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.20

5 years ago

2.0.19

5 years ago

2.0.18

5 years ago

2.0.17

5 years ago

2.0.16

5 years ago

2.0.15

5 years ago

2.0.14

5 years ago

2.0.13

5 years ago

2.0.12

5 years ago

2.0.11

6 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.32

7 years ago

1.2.31

7 years ago

1.2.30

7 years ago

1.2.29

7 years ago

1.2.28

7 years ago

1.2.27

7 years ago

1.2.26

7 years ago

1.2.25

7 years ago

1.2.23

7 years ago

1.2.22

7 years ago

1.2.21

7 years ago

1.2.20

7 years ago

1.2.19

7 years ago

1.2.18

7 years ago

1.2.17

7 years ago

1.2.15

7 years ago

1.2.14

7 years ago

1.2.13

7 years ago

1.2.12

7 years ago

1.2.11

7 years ago

1.2.10

7 years ago

1.2.9

7 years ago

1.2.8

7 years ago

1.2.7

7 years ago

1.2.6

8 years ago

1.2.5

8 years ago

1.2.4

8 years ago

1.2.3

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago