Commit 53eff927 authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Add Sapper skeleton.

parent 858ff986
Pipeline #207470 failed with stage
in 2 minutes and 33 seconds
*
!/src
!/static
!/LICENSE.md
!/package*.json
!/README.md
!/postcss.config.js
!/rollup.config.js
!/tailwind.config.js
!/tsconfig.json
/__sapper__/
/node_modules/
/src/node_modules/@sapper/
/static/global.css
/static/global.css.map
*.env
!example.env
Publish Docker image:
stage: build
only:
- changes
- master
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
# - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG --destination $CI_REGISTRY_IMAGE:latest
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:latest
FROM node:15
WORKDIR /app
COPY package*.json ./
RUN npm ci
ENV NODE_ENV production
COPY . .
RUN npm run build && \
# Remove devDependencies
npm prune
EXPOSE 3000
VOLUME /public_data
ENV PUBLIC_DATA_DIR="/public_data"
ENV TITLE="EZ-DDI (Docker)"
CMD npm start
......@@ -3,8 +3,9 @@
_Fetch, validate, convert & serve CESSDA-compliants DDI repositories._
By:
* [Agnieszka Slusarczyk](mailto:agneska@agneska.fr)
* [Emmanuel Raviart](mailto:emmanuel@raviart.com)
- [Agnieszka Slusarczyk](mailto:agneska@agneska.fr)
- [Emmanuel Raviart](mailto:emmanuel@raviart.com)
Copyright (C) 2020 Cepremap & Progedo
......
......@@ -12,6 +12,8 @@ npm install
## Usage
### Fetching Nesstar Servers
```bash
npx tsc
# ADISP
......@@ -27,3 +29,17 @@ node src/scripts/retrieve_nesstar_ddis.js --url http://nesstar.ukdataservice.ac.
# Norwegian Centre for Research Data
node src/scripts/retrieve_nesstar_ddis.js --url http://nsddata.nsd.uib.no ../public_data/nsddata-ddi/
```
### Extracting TypeScript Raw Types from DDI files
```bash
npx babel-node --extensions ".ts" --max-old-space-size=8192 src/scripts/raw_types_from_ddi_files.ts ../public_data/adisp-ddi/ ../public_data/adisp-ddi/ ../public_data/ined-ddi/ --target=src/raw_types/enquetes.ts
npx babel-node --extensions ".ts" --max-old-space-size=8192 src/scripts/raw_types_from_ddi_files.ts ../public_data/xml-ddi-adisp/ --target=src/raw_types/enquetes_adisp_fournies.ts
npx babel-node --extensions ".ts" --max-old-space-size=8192 src/scripts/raw_types_from_ddi_files.ts ../public_data/adisp-ddi/ --target=src/raw_types/enquetes_adisp.ts
npx babel-node --extensions ".ts" --max-old-space-size=8192 src/scripts/raw_types_from_ddi_files.ts ../public_data/cdsp-ddi/ --target=src/raw_types/enquetes_cdsp.ts
npx babel-node --extensions ".ts" --max-old-space-size=8192 src/scripts/raw_types_from_ddi_files.ts ../public_data/ined-ddi/ --target=src/raw_types/enquetes_ined.ts
# Prettify generated TypeScript files:
npm run prettier
```
module.exports = {
presets: [
[
"@babel/preset-env",
{
bugfixes: true,
corejs: 3,
targets: "> 0.25%, not dead",
useBuiltIns: "usage",
},
],
"@babel/preset-typescript",
],
plugins: ["@babel/plugin-syntax-dynamic-import"],
}
import fs from "fs"
import postcss from "postcss"
// eslint-disable-next-line import/extensions
import postcssConfig from "./postcss.config.js"
const { readFile, unlink, writeFile } = fs.promises
const main = async () => {
let sourcemap = process.argv[process.argv.length - 1]
if (sourcemap === "true") sourcemap = true
else if (sourcemap === "false") sourcemap = false
const pcss = await readFile("src/styles/index.pcss")
const result = await postcss(postcssConfig.plugins).process(pcss, {
from: "src/styles/index.pcss",
to: "static/global.css",
map: sourcemap ? { inline: sourcemap === "inline" } : false,
})
await writeFile("static/global.css", result.css)
if (result.map)
await writeFile("static/global.css.map", result.map.toString())
else {
try {
await unlink("static/global.css.map")
} catch (err) {
if (err.code !== "ENOENT") {
throw err
}
}
}
}
main()
# To use this file, rename it to `.env`.
BASE_URL="http://localhost:3000"
# PostgreSQL database configuration
DB_HOST="localhost"
DB_PORT=5432
DB_NAME="ezddi"
DB_USER="ezddi"
# Change value of DB_PASSWORD!
DB_PASSWORD="ezdddi"
# DEV_AUTHENTICATION='{"email": "exemple.admin@example.com", "full_name": "Exemple Admin", "preferred_username": "admin", "roles": ["ezddi_admin"]}'
# DEV_AUTHENTICATION='{"email": "exemple.diffuseur@example.com", "full_name": "Exemple Diffuseur", "preferred_username": "diffuseur", "roles": ["ezddi_diffuseur"]}'
DEV_AUTHENTICATION='{"email": "exemple.support@example.com", "full_name": "Exemple Suport", "preferred_username": "support", "roles": ["ezddi_support"]}'
# DEV_AUTHENTICATION='{"email": "exemple.utilisateur@example.com", "full_name": "Exemple Utilisateur", "preferred_username": "utilisateur", "roles": ["ezddi_utilisateur"]}'
# Log every HTTP requests.
NODE_ENV="development"
# OpenID Connect configuration
# OPENID_CONNECT_CLIENT_ID="OPENID_CONNECT_CLIENT_ID"
# OPENID_CONNECT_CLIENT_SECRET="OPENID_CONNECT_CLIENT_SECRET"
# OPENID_CONNECT_ISSUER_URL="https://IDENTITY_PROVIDER/REALM"
# Set to true when application is behind a proxy.
PROXY=false
# Directory containing public data files used by application (DDI survey files, etc).
PUBLIC_DATA_DIR="../public_data"
# Change value OF SESSION_SECRET!
SESSION_SECRET="SESSION_SECRET"
# TITLE="EZ-DDI"
This diff is collapsed.
{
"name": "ez-ddi",
"version": "0.0.1",
"description": "Fetch, validate, convert & serve CESSDA-compliants DDI repositories",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "AGPL-3.0-or-later",
"repository": {
"type": "git",
"url": "https://git.nomics.world/progedo/ez-ddi.git"
},
"version": "0.0.1",
"author": "DBnomics Team",
"license": "AGPL-3.0-or-later",
"devDependencies": {
"@types/command-line-args": "^5.0.0",
"@types/fs-extra": "^9.0.5",
"@types/node": "^14.14.12",
"@types/node-fetch": "^2.5.7",
"prettier": "^2.2.1",
"typescript": "^4.1.2"
"scripts": {
"dev": "sapper dev",
"build": "sapper build --legacy",
"clean": "rimraf __sapper__",
"configure": "babel-node --extensions \".ts\" src/configure.ts",
"export": "sapper export --legacy",
"postinstall": "patch-package",
"prettier": "prettier --plugin-search-dir=. --write \"*.js\" --write \"src/*.ts\" \"src/**/*.ts\" \"src/**/*.svelte\"",
"start": "node __sapper__/build",
"validate": "svelte-check --ignore src/node_modules/@sapper"
},
"engines": {
"node": ">=15"
},
"dependencies": {
"body-parser": "^1.19.0",
"command-line-args": "^5.1.1",
"compression": "^1.7.1",
"express-session": "^1.17.1",
"fast-xml-parser": "^3.17.5",
"fs-extra": "^9.0.1",
"node-fetch": "^2.6.1",
"node-stream-zip": "^1.12.0",
"query-string": "^6.13.7"
"polka": "next",
"sirv": "^1.0.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/node": "^7.12.10",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-typescript": "^7.12.7",
"@babel/runtime": "^7.0.0",
"@biryani/core": "^0.4.2",
"@fluent/bundle": "^0.16.0",
"@fluent/langneg": "^0.5.0",
"@fluent/sequence": "^0.6.0",
"@rollup/plugin-babel": "^5.0.0",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.0.1",
"@rollup/plugin-replace": "^2.2.0",
"@rollup/plugin-typescript": "^8.1.0",
"@rollup/plugin-url": "^6.0.0",
"@tsconfig/svelte": "^1.0.10",
"@types/command-line-args": "^5.0.0",
"@types/compression": "^1.7.0",
"@types/connect-pg-simple": "^4.2.2",
"@types/express": "^4.17.9",
"@types/express-session": "^1.17.3",
"@types/fs-extra": "^9.0.5",
"@types/node": "^14.14.12",
"@types/node-fetch": "^2.5.7",
"@types/passport": "^1.0.4",
"@types/passport-local": "^1.0.33",
"@types/polka": "^0.5.1",
"a17t": "^0.4.0",
"cached-iterable": "^0.3.0",
"command-line-args": "^5.1.1",
"connect-pg-simple": "^6.2.1",
"cssnano": "^4.1.10",
"dedent-js": "^1.0.1",
"dotenv": "^8.2.0",
"fast-xml-parser": "^3.17.4",
"fs-extra": "^9.0.1",
"kleur": "^4.1.3",
"morgan": "^1.10.0",
"openid-client": "^4.2.2",
"passport": "^0.4.1",
"passport-local": "^1.0.0",
"patch-package": "^6.2.2",
"pg-native": "^3.0.0",
"pg-promise": "^10.7.5",
"postcss": "^8.1.6",
"postcss-each": "^0.10.0",
"postcss-import": "^14.0.0",
"postcss-load-config": "^2.1.2",
"prettier": "^2.2.1",
"prettier-plugin-svelte": "^1.4.1",
"quicktype-core": "^6.0.62",
"rimraf": "^3.0.2",
"rollup": "^2.3.4",
"rollup-plugin-svelte": "^7.0.0",
"rollup-plugin-terser": "^7.0.0",
"sapper": "^0.28.0",
"svelte": "^3.17.3",
"svelte-check": "^1.1.17",
"svelte-preprocess": "^4.6.1",
"tailwindcss": "^2.0.1",
"tslib": "^2.0.1",
"typescript": "^4.1.2"
}
}
const cssnano = require("cssnano")
const postcssImport = require("postcss-import")
const tailwindcss = require("tailwindcss")
const tailwindcssConfig = require("./tailwind.config")
const mode = process.env.NODE_ENV
const dev = mode === "development"
module.exports = {
plugins: [
postcssImport,
// require("postcss-url")(),
tailwindcss(tailwindcssConfig),
// Plugins for polyfills and the like (such as postcss-preset-env) should generally go here
// but a few have to run *before* Tailwind
!dev &&
cssnano({
preset: ["default", { discardComments: { removeAll: true } }],
}),
].filter(Boolean),
}
import babel from "@rollup/plugin-babel"
import commonjs from "@rollup/plugin-commonjs"
import json from "@rollup/plugin-json"
import resolve from "@rollup/plugin-node-resolve"
import replace from "@rollup/plugin-replace"
import typescript from "@rollup/plugin-typescript"
import url from "@rollup/plugin-url"
import { spawn } from "child_process"
import colors from "kleur"
import path from "path"
import { performance } from "perf_hooks"
import svelte from "rollup-plugin-svelte"
import { terser } from "rollup-plugin-terser"
import config from "sapper/config/rollup.js"
import pkg from "./package.json"
const { createPreprocessors } = require("./svelte.config.js")
const mode = process.env.NODE_ENV
const dev = mode === "development"
const sourcemap = dev ? "inline" : false
const legacy = !!process.env.SAPPER_LEGACY_BUILD
const preprocess = createPreprocessors({ sourceMap: !!sourcemap })
// Changes in these files will trigger a rebuild of the global CSS.
const globalCSSWatchFiles = [
"postcss.config.js",
"tailwind.config.js",
"src/styles/index.pcss",
]
const onwarn = (warning, onwarn) => {
switch (warning.code) {
case "CIRCULAR_DEPENDENCY":
if (/[/\\](@fluent|@sapper|passport)[/\\]/.test(warning.message)) {
return
}
break
case "MISSING_EXPORT":
if (/'preload'/.test(warning.message)) {
return
}
break
case "THIS_IS_UNDEFINED":
return
}
console.log("onwarn", warning)
return onwarn(warning)
}
export default {
client: {
input: config.client.input().replace(/\.js$/, ".ts"),
output: { ...config.client.output(), sourcemap },
plugins: [
replace({
"process.browser": true,
"process.env.NODE_ENV": JSON.stringify(mode),
}),
svelte({
compilerOptions: {
dev,
hydratable: true,
immutable: true,
},
emitCss: true,
preprocess,
}),
url({
sourceDir: path.resolve(__dirname, "src/node_modules/images"),
publicPath: "/client/",
}),
resolve({
browser: true,
dedupe: ["svelte"],
}),
commonjs({ sourceMap: !!sourcemap }),
typescript({ sourceMap: !!sourcemap }),
legacy &&
babel({
babelHelpers: "runtime",
exclude: ["node_modules/@babel/**"],
extensions: [".js", ".mjs", ".html", ".svelte"],
presets: [
[
"@babel/preset-env",
{
targets: "> 0.25%, not dead",
},
],
],
plugins: [
"@babel/plugin-syntax-dynamic-import",
[
"@babel/plugin-transform-runtime",
{
useESModules: true,
},
],
],
}),
!dev &&
terser({
module: true,
}),
(() => {
let builder
let rebuildNeeded = false
const buildGlobalCSS = () => {
if (builder) {
rebuildNeeded = true
return
}
rebuildNeeded = false
const start = performance.now()
try {
builder = spawn("node", [
"--experimental-modules",
"--unhandled-rejections=strict",
"build-global-css.mjs",
sourcemap,
])
builder.stdout.pipe(process.stdout)
builder.stderr.pipe(process.stderr)
builder.on("close", (code) => {
if (code === 0) {
const elapsed = parseInt(performance.now() - start, 10)
console.log(
`${colors
.bold()
.green(
"✔ global css",
)} (src/styles/index.pcss → static/global.css${
sourcemap === true ? " + static/global.css.map" : ""
}) ${colors.gray(`(${elapsed}ms)`)}`,
)
} else if (code !== null) {
if (dev) {
console.error(`global css builder exited with code ${code}`)
console.log(colors.bold().red("✗ global css"))
} else {
throw new Error(`global css builder exited with code ${code}`)
}
}
builder = undefined
if (rebuildNeeded) {
console.log(
`\n${colors
.bold()
.italic()
.cyan("something")} changed. rebuilding...`,
)
buildGlobalCSS()
}
})
} catch (err) {
console.log(colors.bold().red("✗ global css"))
console.error(err)
}
}
return {
name: "build-global-css",
buildStart() {
buildGlobalCSS()
globalCSSWatchFiles.forEach((file) => this.addWatchFile(file))
},
generateBundle: buildGlobalCSS,
}
})(),
],
onwarn,
preserveEntrySignatures: false,
},
server: {
input: { server: config.server.input().server.replace(/\.js$/, ".ts") },
output: { ...config.server.output(), sourcemap },
plugins: [
replace({
"global.process.env.NODE_ENV": JSON.stringify(mode), // For pg-promise
"process.browser": false,
"process.env.NODE_ENV": JSON.stringify(mode),
}),
svelte({
compilerOptions: {
dev,
generate: "ssr",
hydratable: true,
immutable: true,
},
emitCss: false,
preprocess,
}),
url({
sourceDir: path.resolve(__dirname, "src/node_modules/images"),
publicPath: "/client/",
emitFiles: false, // already emitted by client build
}),
resolve({
dedupe: ["svelte"],
}),
commonjs({
sourceMap: !!sourcemap,
}),
typescript({ sourceMap: !!sourcemap }),
json(),
],
external:
Object.keys(pkg.dependencies).concat(require("module").builtinModules) ||
Object.keys(process.binding("natives")), // eslint-disable-line global-require,
onwarn,
preserveEntrySignatures: "strict",
},
serviceworker: {
input: config.serviceworker.input().replace(/\.js$/, ".ts"),
output: { ...config.serviceworker.output(), sourcemap },
plugins: [
resolve(),
replace({
"process.browser": true,
"process.env.NODE_ENV": JSON.stringify(mode),
}),
commonjs({ sourceMap: !!sourcemap }),
typescript({ sourceMap: !!sourcemap }),
!dev && terser(),
],
preserveEntrySignatures: false,
onwarn,
},
}
/**
* These declarations tell TypeScript that we allow import of images, e.g.
* ```
<script lang='ts'>
import successkid from 'images/successkid.jpg';
</script>
<img src="{successkid}">
```
*/
declare module "*.gif" {
const value: string
export = value
}
declare module "*.jpg" {
const value: string
export = value
}
declare module "*.jpeg" {
const value: string
export = value
}
declare module "*.png" {