Skip to content

Commit

Permalink
Refactoe according to feedback. Reuse templates/components, generate …
Browse files Browse the repository at this point in the history
…exportables from template files.
  • Loading branch information
rokbar-nosto committed Dec 20, 2023
1 parent d26ca47 commit 206322e
Show file tree
Hide file tree
Showing 15 changed files with 258 additions and 563 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"type": "git",
"url": "git+https://github.com/Nosto/nosto-autocomplete.git"
},
"type": "module",
"license": "BSD-3-Clause",
"author": "Nosto",
"main": "dist/nosto-autocomplete.cjs",
Expand Down
27 changes: 27 additions & 0 deletions scripts/exportTemplates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as fs from 'fs'

// write script that generates const variable string from /src/defaults/autocomplete.liquid
function generateAutocompleteLiquid() {
const autocompleteLiquid = fs.readFileSync('./src/defaults/autocomplete.liquid', 'utf8')
const autocompleteLiquidLines = autocompleteLiquid.split('\n')
const autocompleteLiquidLinesWithConst = `export const defaultLiquidTemplate = \`\n${autocompleteLiquidLines.map(line => ` ${line}`).join('\n')}\n\`\n`

fs.appendFileSync('./src/_generated.ts', autocompleteLiquidLinesWithConst)
}

function generateAutocompleteMustache() {
const autocompleteMustache = fs.readFileSync('./src/defaults/autocomplete.mustache', 'utf8')
const autocompleteMustacheLines = autocompleteMustache.split('\n')
const autocompleteMustacheLinesWithConst = `export const defaultMustacheTemplate = \`\n${autocompleteMustacheLines.map(line => ` ${line}`).join('\n')}\n\`\n`

fs.appendFileSync('./src/_generated.ts', autocompleteMustacheLinesWithConst)
}

(() => {
if (fs.existsSync('./src/_generated.ts')) {
fs.unlinkSync('./src/_generated.ts')
}

generateAutocompleteLiquid()
generateAutocompleteMustache()
})()
162 changes: 0 additions & 162 deletions spec/components/Autocomplete.tsx

This file was deleted.

3 changes: 1 addition & 2 deletions spec/liquid.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import "@testing-library/jest-dom"
import {
fromLiquidTemplate, fromRemoteLiquidTemplate,
fromLiquidTemplate, fromRemoteLiquidTemplate, defaultLiquidTemplate as liquidTemplate
} from "../src/liquid"
import { handleAutocomplete, hooks, autocompleteSuite } from './suites/autocomplete'
import liquidTemplate from './templates/liquid'
import { waitFor } from '@testing-library/dom'

function libraryScript() {
Expand Down
2 changes: 1 addition & 1 deletion spec/mustache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import "@testing-library/jest-dom"
import {
fromMustacheTemplate,
fromRemoteMustacheTemplate,
defaultMustacheTemplate as mustacheTemplate
} from "../src/mustache"
import mustacheTemplate from "./templates/mustache"
import {
autocompleteSuite,
handleAutocomplete,
Expand Down
2 changes: 1 addition & 1 deletion spec/react.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "@testing-library/jest-dom"
import { Autocomplete } from "./components/Autocomplete"
import { Autocomplete } from "../src/defaults/Autocomplete"
import type React from "react"
import type ReactDOM from "react-dom/client"
import { DefaultState } from '../src/utils/state'
Expand Down
101 changes: 0 additions & 101 deletions spec/templates/liquid.ts

This file was deleted.

Loading

0 comments on commit 206322e

Please sign in to comment.