@soleil-se/build-app 1.12.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,124 @@
1
+ ---
2
+ title: Changelog
3
+ ---
4
+
5
+ Baseras på [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) och använder [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [2.0.0] - 2024-10-21
8
+
9
+ - Ta bort stödet för WebApps 1.
10
+ - Stöd för Svelte 5, bakåtkompatibel med 3 och 4.
11
+ - Ta bort default alias för mer kontroll.
12
+ - Gör det möjligt att ta bort och lägga till tasks utan omstart.
13
+ - Sitevision API:er måste importeras med `@sitevision/api`.
14
+
15
+ ## [1.11.1] - 2024-01-09
16
+
17
+ - Nypublicering då något gick fel vid publicering av 1.11.0.
18
+ - Ändra homepage länk.
19
+
20
+ ## [1.11.0] - 2024-01-09
21
+
22
+ - Möjlighet att bygga ihop app utan `user_config.json` och `project_config.json`, vid synkning krävs dock filerna för miljöinformation och autentisering.
23
+ - Nya uppstartskommandon som bakar ihop argument:
24
+ - `build`: Bygger ihop appen utan att ladda upp.
25
+ - `watch`: Startar en watcher, när någon de filer som loggas vid uppstart ändras byggs appen ihop och laddas upp till default miljön eller den miljö som anges i `--env` argumentet.
26
+ - `start`: Bygger först ihop och laddar upp appen till default miljön eller den miljö som anges i `--env` argumentet, därefter startas en watcher.
27
+ - `deploy`: Bygger ihop, signerar och laddar upp appen till default miljön eller den miljö som anges i `--env` argumentet.
28
+
29
+ ## [1.10.0] - 2023-11-21
30
+
31
+ - Hantera exporter av `.svelte` filer bättre i `@rollup/plugin-node-resolve`
32
+ - Lägg till ytterliggare replace i `@rollup/plugin-replace` för att ta reda på om koden körs på servern eller i webbläsaren.
33
+
34
+ ## [1.9.0] - 2023-09-20
35
+
36
+ - Skriv ut information om nuvarande miljö om skriptet startas självstående.
37
+ - Starta en watcher på förändringar i gits checksum om skriptet startas självstående.
38
+ - Modernare default på babel-env.
39
+
40
+ ## [1.8.2] - 2023-07-06
41
+
42
+ - Lägg till ytterligare introkod för servern som i vissa fall behövs för Svelte 4.
43
+
44
+ ## [1.8.1] - 2023-06-28
45
+
46
+ - Uppdatera `rollup-plugin-svelte` för att slippa varning kring css.
47
+
48
+ ## [1.8.0] - 2023-06-26
49
+
50
+ - Stöd för Svelte 4.
51
+ - Lägsta version av Node som stödjs är nu 16.
52
+
53
+ ## [1.7.1] - 2023-06-12
54
+
55
+ - Justera sökväg för `node_modules` så det fungerar på Mac.
56
+
57
+ ## [1.7.0] - 2023-06-02
58
+
59
+ - Lägg till appens `node_modules` när dependencies resolvas.
60
+
61
+ ## [1.6.1] - 2023-03-21
62
+
63
+ - Hantera CSS-filer genererade av klientsidekoden för WebApps 1.
64
+
65
+ ## [1.6.0] - 2023-02-28
66
+
67
+ - Justera hantering av CSS för att minska risken för duplicerade media queries.
68
+ - Dämpa varning vid import av `@sitevision/api/common/events` då det inte är Node API:et som importeras.
69
+
70
+ ## [1.5.0] - 2023-01-11
71
+
72
+ - Stöd för att importera SVG-filer som text.
73
+ - Uppdatera Rollup till version 3.
74
+
75
+ ## [1.4.2] - 2022-08-26
76
+
77
+ - Uppdatera dependencies.
78
+
79
+ ## [1.4.1] - 2022-04-19
80
+
81
+ - Uppdatera dependencies.
82
+
83
+ ## [1.4.0] - 2022-04-06
84
+
85
+ - Stöd för flerspråkiga namn på en app i `manifest.json`.
86
+
87
+ ## [1.3.1] - 2022-03-25
88
+
89
+ - Acceptera även argumentet `--build` för att starta bygge tillsammans med `--watch`.
90
+
91
+ ## [1.3.0] - 2022-03-17
92
+
93
+ - Läs även in `compilerOptions` från `svelte.config.js`.
94
+ - Kopiera bara `.json` filer från `./src/i18n`.
95
+
96
+ ## [1.2.2] - 2022-03-11
97
+
98
+ - Skicka med `args.debug` till config tasks.
99
+
100
+ ## [1.2.1] - 2022-03-03
101
+
102
+ - Slå av `errorOnUnmatchedPattern` för ESLint.
103
+ - Nytt uppstartsmeddelande.
104
+
105
+ ## [1.2.0] - 2022-03-01
106
+
107
+ - Byt ut `rollup-plugin-filesize` mot en egen version för att bli av deprecation meddelanden.
108
+ - Ta bort banner även vid debug då det är onödig information.
109
+
110
+ ## [1.1.0] - 2022-02-16
111
+
112
+ - Använd närmsta `svelte.config.js` för preprocessing options.
113
+
114
+ ## [1.0.2] - 2022-02-09
115
+
116
+ - Ta bort `sass` som felaktigt ligger med som dependency.
117
+
118
+ ## [1.0.1] - 2022-02-08
119
+
120
+ - Se till att det går att bygga ihop WebApps 1 app utan `index.js`.
121
+
122
+ ## [1.0.0] - 2022-02-08
123
+
124
+ Första release.
package/config/index.js CHANGED
@@ -3,25 +3,23 @@ import copy from '../utils/copy.js';
3
3
  import configFiles from '../utils/configFiles.js';
4
4
 
5
5
  export default function config({ src, dest, cache, debug }) {
6
- if (src) {
7
- return [
8
- copy({ src: [`${src}/index.html`, `${src}/config.css`], dest, deep: false }),
9
- server({
10
- input: `${src}/index.js`,
11
- output: `${dest}/index.js`,
12
- debug,
13
- }),
14
- client({
15
- input: `${src}/config.js`,
16
- output: `${dest}/config.js`,
17
- globals: { jquery: 'jQuery' },
18
- showSize: false,
19
- hydratable: false,
20
- cache,
21
- debug,
22
- }),
23
- configFiles({ dest }),
24
- ];
25
- }
26
- return undefined;
6
+ return [
7
+ copy({ src: [`${src}/index.html`, `${src}/config.css`], dest, deep: false }),
8
+ server({
9
+ input: `${src}/index.js`,
10
+ output: `${dest}/index.js`,
11
+ debug,
12
+ }),
13
+ client({
14
+ input: `${src}/config.js`,
15
+ output: `${dest}/config.js`,
16
+ globals: { jquery: 'jQuery' },
17
+ showSize: false,
18
+ hydratable: false,
19
+ cache,
20
+ debug,
21
+ format: 'iife',
22
+ }),
23
+ configFiles({ dest }),
24
+ ];
27
25
  }
package/index.js CHANGED
@@ -1,86 +1,94 @@
1
+ import fse from 'fs-extra';
1
2
  import args from '@soleil-se/build-utils/args';
2
3
  import runTasks from '@soleil-se/build-utils/runTasks';
3
4
  import task from '@soleil-se/build-utils/task';
4
5
  import watch from '@soleil-se/build-utils/watch';
5
6
  import { logError, logStartup, logEnviroment, logTimestamp } from '@soleil-se/build-utils/log';
6
7
  import createChecksumChecker from '@soleil-se/build-utils/createChecksumChecker';
8
+ import { env, rollup } from '@soleil-se/build-config';
7
9
 
8
- import {
9
- input, manifest, addonName, env, rollup, watchPaths, eslintPaths,
10
- } from './config.js';
11
-
10
+ import { readManifest } from './manifest.js';
12
11
  import { clean, copy, files, zip, eslint } from './utils/index.js';
13
12
  import { client, server } from './rollup/index.js';
14
13
  import { activate, upload, sign } from './requests/index.js';
15
14
  import config from './config/index.js';
16
15
 
17
- const zipPath = `./dist/${manifest.id}-${manifest.version}.zip`;
18
-
19
16
  async function main() {
20
- logTimestamp(`${addonName} (${manifest.id})`);
17
+ const manifest = await readManifest();
18
+ const zipPath = `./dist/${manifest.id}-${manifest.version}.zip`;
19
+
20
+ logTimestamp(`${manifest.name} (${manifest.id})`);
21
21
  logStartup(import.meta.url);
22
+ if (!manifest.bundled) {
23
+ logError('WebApps 1 is no longer supported. To use WebApps 2 set bundled to true in manifest.json.');
24
+ process.exit(1);
25
+ }
22
26
  if (!args.project && args.sync && env) {
23
27
  logEnviroment(env);
24
28
  }
25
29
  const tasks = [
26
30
  task('clean', clean({ dir: './dist' })),
27
- args.eslint && task('eslint', eslint({ src: eslintPaths })),
31
+ args.eslint && task('eslint', eslint({ src: ['./**/*.{js,svelte}'] })),
28
32
  task('copy', [
29
33
  copy({ src: './manifest.json', dest: './dist/src' }),
30
- copy(manifest.bundled || (input.server || '').startsWith('./src')
31
- ? { src: ['./src/manifest.json', './src/appDataDefaults.json', './src/i18n/*.json', './src/config', './src/resource'], dest: './dist' }
32
- : { src: ['./src'], dest: './dist' }),
34
+ copy({ src: ['./src/manifest.json', './src/appDataDefaults.json', './src/i18n/*.json', './src/config', './src/resource'], dest: './dist' }),
33
35
  ]),
34
36
  task('server', server({
35
- input: input.server,
37
+ input: './src/index.js',
36
38
  output: './dist/src/index.js',
37
39
  debug: args.debug,
38
- bundled: manifest.bundled,
39
40
  cache: args.cache,
40
41
  extractCss: true,
41
- })),
42
+ }), () => fse.existsSync('./src/index.js')),
42
43
  task('client', client({
43
- input: input.client,
44
- output: manifest.bundled ? './dist/src/main.js' : './dist/src/resource/client/index.js',
45
- bundled: manifest.bundled,
44
+ input: './src/main.js',
45
+ output: './dist/src/main.js',
46
46
  globals: rollup?.client?.globals,
47
47
  debug: args.debug,
48
48
  cache: args.cache,
49
49
  extractCss: true,
50
- })),
50
+ }), () => fse.existsSync('./src/main.js')),
51
51
  task('hooks', server({
52
- input: input.hooks,
52
+ input: './src/hooks.js',
53
53
  output: './dist/src/hooks.js',
54
- bundled: manifest.bundled,
55
54
  debug: args.debug,
56
55
  cache: args.cache,
57
56
  extractCss: true,
58
- })),
59
- task('config', config({ src: input.config, dest: './dist/src/config', cache: args.cache, debug: args.debug })),
60
- task('globalConfig', config({ src: input.globalConfig, dest: './dist/src/config/global', cache: args.cache })),
57
+ }), () => fse.existsSync('./src/hooks.js')),
58
+ task('config', config({
59
+ src: './config',
60
+ dest: './dist/src/config',
61
+ cache: args.cache,
62
+ debug: args.debug,
63
+ }), () => fse.existsSync('./config')),
64
+ task('globalConfig', config({
65
+ src: './config_global',
66
+ dest: './dist/src/config/global',
67
+ cache: args.cache,
68
+ }), () => fse.existsSync('./config_global')),
61
69
  task('files', files({ manifest, dest: './dist' })),
62
70
  task('zip', zip({ src: './dist/src', dest: zipPath })),
63
71
  ];
64
72
 
65
73
  if (args.sign ?? env?.sign ?? env?.production) {
66
- tasks.push(task('sign', sign({ src: zipPath, addonName, manifest })));
74
+ tasks.push(task('sign', sign({ src: zipPath })));
67
75
  }
68
76
 
69
77
  if (args.sync) {
70
78
  tasks.push(task('upload', upload({
71
79
  src: zipPath,
72
- addonName,
73
- manifest,
74
80
  force: args.force || !env?.production,
75
81
  })));
76
82
 
77
- if (args.sync && args.activate) {
78
- tasks.push(task('activate', activate(addonName)));
83
+ if (args.activate) {
84
+ tasks.push(task('activate', activate()));
79
85
  }
80
86
  }
81
87
 
82
88
  if (args.watch) {
83
- watch(watchPaths, () => runTasks(tasks));
89
+ watch('./**/*', () => runTasks(tasks), {
90
+ ignored: ['./dist/**/*', './node_modules/**/*', './*.md', './.*', 'package-lock.json', 'yarn.lock', './*config*.*'],
91
+ });
84
92
  if (!args.project) createChecksumChecker();
85
93
  } else {
86
94
  await runTasks(tasks);
package/manifest.js ADDED
@@ -0,0 +1,19 @@
1
+ import fse from 'fs-extra';
2
+ import config from '@soleil-se/build-config';
3
+
4
+ import isObject from './api/isObject.js';
5
+
6
+ export function getAddonName(manifest) {
7
+ return isObject(manifest.name) ? manifest.name[config.addonNameLang || 'sv'] : manifest.name;
8
+ }
9
+
10
+ export async function readManifest() {
11
+ let manifest = {};
12
+ if (fse.existsSync('./manifest.json')) {
13
+ manifest = await fse.readJson('./manifest.json');
14
+ } else if (fse.existsSync('./src/manifest.json')) {
15
+ manifest = await fse.readJson('./src/manifest.json');
16
+ }
17
+ manifest.name = getAddonName(manifest);
18
+ return manifest;
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soleil-se/build-app",
3
- "version": "1.12.0",
3
+ "version": "2.0.0",
4
4
  "bin": {
5
5
  "build-app": "./bin/index.js",
6
6
  "sv-app-build": "./bin/index.js"
@@ -10,47 +10,46 @@
10
10
  "license": "UNLICENSED",
11
11
  "type": "module",
12
12
  "engines": {
13
- "node": ">=16.0.0"
13
+ "node": ">=20.0.0"
14
14
  },
15
15
  "homepage": "https://docs.soleil.se/build/app",
16
16
  "dependencies": {
17
- "@babel/core": "7.23.6",
18
- "@babel/preset-env": "7.23.6",
19
- "@rollup/plugin-alias": "5.1.0",
17
+ "@babel/core": "7.25.8",
18
+ "@babel/preset-env": "7.25.8",
19
+ "@rollup/plugin-alias": "5.1.1",
20
20
  "@rollup/plugin-babel": "6.0.4",
21
- "@rollup/plugin-commonjs": "25.0.7",
21
+ "@rollup/plugin-commonjs": "28.0.1",
22
22
  "@rollup/plugin-json": "6.1.0",
23
- "@rollup/plugin-node-resolve": "15.2.3",
24
- "@rollup/plugin-replace": "5.0.5",
23
+ "@rollup/plugin-node-resolve": "15.3.0",
24
+ "@rollup/plugin-replace": "6.0.1",
25
25
  "@rollup/plugin-terser": "0.4.4",
26
- "archiver": "6.0.1",
27
- "autoprefixer": "10.4.16",
26
+ "archiver": "7.0.1",
27
+ "autoprefixer": "10.4.20",
28
28
  "babel-plugin-transform-async-to-promises": "0.8.18",
29
29
  "chalk": "5.3.0",
30
- "find-up": "6.3.0",
31
- "form-data": "4.0.0",
30
+ "find-up": "7.0.0",
31
+ "form-data": "4.0.1",
32
32
  "fs-extra": "11.2.0",
33
- "glob": "^10.3.10",
34
- "got": "13.0.0",
33
+ "glob": "^11.0.0",
34
+ "got": "14.4.3",
35
35
  "gzip-size": "7.0.0",
36
36
  "lodash-es": "4.17.21",
37
37
  "minimist": "^1.2.8",
38
- "postcss": "8.4.32",
39
- "postcss-pxtorem": "6.0.0",
38
+ "postcss": "8.4.47",
39
+ "postcss-pxtorem": "6.1.0",
40
40
  "pretty-bytes": "6.1.1",
41
- "prompts": "^2.4.2",
42
- "rollup": "3.29.4",
43
- "rollup-plugin-cleanup": "3.2.1",
41
+ "prompts": "2.4.2",
42
+ "rollup": "4.24.0",
44
43
  "rollup-plugin-postcss": "4.0.2",
45
44
  "rollup-plugin-string": "3.0.0",
46
- "rollup-plugin-svelte": "7.1.6",
45
+ "rollup-plugin-svelte": "7.2.2",
47
46
  "slash": "5.1.0",
48
- "svelte-preprocess": "5.1.3",
49
- "@soleil-se/build-config": "1.2.0",
50
- "@soleil-se/build-utils": "1.6.0"
47
+ "svelte-preprocess": "6.0.3",
48
+ "@soleil-se/build-config": "1.3.0",
49
+ "@soleil-se/build-utils": "1.7.0"
51
50
  },
52
51
  "devDependencies": {
53
- "svelte": "4.2.8"
52
+ "svelte": "5.0.2"
54
53
  },
55
54
  "scripts": {},
56
55
  "description": "Script for building WebApps, RESTApps and Widgets with Svelte in Sitevision.",
@@ -1,25 +1,11 @@
1
1
  import chalk from 'chalk';
2
- import fse from 'fs-extra';
3
2
 
4
3
  import { logSuccess } from '@soleil-se/build-utils/log';
5
4
 
5
+ import { readManifest } from '../manifest.js';
6
6
  import addonRequest from './api/addonRequest.js';
7
7
  import handleError from './api/handleError.js';
8
8
 
9
- function readManifestFile() {
10
- try {
11
- if (fse.existsSync('./manifest.json')) {
12
- return fse.readJsonSync('./manifest.json');
13
- }
14
- if (fse.existsSync('./src/manifest.json')) {
15
- return fse.readJsonSync('./src/manifest.json');
16
- }
17
- throw new Error('Could not find manifest.json...');
18
- } catch (e) {
19
- throw new Error('Unable to parse manifest.json...');
20
- }
21
- }
22
-
23
9
  function getPropertiesUri(type, id, version) {
24
10
  switch (type.toLowerCase()) {
25
11
  case 'webapp':
@@ -32,10 +18,9 @@ function getPropertiesUri(type, id, version) {
32
18
  }
33
19
  }
34
20
 
35
- export default async function activateAddon(addonName) {
21
+ export default async function activateAddon(name) {
36
22
  try {
37
- const manifest = readManifestFile();
38
- const { id, version, type } = manifest;
23
+ const { id, version, type } = await readManifest();
39
24
 
40
25
  const { 'jcr:uuid': customModuleExecutableId } = await addonRequest({
41
26
  url: getPropertiesUri(type, id, version),
@@ -43,12 +28,12 @@ export default async function activateAddon(addonName) {
43
28
  });
44
29
 
45
30
  await addonRequest({
46
- url: `Addon%20Repository/${encodeURIComponent(addonName)}/activatecustommoduleexecutable`,
31
+ url: `Addon%20Repository/${encodeURIComponent(name)}/activatecustommoduleexecutable`,
47
32
  method: 'PUT',
48
33
  searchParams: { customModuleExecutableId },
49
34
  });
50
35
 
51
- logSuccess(`${type} ${chalk.white(`${addonName} (${id}@${version})`)} activated successfully!`);
36
+ logSuccess(`${type} ${chalk.white(`${name} (${id}@${version})`)} activated successfully!`);
52
37
  } catch (error) {
53
38
  handleError(error);
54
39
  }
@@ -1,12 +1,12 @@
1
1
  import handleError from './api/handleError.js';
2
2
  import addonRequest from './api/addonRequest.js';
3
3
 
4
- export default async function addonExists(addonName) {
4
+ export default async function addonExists(name) {
5
5
  try {
6
6
  const addons = await addonRequest('Addon%20Repository/nodes', {
7
7
  method: 'GET',
8
8
  });
9
- return !!addons.find((addon) => addon.name === addonName);
9
+ return !!addons.find((addon) => addon.name === name);
10
10
  } catch (error) {
11
11
  return handleError(error);
12
12
  }
@@ -1,3 +1,4 @@
1
+ // eslint-disable-next-line import/no-unresolved
1
2
  import got from 'got';
2
3
  import config from '@soleil-se/build-config';
3
4
 
@@ -16,13 +16,13 @@ function getCreateUri(type) {
16
16
  }
17
17
  }
18
18
 
19
- export default async function createAddon({ addonName, manifest }) {
19
+ export default async function createAddon(manifest) {
20
20
  try {
21
21
  await addonRequest({
22
22
  url: getCreateUri(manifest.type),
23
- searchParams: { name: addonName, category: manifest.category || 'Other' },
23
+ searchParams: { name: manifest.name, category: manifest.category || 'Other' },
24
24
  });
25
- logSuccess(`${manifest.type} ${chalk.white(`${addonName} (${manifest.id})`)} created successfully!`);
25
+ logSuccess(`${manifest.type} ${chalk.white(`${manifest.name} (${manifest.id})`)} created successfully!`);
26
26
  } catch (error) {
27
27
  handleError(error);
28
28
  }
package/requests/index.js CHANGED
@@ -3,26 +3,27 @@ import createAddon from './createAddon.js';
3
3
  import uploadAddon from './uploadAddon.js';
4
4
  import activateAddon from './activateAddon.js';
5
5
  import signAddon from './signAddon.js';
6
+ import { readManifest } from '../manifest.js';
6
7
 
7
- export function upload({ src, addonName, manifest, force }) {
8
+ export function upload({ src, force }) {
8
9
  return async () => {
9
- let checkIfExists = true;
10
- if (checkIfExists) {
11
- const exists = await addonExists(addonName);
12
- if (!exists) {
13
- await createAddon({ addonName, manifest });
14
- }
15
- checkIfExists = false;
16
- }
17
-
18
- return uploadAddon({ src, addonName, manifest, force });
10
+ const manifest = await readManifest();
11
+ const exists = await addonExists(manifest.name);
12
+ if (!exists) await createAddon(manifest);
13
+ return uploadAddon({ src, manifest, force });
19
14
  };
20
15
  }
21
16
 
22
- export function activate(addonName) {
23
- return () => activateAddon(addonName);
17
+ export function activate() {
18
+ return async () => {
19
+ const manifest = await readManifest();
20
+ return activateAddon(manifest.name);
21
+ };
24
22
  }
25
23
 
26
- export function sign({ src, addonName, manifest }) {
27
- return () => signAddon({ src, addonName, manifest });
24
+ export function sign({ src }) {
25
+ return async () => {
26
+ const manifest = await readManifest();
27
+ return signAddon({ src, manifest });
28
+ };
28
29
  }
@@ -2,6 +2,7 @@ import { basename } from 'path';
2
2
  import fse from 'fs-extra';
3
3
  import chalk from 'chalk';
4
4
  import prompts from 'prompts';
5
+ // eslint-disable-next-line import/no-unresolved
5
6
  import got from 'got';
6
7
  import FormData from 'form-data';
7
8
  import { logSuccess } from '@soleil-se/build-utils/log';
@@ -51,14 +52,14 @@ async function signRequest(path) {
51
52
  }).buffer();
52
53
  }
53
54
 
54
- export default async function signAddon({ src, addonName, manifest }) {
55
+ export default async function signAddon({ src, manifest }) {
55
56
  try {
56
57
  if (!fse.existsSync(src)) throw new Error(`Could not find ${src}`);
57
58
 
58
59
  const response = await signRequest(src);
59
60
  await fse.writeFile(src, response);
60
61
 
61
- logSuccess(`${manifest.type} ${chalk.white(`${addonName} (${manifest.id})`)} signed successfully!`);
62
+ logSuccess(`${manifest.type} ${chalk.white(`${manifest.name} (${manifest.id})`)} signed successfully!`);
62
63
  } catch (error) {
63
64
  handleError(error);
64
65
  }
@@ -18,7 +18,7 @@ function getUploadUri(type, name) {
18
18
  }
19
19
  }
20
20
 
21
- export default async function uploadAddon({ src, addonName, manifest, force }) {
21
+ export default async function uploadAddon({ src, manifest, force }) {
22
22
  try {
23
23
  if (!fse.existsSync(src)) {
24
24
  throw new Error(`Could not find ${src}`);
@@ -26,11 +26,11 @@ export default async function uploadAddon({ src, addonName, manifest, force }) {
26
26
  const form = new FormData();
27
27
  form.append('file', fse.createReadStream(src));
28
28
 
29
- await addonRequest(getUploadUri(manifest.type, addonName), {
29
+ await addonRequest(getUploadUri(manifest.type, manifest.name), {
30
30
  searchParams: { force },
31
31
  body: form,
32
32
  });
33
- logSuccess(`${manifest.type} ${chalk.white(`${addonName} (${manifest.id})`)} uploaded successfully!`);
33
+ logSuccess(`${manifest.type} ${chalk.white(`${manifest.name} (${manifest.id})`)} uploaded successfully!`);
34
34
  } catch (error) {
35
35
  handleError(error);
36
36
  }
@@ -8,24 +8,15 @@ const resolveAlias = (root, aliases = {}) => Object.entries(aliases)
8
8
  [key]: path.resolve(root, value),
9
9
  }), {});
10
10
 
11
- const clientAlias = config?.projectRoot ? resolveAlias(config.projectRoot, {
12
- '#api/webapps': './server_src/webapps/api',
13
- '#api': './server_src/api',
14
- '#components': './server_src/webapps/components',
15
- ...config?.rollup?.client?.alias,
16
- }) : {};
11
+ const clientAlias = config?.projectRoot
12
+ ? resolveAlias(config.projectRoot, config?.rollup?.client?.alias) : {};
17
13
 
18
14
  export function getAliasClientPlugin() {
19
15
  return alias({ entries: clientAlias });
20
16
  }
21
17
 
22
- const serverAlias = config?.projectRoot ? resolveAlias(config.projectRoot, {
23
- '#api/webapps': './server_src/webapps/api',
24
- '#api/restapps': './server_src/restapps/api',
25
- '#api': './server_src/api',
26
- '#components': './server_src/webapps/components',
27
- ...config?.rollup?.server?.alias,
28
- }) : {};
18
+ const serverAlias = config?.projectRoot
19
+ ? resolveAlias(config.projectRoot, config?.rollup?.server?.alias) : {};
29
20
 
30
21
  export function getAliasServerPlugin() {
31
22
  return alias({ entries: serverAlias });
@@ -2,9 +2,8 @@ import { babel } from '@rollup/plugin-babel';
2
2
 
3
3
  const commonOptions = {
4
4
  babelrc: false,
5
- extensions: ['.js', '.mjs', '.html', '.svelte'],
5
+ extensions: ['.js', '.mjs', '.html', '.svelte', '.cjs'],
6
6
  babelHelpers: 'bundled',
7
- plugins: ['babel-plugin-transform-async-to-promises'],
8
7
  };
9
8
 
10
9
  export function getBabelClientPlugin() {
@@ -29,6 +28,7 @@ export function getBabelClientPlugin() {
29
28
  export function getBabelServerPlugin() {
30
29
  return babel({
31
30
  ...commonOptions,
31
+ plugins: ['babel-plugin-transform-async-to-promises'],
32
32
  presets: [
33
33
  ['@babel/preset-env', {
34
34
  exclude: ['@babel/plugin-transform-arrow-functions'],
@@ -2,6 +2,7 @@ import { dirname } from 'path';
2
2
  import { findUpSync } from 'find-up';
3
3
  import fse from 'fs-extra';
4
4
  import { kebabCase } from 'lodash-es';
5
+ import { createRequire } from 'module';
5
6
 
6
7
  import preprocessOptions from './common/preprocessOptions.js';
7
8
 
@@ -30,6 +31,13 @@ async function getPreprocess(svelteConfig) {
30
31
  return sveltePreprocess(preprocessOptions);
31
32
  }
32
33
 
34
+ function isLegacy() {
35
+ const require = createRequire(import.meta.url);
36
+ // eslint-disable-next-line import/no-extraneous-dependencies
37
+ const { version } = require('svelte/package.json');
38
+ return version.startsWith('3') || version.startsWith('4');
39
+ }
40
+
33
41
  export default async function getSveltePlugin({
34
42
  input, debug = false, extractCss = true, ssr, hydratable = true,
35
43
  }) {
@@ -41,12 +49,16 @@ export default async function getSveltePlugin({
41
49
  preprocess: await getPreprocess(svelteConfig),
42
50
  emitCss: extractCss,
43
51
  compilerOptions: {
52
+ css: !extractCss ? 'injected' : undefined,
44
53
  ...svelteConfig.compilerOptions,
45
- generate: ssr ? 'ssr' : 'dom',
46
- hydratable,
54
+ generate: ssr ? 'server' : 'client',
47
55
  dev: debug,
48
- enableSourcemap: debug,
49
56
  cssHash,
57
+ ...(isLegacy() ? {
58
+ enableSourcemap: debug,
59
+ hydratable,
60
+ generate: ssr ? 'ssr' : 'dom',
61
+ } : {}),
50
62
  },
51
63
  });
52
64
  }
package/rollup/client.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { rollup } from 'rollup';
2
2
  import json from '@rollup/plugin-json';
3
-
4
3
  import fse from 'fs-extra';
5
4
 
6
5
  import onwarn from './utils/onwarn.js';
@@ -16,7 +15,7 @@ import getPostcssPlugin from './api/getPostcssPlugin.js';
16
15
  import getTerserPlugin from './api/getTerserPlugin.js';
17
16
  import getStringPlugin from './api/getStringPlugin.js';
18
17
 
19
- import sitevisionPlugin from './plugins/sitevisionClient.js';
18
+ import sitevisionPlugin from './plugins/sitevision.js';
20
19
  import bundleSizePlugin from './plugins/bundleSize.js';
21
20
  import amdGlobalsPlugin from './plugins/amdGlobals.js';
22
21
 
@@ -27,23 +26,19 @@ export default function rollupClient({
27
26
  output,
28
27
  extractCss = false,
29
28
  showSize = true,
30
- bundled,
31
29
  hydratable,
32
30
  cache = true,
31
+ format = 'amd',
33
32
  } = {}) {
34
- if (!input) return false;
35
-
36
33
  let bundleCache;
37
34
  let plugins;
38
35
 
39
- const external = bundled ? getSitevisionClientPackages() : Object.keys(globals);
40
-
41
36
  return async () => {
42
37
  if (!fse.existsSync(input)) return Promise.resolve();
43
38
 
44
39
  plugins = plugins || [
45
- bundled ? sitevisionPlugin() : false,
46
- bundled ? amdGlobalsPlugin({ globals }) : false,
40
+ format === 'amd' && amdGlobalsPlugin({ globals }),
41
+ sitevisionPlugin({ context: 'client' }),
47
42
  getReplaceClientPlugin(),
48
43
  getAliasClientPlugin(),
49
44
  getNodeResolvePlugin({ input }),
@@ -59,7 +54,7 @@ export default function rollupClient({
59
54
 
60
55
  try {
61
56
  const bundle = await rollup({
62
- external,
57
+ external: getSitevisionClientPackages(),
63
58
  input,
64
59
  plugins,
65
60
  onwarn,
@@ -68,9 +63,13 @@ export default function rollupClient({
68
63
 
69
64
  bundleCache = cache && bundle.cache;
70
65
  return bundle.write({
66
+ // name: format === 'amd' ? 'app' : undefined,
67
+ // banner: format === 'amd' ? 'define(function (require) {' : undefined,
68
+ // footer: format === 'amd' ? 'return app; });' : undefined,
69
+ // format: 'iife',
70
+ format,
71
71
  file: output,
72
72
  globals,
73
- format: bundled ? 'amd' : 'iife',
74
73
  sourcemap: debug ? 'inline' : false,
75
74
  interop: 'auto',
76
75
  });
@@ -1,4 +1,4 @@
1
- export default function sitevisionClient() {
1
+ export default function sitevision({ context } = {}) {
2
2
  const ignored = [];
3
3
 
4
4
  function isSitevisionScope(id) {
@@ -16,14 +16,23 @@ export default function sitevisionClient() {
16
16
  return !ignored.includes(id);
17
17
  }
18
18
 
19
+ function getVirtualModule(pkg) {
20
+ if (context === 'server') {
21
+ return `var ${pkg} = require('${pkg}');\nexport default ${pkg};`;
22
+ } if (context === 'client') {
23
+ return `export { default } from '${pkg}';`;
24
+ }
25
+ throw new Error('Invalid context, must be either "server" or "client".');
26
+ }
27
+
19
28
  return {
20
- name: 'rollup-plugin-sitevision-client',
29
+ name: 'rollup-plugin-sitevision',
21
30
  resolveId(importee) {
22
31
  if (shouldResolve(importee)) {
23
32
  // Should be handled as usual.
24
33
  return null;
25
34
  }
26
- // Most likely a SiteVision dependency.
35
+ // Most likely a Sitevision dependency.
27
36
  // Do not ask other plugins or check the file system to find it.
28
37
  if (!ignored.includes(importee)) {
29
38
  ignored.push(importee);
@@ -37,7 +46,7 @@ export default function sitevisionClient() {
37
46
  // The virtual source code for the provided Sitevision dependency.
38
47
  const pkg = id.split('/').pop();
39
48
  return {
40
- code: `export { default } from '${pkg}';`,
49
+ code: getVirtualModule(pkg),
41
50
  syntheticNamedExports: true,
42
51
  };
43
52
  },
package/rollup/server.js CHANGED
@@ -1,7 +1,5 @@
1
1
  import { rollup } from 'rollup';
2
2
  import json from '@rollup/plugin-json';
3
- import cleanup from 'rollup-plugin-cleanup';
4
-
5
3
  import fse from 'fs-extra';
6
4
 
7
5
  import onwarn from './utils/onwarn.js';
@@ -16,18 +14,15 @@ import getPostcssPlugin from './api/getPostcssPlugin.js';
16
14
  import getTerserPlugin from './api/getTerserPlugin.js';
17
15
  import getStringPlugin from './api/getStringPlugin.js';
18
16
 
19
- import sitevision from './plugins/sitevisionServer.js';
17
+ import sitevision from './plugins/sitevision.js';
20
18
 
21
19
  export default function rollupServer({
22
20
  debug,
23
21
  input,
24
22
  output,
25
23
  extractCss = false,
26
- bundled,
27
24
  cache = true,
28
25
  } = {}) {
29
- if (!input) return false;
30
-
31
26
  let bundleCache;
32
27
  let plugins;
33
28
 
@@ -37,7 +32,7 @@ export default function rollupServer({
37
32
  plugins = plugins || [
38
33
  getReplaceServerPlugin(),
39
34
  getAliasServerPlugin(),
40
- sitevision(),
35
+ sitevision({ context: 'server' }),
41
36
  json(),
42
37
  getStringPlugin(),
43
38
  getNodeResolvePlugin({ input }),
@@ -45,7 +40,7 @@ export default function rollupServer({
45
40
  await getSveltePlugin({ input, extractCss, ssr: true }),
46
41
  getPostcssPlugin({ extractCss, debug }),
47
42
  getBabelServerPlugin(),
48
- bundled ? getTerserPlugin({ debug }) : cleanup({ maxEmptyLines: 1 }),
43
+ getTerserPlugin({ debug }),
49
44
  ];
50
45
 
51
46
  try {
package/utils/files.js CHANGED
@@ -31,12 +31,12 @@ async function moveFileIfExists(src, dest) {
31
31
  return fse.move(src, dest, { overwrite: true });
32
32
  }
33
33
 
34
- async function manageCss({ type, bundled, dest }) {
34
+ async function manageCss({ type, dest }) {
35
35
  const serverOutput = `${dest}/src/index.css`;
36
- const clientOutput = bundled ? `${dest}/src/main.css` : `${dest}/src/resource/client/index.css`;
36
+ const clientOutput = `${dest}/src/main.css`;
37
37
  const hooksOutput = `${dest}/src/hooks.css`;
38
38
 
39
- const cssDest = ['webapp', 'widget'].includes(type.toLowerCase()) ? `${dest}/src/css` : `${dest}/src/resource/client`;
39
+ const cssDest = ['webapp', 'widget'].includes(type) ? `${dest}/src/css` : `${dest}/src/resource/client`;
40
40
 
41
41
  if (await hasSameContent(serverOutput, clientOutput)) {
42
42
  await fse.remove(serverOutput);
@@ -50,9 +50,9 @@ async function manageCss({ type, bundled, dest }) {
50
50
  }
51
51
 
52
52
  export default function files({ manifest, dest }) {
53
- const { type, bundled } = manifest;
54
- if (type.toLowerCase() === 'restapp') return manageCss({ type, bundled, dest });
53
+ const type = manifest.type.toLowerCase();
54
+ if (type === 'restapp') return manageCss({ type, dest });
55
55
  return () => Promise.all(
56
- [createMain(dest), createIndex(dest), manageCss({ type, bundled, dest })],
56
+ [createMain(dest), createIndex(dest), manageCss({ type, dest })],
57
57
  );
58
58
  }
package/config.js DELETED
@@ -1,70 +0,0 @@
1
- import config from '@soleil-se/build-config';
2
- import fse from 'fs-extra';
3
- import { dirname } from 'path';
4
-
5
- import isObject from './api/isObject.js';
6
-
7
- function readManifestFile() {
8
- if (fse.existsSync('./manifest.json')) return fse.readJsonSync('./manifest.json');
9
- if (fse.existsSync('./src/manifest.json')) return fse.readJsonSync('./src/manifest.json');
10
- return {};
11
- }
12
-
13
- function getAddonName(manifest, addonNameLang = 'sv') {
14
- return isObject(manifest.name) ? manifest.name[addonNameLang] : manifest.name;
15
- }
16
-
17
- function getClientInput() {
18
- if (fse.existsSync('./src/main.js')) return './src/main.js';
19
- if (fse.existsSync('./app_src/main.js')) return './app_src/main.js';
20
- return false;
21
- }
22
-
23
- function getServerInput() {
24
- if (fse.existsSync('./src/index.js')) return './src/index.js';
25
- if (fse.existsSync('./app_src/index.js')) return './app_src/index.js';
26
- return false;
27
- }
28
-
29
- function getHooksInput() {
30
- if (fse.existsSync('./src/hooks.js')) return './src/hooks.js';
31
- if (fse.existsSync('./app_src/hooks.js')) return './app_src/hooks.js';
32
- return false;
33
- }
34
-
35
- function getConfigInput() {
36
- if (fse.existsSync('./config')) return './config';
37
- if (fse.existsSync('./app_config')) return './app_config';
38
- return false;
39
- }
40
-
41
- function getGlobalConfigInput() {
42
- if (fse.existsSync('./config_global')) return './config_global';
43
- if (fse.existsSync('./app_config_global')) return './app_config_global';
44
- return false;
45
- }
46
-
47
- export const { env, projectRoot, rollup, addonNameLang } = config;
48
- export const manifest = readManifestFile();
49
- export const addonName = getAddonName(manifest, addonNameLang);
50
- export const type = manifest.type.toLowerCase();
51
- export const input = {
52
- client: getClientInput(),
53
- server: getServerInput(),
54
- hooks: getHooksInput(),
55
- config: getConfigInput(),
56
- globalConfig: getGlobalConfigInput(),
57
- };
58
-
59
- const folders = [
60
- input.client && dirname(input.client),
61
- input.server && dirname(input.server),
62
- input.hooks && dirname(input.hooks),
63
- input.config,
64
- input.globalConfig,
65
- ]
66
- .filter((folder) => !!folder)
67
- .filter((v, i, arr) => arr.indexOf(v) === i);
68
-
69
- export const watchPaths = folders.map((folder) => `${folder}/**/*`).concat('./manifest.json');
70
- export const eslintPaths = folders.map((folder) => `${folder}/**/*.{js,svelte}`);
@@ -1,81 +0,0 @@
1
- import { camelCase } from 'lodash-es';
2
- import { isAbsolute } from 'path';
3
-
4
- const sitevisionPackages = [
5
- 'underscore',
6
- 'router',
7
- 'i18n',
8
- 'appData',
9
- 'globalAppData',
10
- 'appResource',
11
- 'appInfo',
12
- 'storage',
13
- 'oauth2',
14
- 'privileged',
15
- 'app',
16
- 'events',
17
- 'hooks',
18
- 'cache',
19
- ];
20
-
21
- export default function sitevisionServer() {
22
- const ignored = [];
23
-
24
- function startsWithUpperCase(id) {
25
- return /^[A-Z]/.test(id);
26
- }
27
-
28
- function isSitevisionPath(id) {
29
- if (isAbsolute(id) && !id.startsWith('/')) {
30
- return false;
31
- }
32
- return startsWithUpperCase(id);
33
- }
34
-
35
- function isExcluded(id) {
36
- return sitevisionPackages.includes(id);
37
- }
38
-
39
- function isSitevisionScope(id) {
40
- return id.startsWith('@sitevision/api');
41
- }
42
-
43
- function shouldResolve(importee) {
44
- if (isSitevisionScope(importee) || isExcluded(importee) || isSitevisionPath(importee)) {
45
- return false;
46
- }
47
- return true;
48
- }
49
-
50
- function shouldLoad(id) {
51
- return !ignored.includes(id);
52
- }
53
-
54
- return {
55
- name: 'rollup-plugin-sitevision-server',
56
- resolveId(importee) {
57
- if (shouldResolve(importee)) {
58
- // Should be handled as usual.
59
- return null;
60
- }
61
- // Most likely a SiteVision dependency.
62
- // Do not ask other plugins or check the file system to find it.
63
- if (!ignored.includes(importee)) {
64
- ignored.push(importee);
65
- }
66
- return importee;
67
- },
68
- load(id) {
69
- if (shouldLoad(id)) {
70
- return null;
71
- }
72
- // The virtual source code for the provided SiteVision dependency.
73
- const pkg = id.split('/').pop();
74
- const name = camelCase(pkg);
75
- return {
76
- code: `var ${name} = require('${pkg}'); export default ${name}`,
77
- syntheticNamedExports: true,
78
- };
79
- },
80
- };
81
- }