New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kotsu

Package Overview
Dependencies
Maintainers
3
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kotsu - npm Package Compare versions

Comparing version 1.12.0 to 1.13.0

modules/cache.js

10

gruntfile.js
const timeGrunt = require('time-grunt')
const gruntWriteJson = require('./modules/grunt-write-json')
const gruntJSPM = require('./modules/grunt-jspm')
const gruntJSPMEmitter = require('./modules/grunt-jspm-emitter')
const jitGrunt = require('jit-grunt')

@@ -12,2 +14,4 @@ const gettext = require('./modules/gettext')

gruntJSPM(grunt)
gruntJSPMEmitter(grunt)
gruntWriteJson(grunt)

@@ -138,2 +142,4 @@

grunt.registerTask('jspmWatch', grunt.option('hmr') ? 'jspmEmitter' : 'jspm:watch')
// Build for development and serve

@@ -148,2 +154,3 @@ grunt.registerTask('default', [

'nunjucks',
'jspmWatch',
'sprite',

@@ -170,3 +177,3 @@ 'webfont',

'postcss:autoprefix',
'shell:jspm_build',
'jspm:build',
'uncss',

@@ -185,2 +192,3 @@ 'csso',

grunt.registerTask('serve', [
'jspmWatch',
'browserSync',

@@ -187,0 +195,0 @@ 'watch'

46

modules/clean-workdir.js
const { exec, execSync } = require('child_process')
const { green, red } = require('chalk')
exec('git --version', (error) => {
if (error) {
console.error('[clean-workdir] No Git has been detected.\n\nSkipping clean working directory test.\n')
console.error(error)
return
}
const isFromCLI = require.main === module
const logError = (message) => console.error(red(message))
exec('git status --porcelain', (error, stdout) => {
const checkIsWorkDirClean = () => {
exec('git --version', (error) => {
if (error) {
console.error('[clean-workdir] an error occured:\n')
console.error(error)
return
console.log('[clean-workdir] No Git has been detected.\n\nSkipping clean working directory test.\n')
return console.log(error)
}
if (stdout) {
console.error('[clean-workdir] Modified files have been detected.\n')
console.error('Build task should not generate or change files outside build folder:\n')
console.error(stdout)
console.error(execSync('git diff --color').toString())
return process.exit(1)
}
exec('git status --porcelain', (error, stdout) => {
if (error) {
logError('[clean-workdir] an error occured:\n')
return logError(error)
}
console.log(`[clean-workdir] no modified files detected outside of build folder. Live long and prosper`)
if (stdout) {
logError('[clean-workdir] Modified files have been detected.\n')
logError('Build task should not generate or change files outside the build folder:\n')
logError(stdout)
console.error(execSync('git diff --color').toString())
return process.exit(1)
}
console.log(green('[clean-workdir] no modified files detected outside of the build folder. Live long and prosper'))
})
})
})
}
if (isFromCLI) checkIsWorkDirClean()
module.exports = checkIsWorkDirClean

@@ -1,3 +0,3 @@

import gt from 'grunt'
import gruntfile from '../gruntfile'
const gt = require('grunt')
const gruntfile = require('../gruntfile')

@@ -19,2 +19,2 @@ const grunt = gruntfile.call(gt, gt)

export { grunt, runGrunt }
module.exports = { grunt, runGrunt }

@@ -100,6 +100,5 @@ const _ = require('lodash')

* Array of crumbs, dot-notation string or url.
* @param {boolean} [forceRender = true] Render output with Nunjucks
* @param {boolean} [cached = true] Use cached rendered version if available
* @param {object} [ctx = this.getVariables()] Nunjucks context for forced rendering
* @return {object} Properties of the page, including its sub pages
* @param {object} [ctx = this.getVariables()] Nunjucks context
* @return {object} Rendered properties of the page, including its sub pages
* To get not rendered properties, access `$raw` property
* @example

@@ -109,32 +108,18 @@ * getPage('blog.post')

* getPage(['blog', 'post'])
* getPage(['blog', 'post']).$raw
*/
env.addGlobal('getPage', function (path, forceRender = true, cached = true, ctx = this.getVariables()) {
env.addGlobal('getPage', function (path, ctx = this.getVariables()) {
path = (path.includes('/') && crumble(path)) || path
const { matter } = this.ctx.SITE
const renderData = (tmpl) => render(env, ctx, tmpl)
const { SITE: { matter } } = this.ctx
let page = _.get(matter, path)
let $raw = _.get(matter.$raw, path)
const getRenderedData = () => {
if (!this.ctx.SITE.matterRendered) {
this.ctx.SITE.matterRendered = renderData(matter)
}
if (!page || (matter.$raw && !$raw)) return log.error(`[getPage] can not find \`${path}\` inside site Matter data [${this.ctx.PAGE.props.url}]`)
return this.ctx.SITE.matterRendered
}
page = Object.assign({}, { $raw }, page)
const data = (forceRender && cached && getRenderedData()) || matter
Object.defineProperty(page, 'props', { enumerable: false })
Object.defineProperty(page, '$raw', { enumerable: false })
let page = _.get(data, path)
if (!page) {
log.error(`[getPage] can not find \`${path}\` inside site Matter data [${this.ctx.PAGE.props.url}]`)
return
}
if (forceRender) {
page = cached ? page : renderData(page)
}
page = Object.assign({}, page)
Object.defineProperty(page, 'props', { enumerable: false })
return page

@@ -168,4 +153,7 @@ })

env.addGlobal('initPage', function () {
const { config, getPage, numbro, moment } = this.env.globals
const { format } = this.env.filters
const { env: { globals, filters }, ctx } = this
const { numbro, moment } = globals
const config = globals.config.bind(this)
const getPage = globals.getPage.bind(this)
const format = filters.format.bind(this)

@@ -175,6 +163,8 @@ // Use specified on page breadcrumb if there is one.

// inside page or layout that page extends.
const breadcrumb = this.ctx.PAGE.breadcrumb || this.ctx.PAGE.props.breadcrumb
const breadcrumb = ctx.PAGE.breadcrumb || ctx.PAGE.props.breadcrumb
// Retrieve page props following breadcrumb, render (as part of `getPage`) and format it
config.call(this, 'PAGE', format.call(this, getPage.call(this, breadcrumb).props, this.ctx.PLACEHOLDERS))
const pageProps = getPage(breadcrumb).props
const formattedPageProps = format(pageProps, ctx.PLACEHOLDERS)
config('PAGE', formattedPageProps)

@@ -184,10 +174,10 @@ // Fill page data with rest of only available through Nunjucks injection props

// because they can be computed only during Nunjucks task runtime
config.call(this, 'PAGE', this.ctx.PAGE.props)
config('PAGE', ctx.PAGE.props)
// Set l10n defaults
const { locale } = this.ctx.PAGE
const { locale } = ctx.PAGE
numbro.setLanguage(locale)
numbro.defaultFormat(this.ctx.SITE.locales[locale].numberFormat)
numbro.defaultCurrencyFormat(this.ctx.SITE.locales[locale].currencyFormat)
numbro.defaultFormat(ctx.SITE.locales[locale].numberFormat)
numbro.defaultCurrencyFormat(ctx.SITE.locales[locale].currencyFormat)

@@ -194,0 +184,0 @@ moment.locale(locale)

const { get, merge } = require('lodash')
const { join } = require('path')
const crumble = require('../modules/crumble')
const humanReadableUrl = require('../modules/humanReadableUrl')
const i18nTools = require('../modules/i18n-tools')
const nunjucksExtensions = require('../modules/nunjucks-extensions')
const crumble = require('./crumble')
const humanReadableUrl = require('./humanReadableUrl')
const i18nTools = require('./i18n-tools')
const nunjucksExtensions = require('./nunjucks-extensions')
const render = require('./nunjucks-render')
let matterCache
let imagesCache
const prepareMatter = (env, data) => {
const { matter } = data.SITE
const theMatter = typeof matter === 'function' ? matter() : matter
const rendered = render(env, data, theMatter)
data.SITE.matter = rendered
data.SITE.matter.$raw = theMatter
}
module.exports = function (config) {

@@ -55,8 +62,6 @@ config = merge({

}
},
preprocessData (data) {
const pagepath = humanReadableUrl(this.src[0].replace((this.orig.cwd || this.orig.orig.cwd), ''), humanReadableUrlsExclude)
const breadcrumb = crumble(pagepath)
const { matter, images } = data.SITE
const { data } = env.opts
const { SITE } = data
const { matter, images } = SITE

@@ -71,15 +76,12 @@ if ((typeof matter !== 'function') && (typeof matter !== 'object')) {

if (!matterCache) {
matterCache = typeof matter === 'function' ? matter() : matter
}
prepareMatter(env, data)
SITE.images = typeof images === 'function' ? images() : images
},
if (!imagesCache) {
imagesCache = typeof images === 'function' ? images() : images
}
preprocessData (data) {
const pagepath = humanReadableUrl(this.src[0].replace((this.orig.cwd || this.orig.orig.cwd), ''), humanReadableUrlsExclude)
const breadcrumb = crumble(pagepath)
const { matter } = data.SITE
const { props } = get(matter, breadcrumb)
data.SITE.matter = Object.assign({}, matterCache)
data.SITE.images = imagesCache
const { props } = get(matterCache, breadcrumb)
data.PAGE = merge(data.PAGE, {

@@ -125,1 +127,3 @@ props: {

}
module.exports.prepareMatter = prepareMatter

@@ -1,8 +0,9 @@

import nunjucks from 'nunjucks'
import cloneDeep from 'lodash/cloneDeep'
import { grunt } from './grunt'
import nunjucksExtensions from './nunjucks-extensions'
import i18nTools from './i18n-tools'
const nunjucks = require('nunjucks')
const cloneDeep = require('lodash/cloneDeep')
const { grunt } = require('./grunt')
const nunjucksExtensions = require('./nunjucks-extensions')
const i18nTools = require('./i18n-tools')
const { cache } = require('./cache')
export const env = nunjucks.configure(grunt.config('path.source.templates'))
const env = nunjucks.configure(grunt.config('path.source.templates'))

@@ -16,9 +17,12 @@ nunjucksExtensions(env)

* for Kotsu environment
* @param {string} template Template to render
* @param {object [context] Template context
* @param {boolean} [parse] Parse output with `JSON.parse`.
* Useful for object or array dumps
* @param {string} template Template to render
* @param {object} [context] Template context
* @param {boolean} [parse] Parse output with `JSON.parse`.
* Useful for object or array dumps
* @param {boolean} [resetCache=true] Reset cache
* @return {string} Rendered template
*/
export const renderString = (template, context, parse) => {
const renderString = (template, context, parse, resetCache = true) => {
if (resetCache) cache.reset()
const rendered = env.renderString(template, cloneDeep(context))

@@ -32,1 +36,3 @@

}
module.exports = { env, renderString }
{
"name": "kotsu",
"version": "1.12.0",
"version": "1.13.0",
"description": "Clean, opinionated foundation for new projects — to boldly go where no man has gone before",

@@ -58,7 +58,6 @@ "homepage": "https://kotsu.2bad.me",

"grunt-image-size": "1.0.0",
"grunt-nunjucks-2-html": "2.1.0",
"grunt-nunjucks-2-html": "2.2.0",
"grunt-postcss": "0.9.0",
"grunt-responsive-images": "1.10.1",
"grunt-sass": "2.1.0",
"grunt-shell": "2.1.0",
"grunt-sitemap-xml": "0.3.0",

@@ -70,5 +69,7 @@ "grunt-size-report": "0.1.4",

"grunt-webfont": "1.6.0",
"hash-sum": "1.0.2",
"jit-grunt": "0.10.0",
"jspm": "0.17.0-beta.47",
"lodash": "4.17.5",
"lru-cache": "4.1.2",
"markdown-it": "8.4.1",

@@ -99,3 +100,2 @@ "moment": "2.21.0",

"jest-jspm": "0.1.2",
"npm-run-all": "4.1.2",
"snazzy": "7.1.1",

@@ -129,10 +129,4 @@ "standard": "11.0.1",

"postinstall": "jspm config registries.github.auth $GITHUB_API_KEY && jspm install",
"start": "run-p \"grunt -- {@}\" js:watch --",
"start-hmr": "run-p \"grunt -- --hmr {@}\" js:chokidar --",
"serve": "run-p grunt:serve js:watch",
"serve-hmr": "run-p \"grunt:serve -- --hmr\" js:chokidar",
"grunt": "grunt",
"grunt:serve": "grunt serve",
"js:chokidar": "cd ./source/scripts && chokidar-socket-emitter",
"js:watch": "grunt shell:jspm_watch",
"start": "grunt",
"serve": "grunt serve",
"lint": "standard | snazzy && stylelint \"**/*.{css,scss,sass}\" \"!{jspm_packages,build,temp}/**\"",

@@ -142,4 +136,6 @@ "test": "npm run lint && jest",

"build": "grunt build",
"jspm": "jspm",
"preversion": "npm test && npm run build",
"postbuild": "node modules/clean-workdir.js"
"version": "node modules/changelog-version",
"postbuild": "node modules/clean-workdir"
},

@@ -146,0 +142,0 @@ "browserslist": [

@@ -46,3 +46,3 @@ ![Kotsu](https://cloud.githubusercontent.com/assets/4460311/23858130/1da87904-0808-11e7-9748-9f56fb8a55e0.png)

9. *(optional)* Set up Continuous Deployment with [CircleCI](https://circleci.com/) or [Werker](http://wercker.com/) Docker following our [guide](https://github.com/LotusTM/Kotsu/wiki/Continuous-Delivery-with-Wercker-Docker-and-CoreOS)
10. Code live with: `npm start` or `npm run start-hmr` if you need [hot module reloading](https://github.com/alexisvincent/systemjs-hot-reloader/)
10. Code live with: `npm start` or `npm start -- --hmr` if you need [Hot Module Reloading](https://github.com/alexisvincent/systemjs-hot-reloader/)
11. Build with: `npm run build`

@@ -49,0 +49,0 @@ 12. Deploy and enjoy your life

// Uncomment if you need to support advanced ES6 features in IE11 and below
// import 'babel-polyfill'
import { SITE, ENV } from '@data'
import data from '@data'
import './utils/dom-polyfills'
const { SITE, ENV } = data
console.log(`${SITE.name} v${SITE.version} #${ENV.buildNumber}, SHA1 ${ENV.buildSHA1}`)
document.querySelector('html').classList.remove('no-js')
module.exports = function () {
// Shell
// https://github.com/sindresorhus/grunt-shell
// Run shell commands
// Launch JSPM build
// @link modules/grunt-jspm
this.config('shell', {
jspm_build: {
command: 'jspm build main <%= file.build.script.minified %> --minify'
this.config('jspm', {
watch: {
options: {
args: ['-wid']
},
files: [{
packageName: 'main',
dest: '<%= file.build.script.compiled %>'
}]
},
jspm_watch: {
command: 'jspm build main <%= file.build.script.compiled %> -wid'
build: {
options: {
args: ['--minify']
},
files: [{
packageName: 'main',
dest: '<%= file.build.script.minified %>'
}]
}
})
// Launch chockidar-socket-emitter for JSPM (SystemJS),
// which is needed to triger updated when Hot Module Reloading
// is enabled with `--hmr` flag
// @link modules/grunt-jspm-emitter
this.config('jspmEmitter', {
listen: {
options: {
watchTask: true,
cwd: '<%= path.source.scripts %>'
}
}
})
// Clean

@@ -16,0 +41,0 @@ // https://github.com/gruntjs/grunt-contrib-clean

/* eslint-env jest */
import { renderString } from '../../../modules/nunjucks-test-utils'
import { env, renderString } from '../../../modules/nunjucks-test-utils'
import { prepareMatter } from '../../../modules/nunjucks-task'

@@ -8,2 +9,3 @@ const render = (template, context = mockContext, parse) => renderString(template, context, parse)

SITE: {
name: 'Test name',
matter: {

@@ -19,6 +21,9 @@ 'index': {

},
'testVar': {
'props': { 'var': '__globarvar value: {{ __globalvar }}' }
'contexVar': {
'props': { 'var': '__contextvar value: {{ __contextvar }}' }
},
'testFunc': {
'globalVar': {
'props': { 'var': 'SITE.name value: {{ SITE.name }}' }
},
'globalFunc': {
'props': { 'func': 'Crumbled url: {{ crumble("blog") }}' }

@@ -35,2 +40,4 @@ }

describe('Nunjucks global function `getPage()`', () => {
beforeAll(() => prepareMatter(env, mockContext))
describe('should get from', () => {

@@ -86,11 +93,29 @@ it('root string-based path', () => {

describe('should force-render received data', () => {
it('with current context', () => {
expect(render(`{% set __globalvar = 'testing __globalvar value' %}{{ getPage('testVar').props.var }}`)).toMatchSnapshot()
it('should get $raw data', () => {
expect(render(`{{ getPage('contexVar').$raw|dump|safe }}`, undefined, true)).toMatchSnapshot()
})
it('should allow to render $raw data', () => {
expect(render(`
{% set __contextvar = 'testing __contextvar value' %}
{{ getPage('contexVar').$raw.props.var|render() }}
`)).toMatchSnapshot()
})
describe('should get rendered data', () => {
it('with global context', () => {
expect(render(`{{ getPage('globalVar').props.var }}`)).toMatchSnapshot()
})
it('with current custom functions', () => {
expect(render(`{{ getPage('testFunc').props.func }}`)).toMatchSnapshot()
it('with global custom functions', () => {
expect(render(`{{ getPage('globalFunc').props.func }}`)).toMatchSnapshot()
})
it('and ignore current context', () => {
expect(render(`
{% set __contextvar = 'testing __contextvar value' %}
{{ getPage('contexVar').props.var }}
`)).toMatchSnapshot()
})
})
})

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc