Skip to content

Commit 981ee52

Browse files
authored
Logrocket (#23)
* introduce logrocket * clean webpack removes also usefull files * apply script * how number of pages
1 parent 0926583 commit 981ee52

File tree

11 files changed

+1251
-8
lines changed

11 files changed

+1251
-8
lines changed

.github/workflows/deploy_theme.yml

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
path: |
2121
~/.npm
2222
~/.cache/bazel
23+
**/node_modules
2324
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/go.sum') }}
2425
restore-keys: |
2526
${{ runner.os }}-
@@ -30,3 +31,4 @@ jobs:
3031
env:
3132
THEME_APP_SECRET: ${{ secrets.THEME_APP_SECRET }}
3233
THEME_ID: ${{ secrets.THEME_ID }}
34+
LOGROCKET_APP_NAME: ${{ secrets.LOGROCKET_APP_NAME }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
# /generated
33
/bin
44
/onix/*.onix
5+
/theme/assets/app.min.*

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ MD_FILES := $(shell find ./ -type f -name '*.md')
22
GO_FILES := $(shell find ./ -type f -name '*.go' | grep -v "generated")
33
TK := npx bazelisk run //:theme --
44
LINT := yarn theme-lint
5+
WP := yarn webpack
56
BZL := yarn bazelisk --
67
BZL_BIN := $(shell npx bazelisk info bazel-bin)
78
VERSION := $(shell cat content/.version | tr -d '\n')
@@ -10,6 +11,7 @@ ONIX_FILE := ""
1011
.PHONY: deploy/theme,deploy/contents,watch,download/theme
1112

1213
deploy/theme:
14+
$(WP)
1315
$(TK) deploy --dir theme
1416

1517
deploy/contents: $(MD_FILES)

onix/onix.go

+21
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const shopDomain string = "k9books.myshopify.com"
2323
var metaFieldNamespace string = "k9bookshelf"
2424
var metaFieldKeyPublishedAt string = "published_at"
2525
var metaFieldKeySubTitle string = "subtitle"
26+
var metaFieldKeyNumberOfPages string = "number_of_pages"
2627

2728
var appKey string = os.Getenv("INGRAM_CONTENT_IMPORTER_APP_KEY")
2829
var appSecret string = os.Getenv("INGRAM_CONTENT_IMPORTER_APP_SECRET")
@@ -183,6 +184,7 @@ func Run(input string) error {
183184
// }
184185

185186
title := d.Title.TitleText
187+
numberOfPages := fmt.Sprintf("%d", d.NumberOfPages)
186188
date, err := extractDatetime(d.PublicationDate)
187189
if err != nil {
188190
return err
@@ -191,6 +193,7 @@ func Run(input string) error {
191193
valueType := client.MetafieldValueTypeString
192194
var publishedAtID *string
193195
var subTitleID *string
196+
var numberOfPagesID *string
194197
for _, edge := range currentProduct.Node.Metafields.Edges {
195198
if edge.Node.Key == metaFieldKeyPublishedAt {
196199
publishedAtID = &edge.Node.ID
@@ -203,6 +206,12 @@ func Run(input string) error {
203206
break
204207
}
205208
}
209+
for _, edge := range currentProduct.Node.Metafields.Edges {
210+
if edge.Node.Key == metaFieldKeyNumberOfPages {
211+
numberOfPagesID = &edge.Node.ID
212+
break
213+
}
214+
}
206215

207216
// NOTE: DescriptionHTML and Tags are possible to edit manually,
208217
// So we should touch only at create-time.
@@ -220,6 +229,12 @@ func Run(input string) error {
220229
Key: &metaFieldKeySubTitle,
221230
Namespace: &metaFieldNamespace,
222231
ValueType: &valueType,
232+
}, {
233+
ID: numberOfPagesID,
234+
Value: &numberOfPages,
235+
Key: &metaFieldKeyNumberOfPages,
236+
Namespace: &metaFieldNamespace,
237+
ValueType: &valueType,
223238
}},
224239
// Variants: []*client.ProductVariantInput{
225240
// {
@@ -283,6 +298,7 @@ func Run(input string) error {
283298
if err != nil {
284299
return err
285300
}
301+
numberOfPages := fmt.Sprintf("%d", d.NumberOfPages)
286302
value := date.String()
287303
valueType := client.MetafieldValueTypeString
288304
res, err := gqlClient.ProductCreateDo(context.Background(), client.ProductInput{
@@ -298,6 +314,11 @@ func Run(input string) error {
298314
Key: &metaFieldKeySubTitle,
299315
Namespace: &metaFieldNamespace,
300316
ValueType: &valueType,
317+
}, {
318+
Value: &numberOfPages,
319+
Key: &metaFieldKeyNumberOfPages,
320+
Namespace: &metaFieldNamespace,
321+
ValueType: &valueType,
301322
}},
302323
Variants: []*client.ProductVariantInput{
303324
{

package.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
"license": "ISC",
1212
"dependencies": {
1313
"@bazel/bazelisk": "1.7.3",
14-
"@shopify/theme-lint": "3.1.0"
14+
"@shopify/theme-lint": "3.1.0",
15+
"logrocket": "1.0.14"
16+
},
17+
"devDependencies": {
18+
"terser-webpack-plugin": "5.0.3",
19+
"ts-loader": "8.0.12",
20+
"typescript": "4.1.3",
21+
"webpack": "5.11.0",
22+
"webpack-cli": "4.2.0"
1523
}
1624
}

storefront/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import LogRocket from 'logrocket';
2+
LogRocket.init('fzwoar/k9bookshelf');

theme/layout/theme.liquid

+1
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,6 @@
104104
</ul>
105105

106106
{{ 'theme.js' | asset_url | script_tag }}
107+
{{ 'app.min.js' | asset_url | script_tag }}
107108
</body>
108109
</html>

theme/sections/product-template.liquid

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181

8282
<p class="product-single__vendor" itemprop="brand">{{ product.vendor | link_to_vendor }}</p>
8383
<p class="product-single__vendor">発売日: {{product.metafields.k9bookshelf.published_at | date: "%Y/%m/%d" }}</p>
84+
<p class="product-single__vendor">ページ数: {{product.metafields.k9bookshelf.number_of_pages }}</p>
8485

8586
<ul class="product-single__tags">
8687
{% for tag in product.tags %}

tsconfig.json

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"compilerOptions": {
3+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
4+
5+
/* Basic Options */
6+
// "incremental": true, /* Enable incremental compilation */
7+
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9+
// "lib": [], /* Specify library files to be included in the compilation. */
10+
// "allowJs": true, /* Allow javascript files to be compiled. */
11+
// "checkJs": true, /* Report errors in .js files. */
12+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
14+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15+
// "sourceMap": true, /* Generates corresponding '.map' file. */
16+
// "outFile": "./", /* Concatenate and emit output to single file. */
17+
// "outDir": "./", /* Redirect output structure to the directory. */
18+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
19+
// "composite": true, /* Enable project compilation */
20+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
21+
// "removeComments": true, /* Do not emit comments to output. */
22+
// "noEmit": true, /* Do not emit outputs. */
23+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
24+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
25+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
26+
27+
/* Strict Type-Checking Options */
28+
"strict": true, /* Enable all strict type-checking options. */
29+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
30+
// "strictNullChecks": true, /* Enable strict null checks. */
31+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
32+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
33+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
34+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
35+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
36+
37+
/* Additional Checks */
38+
// "noUnusedLocals": true, /* Report errors on unused locals. */
39+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
40+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
41+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
42+
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
43+
44+
/* Module Resolution Options */
45+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
46+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
47+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
48+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
49+
// "typeRoots": [], /* List of folders to include type definitions from. */
50+
// "types": [], /* Type declaration files to be included in compilation. */
51+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
52+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
53+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
54+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
55+
56+
/* Source Map Options */
57+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
58+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
59+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
60+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
61+
62+
/* Experimental Options */
63+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
64+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
65+
66+
/* Advanced Options */
67+
"skipLibCheck": true, /* Skip type checking of declaration files. */
68+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
69+
},
70+
"exclude": [
71+
"bazel-*",
72+
]
73+
}

webpack.config.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const webpack = require('webpack');
4+
const TerserJSPlugin = require('terser-webpack-plugin');
5+
6+
module.exports = {
7+
entry: './storefront/index.ts',
8+
module: {
9+
rules: [
10+
{
11+
test: /\.tsx?$/,
12+
use: 'ts-loader',
13+
exclude: /node_modules/,
14+
},
15+
],
16+
},
17+
resolve: {
18+
extensions: ['.ts'],
19+
},
20+
devtool: 'hidden-source-map',
21+
optimization: {
22+
minimizer: [new TerserJSPlugin({})],
23+
},
24+
mode: process.env.NODE_ENV,
25+
output: {
26+
path: path.resolve(__dirname, 'theme','assets'),
27+
filename: 'app.min.js',
28+
},
29+
plugins: [
30+
new webpack.DefinePlugin({
31+
'process.env.BACKEND_ROOT': JSON.stringify(process.env.LOGROCKET_APP_NAME)
32+
}),
33+
],
34+
};

0 commit comments

Comments
 (0)