@videinfra/static-website-builder 2.0.2 → 2.0.4

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.
Files changed (122) hide show
  1. package/.prettierrc +11 -11
  2. package/CHANGELOG.md +214 -210
  3. package/README.md +102 -102
  4. package/bin/builder.js +40 -40
  5. package/eslint.config.js +39 -39
  6. package/gulpfile.js +63 -63
  7. package/init/default/config/config.js +44 -44
  8. package/init/default/src/html/data/global.js +9 -9
  9. package/init/default/src/javascripts/_entries.js +14 -14
  10. package/init/index.js +63 -63
  11. package/init/test/.env +6 -6
  12. package/init/test/.env.local +3 -2
  13. package/init/test/config/config.js +71 -67
  14. package/init/test/src/html/404.twig +12 -12
  15. package/init/test/src/html/data/global.js +10 -10
  16. package/init/test/src/html/env.twig +21 -21
  17. package/init/test/src/html/layouts/base.twig +1 -1
  18. package/init/test/src/html/other.twig +9 -9
  19. package/init/test/src/html/preposition.twig +4 -4
  20. package/init/test/src/javascripts/_entries-alt.js +10 -10
  21. package/init/test/src/javascripts/_entries.js +19 -19
  22. package/init/test/src/javascripts/common.js +13 -13
  23. package/init/test/src/javascripts/main.js +8 -8
  24. package/init/test/src/javascripts/something.ts +9 -9
  25. package/init/test/src/stylesheets/autoprefixer-test.scss +3 -3
  26. package/init/test/src/stylesheets/env-test.scss +28 -28
  27. package/init/test/src/stylesheets/ignore-test.scss +4 -4
  28. package/init/test/src/stylesheets/nested-calc-test.scss +3 -3
  29. package/init/test/src/stylesheets/sub-folder/import-test.scss +2 -2
  30. package/lib/camelize-file-name.js +21 -21
  31. package/lib/generate-gulp-tasks.js +85 -85
  32. package/lib/get-config.js +203 -204
  33. package/lib/get-file-names.js +23 -23
  34. package/lib/get-path.js +102 -102
  35. package/lib/globs-helper.js +243 -243
  36. package/lib/gulp/dynamic-task.js +8 -8
  37. package/lib/gulp/resolve-dynamic-task.js +11 -11
  38. package/lib/gulp/task-before-dest.js +8 -8
  39. package/lib/gulp/task-end.js +10 -10
  40. package/lib/gulp/task-start.js +12 -12
  41. package/lib/gulp/task-watch.js +66 -66
  42. package/lib/init/copy-folder.js +50 -50
  43. package/lib/init/folder-exists.js +10 -10
  44. package/lib/init/get-folder-list.js +16 -16
  45. package/lib/init/merge-package.js +17 -17
  46. package/lib/init/read-package.js +17 -17
  47. package/lib/log-error.js +15 -15
  48. package/lib/merge.js +27 -27
  49. package/lib/run-preprocess.js +32 -32
  50. package/lib/task-order.js +19 -19
  51. package/package.json +68 -68
  52. package/plugins/example/preprocess-config.js +17 -17
  53. package/plugins/example/task.js +55 -55
  54. package/plugins/example.js +38 -38
  55. package/plugins/sass-engine/preprocess-config.js +59 -59
  56. package/plugins/sass.js +41 -41
  57. package/plugins/twig/lodash-filters/filters.js +91 -91
  58. package/plugins/twig/lodash-filters.js +14 -14
  59. package/plugins/twig/symfony-filters/filters.js +102 -102
  60. package/plugins/twig/symfony-filters/preposition_nbsp.js +77 -77
  61. package/plugins/twig/symfony-filters.js +14 -14
  62. package/plugins/twig/symfony-functions/functions.js +31 -31
  63. package/plugins/twig/symfony-functions.js +14 -14
  64. package/plugins/twig-engine/preprocess-config.js +53 -53
  65. package/plugins/twig.js +74 -74
  66. package/tasks/browser-sync/config.js +39 -39
  67. package/tasks/browser-sync/preprocess-config.js +32 -32
  68. package/tasks/browser-sync/task.js +9 -9
  69. package/tasks/clean/config.js +20 -20
  70. package/tasks/clean/preprocess-config.js +19 -19
  71. package/tasks/clean/task.js +7 -7
  72. package/tasks/data/config.js +34 -34
  73. package/tasks/data/data-loader-js.js +14 -14
  74. package/tasks/data/data-loader-json.js +5 -5
  75. package/tasks/data/get-data.js +96 -96
  76. package/tasks/env/config.js +26 -23
  77. package/tasks/env/get-env.js +113 -81
  78. package/tasks/fonts/config.js +24 -24
  79. package/tasks/fonts/task.js +47 -47
  80. package/tasks/global/config.js +7 -7
  81. package/tasks/html/config.js +42 -42
  82. package/tasks/html/task.js +91 -91
  83. package/tasks/icons/config.js +47 -47
  84. package/tasks/icons/preprocess-config.js +60 -60
  85. package/tasks/icons/task.js +56 -56
  86. package/tasks/images/config.js +27 -27
  87. package/tasks/images/task.js +46 -46
  88. package/tasks/javascripts/config.js +69 -69
  89. package/tasks/javascripts/preprocess-config.js +109 -109
  90. package/tasks/javascripts/task.js +86 -86
  91. package/tasks/sitemap/config.js +48 -48
  92. package/tasks/sitemap/preprocess-config.js +18 -18
  93. package/tasks/sitemap/task.js +69 -69
  94. package/tasks/sizereport/config.js +23 -23
  95. package/tasks/sizereport/task.js +16 -16
  96. package/tasks/static/config.js +27 -27
  97. package/tasks/static/task.js +46 -46
  98. package/tasks/stylesheets/config.js +85 -85
  99. package/tasks/stylesheets/preprocess-config.js +41 -41
  100. package/tasks/stylesheets/task.js +73 -73
  101. package/tests/build/build.test.js +153 -153
  102. package/tests/camelize-file-name.test.js +11 -11
  103. package/tests/generate-gulp-tasks.test.js +78 -78
  104. package/tests/glob-helper.test.js +99 -99
  105. package/tests/merge.test.js +10 -10
  106. package/tests/preposition_nbsp.test.js +50 -50
  107. package/tests/run-preprocess.test.js +90 -90
  108. package/tests/sass-stringify.test.js +24 -24
  109. package/tests/sitemap.test.js +12 -12
  110. package/vendor/gulp-rolldown/index.js +151 -151
  111. package/vendor/gulp-rolldown/plugin-raw.js +17 -17
  112. package/vendor/gulp-rolldown/plugin-virtual-entry.js +30 -30
  113. package/vendor/gulp-sass/CHANGELOG.md +168 -168
  114. package/vendor/gulp-sass/LICENSE +20 -20
  115. package/vendor/gulp-sass/README.md +187 -187
  116. package/vendor/gulp-sass/index.js +208 -208
  117. package/vendor/gulp-sass/package.json +61 -61
  118. package/vendor/gulp-sass/sass-stringify.js +32 -32
  119. package/vendor/gulp-twig/LICENSE +20 -20
  120. package/vendor/gulp-twig/README.md +167 -167
  121. package/vendor/gulp-twig/index.js +138 -138
  122. package/vendor/gulp-twig/package.json +44 -44
package/bin/builder.js CHANGED
@@ -1,40 +1,40 @@
1
- #!/usr/bin/env node
2
- import path from 'path';
3
- import { fileURLToPath } from 'node:url';
4
- import minimist from 'minimist';
5
- import { fork } from 'child_process';
6
- import { createRequire } from 'node:module';
7
-
8
- const require = createRequire(import.meta.url);
9
- const allArgs = minimist(process.argv.slice(2));
10
- const additionalArgs = allArgs._;
11
-
12
- if (additionalArgs[0] === 'init') {
13
- import('../init/index').then(({ default: init }) => {
14
- init(additionalArgs[1]);
15
- });
16
- } else {
17
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
18
-
19
- const builderEntryDir = path.resolve(__dirname, '../gulpfile.js');
20
- const gulpModulePath = path.dirname(require.resolve('gulp'));
21
- const gulpBinaryFile = path.join(gulpModulePath, '/bin/gulp');
22
-
23
- let args = ['--gulpfile', builderEntryDir];
24
-
25
- if (additionalArgs.length) {
26
- args = args.concat(additionalArgs);
27
- }
28
-
29
- if (allArgs.config) {
30
- args = args.concat('--config', allArgs.config);
31
- }
32
- if (allArgs.tasks) {
33
- args = args.concat('--tasks', '');
34
- }
35
-
36
- fork(gulpBinaryFile, args).on('exit', function (code) {
37
- // Exit with error if child process exited with an error
38
- process.exit(code);
39
- });
40
- }
1
+ #!/usr/bin/env node
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import minimist from 'minimist';
5
+ import { fork } from 'child_process';
6
+ import { createRequire } from 'node:module';
7
+
8
+ const require = createRequire(import.meta.url);
9
+ const allArgs = minimist(process.argv.slice(2));
10
+ const additionalArgs = allArgs._;
11
+
12
+ if (additionalArgs[0] === 'init') {
13
+ import('../init/index').then(({ default: init }) => {
14
+ init(additionalArgs[1]);
15
+ });
16
+ } else {
17
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
18
+
19
+ const builderEntryDir = path.resolve(__dirname, '../gulpfile.js');
20
+ const gulpModulePath = path.dirname(require.resolve('gulp'));
21
+ const gulpBinaryFile = path.join(gulpModulePath, '/bin/gulp');
22
+
23
+ let args = ['--gulpfile', builderEntryDir];
24
+
25
+ if (additionalArgs.length) {
26
+ args = args.concat(additionalArgs);
27
+ }
28
+
29
+ if (allArgs.config) {
30
+ args = args.concat('--config', allArgs.config);
31
+ }
32
+ if (allArgs.tasks) {
33
+ args = args.concat('--tasks', '');
34
+ }
35
+
36
+ fork(gulpBinaryFile, args).on('exit', function (code) {
37
+ // Exit with error if child process exited with an error
38
+ process.exit(code);
39
+ });
40
+ }
package/eslint.config.js CHANGED
@@ -1,39 +1,39 @@
1
- import { defineConfig } from "eslint/config";
2
-
3
- export default defineConfig([
4
- {
5
- env: {
6
- "browser": true,
7
- "commonjs": true,
8
- "es6": true,
9
- "jquery": true
10
- },
11
- extends: "eslint:recommended",
12
- parserOptions: {
13
- "sourceType": "module"
14
- },
15
- rules: {
16
- "linebreak-style": [
17
- "error",
18
- "unix"
19
- ],
20
- "quotes": [
21
- "error",
22
- "single"
23
- ],
24
- "semi": [
25
- "error",
26
- "always"
27
- ],
28
- "no-console": [
29
- "warn", { "allow": ["warn", "error"] }
30
- ],
31
- "no-debugger": [
32
- "warn"
33
- ],
34
- "no-unused-vars": [
35
- "warn"
36
- ]
37
- }
38
- },
39
- ]);
1
+ import { defineConfig } from "eslint/config";
2
+
3
+ export default defineConfig([
4
+ {
5
+ env: {
6
+ "browser": true,
7
+ "commonjs": true,
8
+ "es6": true,
9
+ "jquery": true
10
+ },
11
+ extends: "eslint:recommended",
12
+ parserOptions: {
13
+ "sourceType": "module"
14
+ },
15
+ rules: {
16
+ "linebreak-style": [
17
+ "error",
18
+ "unix"
19
+ ],
20
+ "quotes": [
21
+ "error",
22
+ "single"
23
+ ],
24
+ "semi": [
25
+ "error",
26
+ "always"
27
+ ],
28
+ "no-console": [
29
+ "warn", { "allow": ["warn", "error"] }
30
+ ],
31
+ "no-debugger": [
32
+ "warn"
33
+ ],
34
+ "no-unused-vars": [
35
+ "warn"
36
+ ]
37
+ }
38
+ },
39
+ ]);
package/gulpfile.js CHANGED
@@ -1,63 +1,63 @@
1
- import { getConfigAsync } from './lib/get-config.js';
2
- import generateGulpTasks from './lib/generate-gulp-tasks.js';
3
-
4
- // Set mode globally it can be used by tasks
5
- let hasProductionArg = false;
6
-
7
- for (let i = 0; i < process.argv.length; i++) {
8
- const argValue = process.argv[i];
9
- // If build task is 'build' or '...-build' then set production mode
10
- if (argValue === 'build' || argValue.match(/^[a-z0-9-]+-build$/)) {
11
- hasProductionArg = true;
12
- }
13
- }
14
-
15
- global.production = global.production || hasProductionArg || process.env.NODE_ENV === 'production';
16
- global.development = !global.production;
17
-
18
- // Config file
19
- let builderConfigFile = process.env.BUILDER_CONFIG_FILE || 'config/config.js';
20
-
21
- if (process.argv.indexOf('--config') !== -1) {
22
- builderConfigFile = process.argv[process.argv.indexOf('--config') + 1];
23
- } else {
24
- for (let i = 0; i < process.argv.length; i++) {
25
- if (process.argv[i].indexOf('--config=') !== -1) {
26
- builderConfigFile = process.argv[i].substr(9);
27
- }
28
- }
29
- }
30
-
31
- // Load all config files and generate gulp tasks
32
- const gulpTasks = generateGulpTasks(await getConfigAsync(builderConfigFile));
33
-
34
- // Expose main tasks
35
- export const build = gulpTasks.build;
36
- export const watch = gulpTasks.watch;
37
-
38
- // Expose separate tasks
39
- export const clean = gulpTasks['clean-beforeBuild'];
40
-
41
- export const fonts = gulpTasks['fonts-build'];
42
- export const fontsWatch = gulpTasks['fonts-watch'];
43
-
44
- export const html = gulpTasks['html-build'];
45
- export const htmlWatch = gulpTasks['html-watch'];
46
-
47
- export const icons = gulpTasks['icons-build'];
48
- export const iconsWatch = gulpTasks['icons-watch'];
49
-
50
- export const images = gulpTasks['images-build'];
51
- export const imagesWatch = gulpTasks['images-watch'];
52
-
53
- export const sitemap = gulpTasks['sitemap-afterBuild'];
54
- export const sitemapWatch = gulpTasks['sitemap-watch'];
55
-
56
- export const staticFiles = gulpTasks['staticFiles-build'];
57
- export const staticFilesWatch = gulpTasks['staticFiles-watch'];
58
-
59
- export const stylesheets = gulpTasks['stylesheets-build'];
60
- export const stylesheetsWatch = gulpTasks['stylesheets-watch'];
61
-
62
- export const javascripts = gulpTasks['javascripts-build'];
63
- export const javascriptsWatch = gulpTasks['javascripts-watch'];
1
+ import { getConfigAsync } from './lib/get-config.js';
2
+ import generateGulpTasks from './lib/generate-gulp-tasks.js';
3
+
4
+ // Set mode globally it can be used by tasks
5
+ let hasProductionArg = false;
6
+
7
+ for (let i = 0; i < process.argv.length; i++) {
8
+ const argValue = process.argv[i];
9
+ // If build task is 'build' or '...-build' then set production mode
10
+ if (argValue === 'build' || argValue.match(/^[a-z0-9-]+-build$/)) {
11
+ hasProductionArg = true;
12
+ }
13
+ }
14
+
15
+ global.production = global.production || hasProductionArg || process.env.NODE_ENV === 'production';
16
+ global.development = !global.production;
17
+
18
+ // Config file
19
+ let builderConfigFile = process.env.BUILDER_CONFIG_FILE || 'config/config.js';
20
+
21
+ if (process.argv.indexOf('--config') !== -1) {
22
+ builderConfigFile = process.argv[process.argv.indexOf('--config') + 1];
23
+ } else {
24
+ for (let i = 0; i < process.argv.length; i++) {
25
+ if (process.argv[i].indexOf('--config=') !== -1) {
26
+ builderConfigFile = process.argv[i].substr(9);
27
+ }
28
+ }
29
+ }
30
+
31
+ // Load all config files and generate gulp tasks
32
+ const gulpTasks = generateGulpTasks(await getConfigAsync(builderConfigFile));
33
+
34
+ // Expose main tasks
35
+ export const build = gulpTasks.build;
36
+ export const watch = gulpTasks.watch;
37
+
38
+ // Expose separate tasks
39
+ export const clean = gulpTasks['clean-beforeBuild'];
40
+
41
+ export const fonts = gulpTasks['fonts-build'];
42
+ export const fontsWatch = gulpTasks['fonts-watch'];
43
+
44
+ export const html = gulpTasks['html-build'];
45
+ export const htmlWatch = gulpTasks['html-watch'];
46
+
47
+ export const icons = gulpTasks['icons-build'];
48
+ export const iconsWatch = gulpTasks['icons-watch'];
49
+
50
+ export const images = gulpTasks['images-build'];
51
+ export const imagesWatch = gulpTasks['images-watch'];
52
+
53
+ export const sitemap = gulpTasks['sitemap-afterBuild'];
54
+ export const sitemapWatch = gulpTasks['sitemap-watch'];
55
+
56
+ export const staticFiles = gulpTasks['staticFiles-build'];
57
+ export const staticFilesWatch = gulpTasks['staticFiles-watch'];
58
+
59
+ export const stylesheets = gulpTasks['stylesheets-build'];
60
+ export const stylesheetsWatch = gulpTasks['stylesheets-watch'];
61
+
62
+ export const javascripts = gulpTasks['javascripts-build'];
63
+ export const javascriptsWatch = gulpTasks['javascripts-watch'];
@@ -1,44 +1,44 @@
1
- /*
2
- * Task configuration
3
- * All options will be merged with defaults, but not replaces whole configuration object
4
- *
5
- * Default configuration can be seen here https://github.com/videinfra/static-website-builder/tree/master/tasks
6
- * in each tasks config.js file
7
- */
8
-
9
- import * as sassPlugin from '@videinfra/static-website-builder/plugins/sass';
10
- import * as twigPlugin from '@videinfra/static-website-builder/plugins/twig';
11
-
12
- export const clean = {};
13
- export const staticFiles = {};
14
- export const html = {};
15
- export const data = {};
16
- export const fonts = {};
17
- export const icons = {};
18
- export const images = {};
19
- export const javascripts = {};
20
- export const stylesheets = {};
21
- export const browserSync = {};
22
- export const sizereport = {};
23
-
24
- export const plugins = [
25
- // Enables SASS engine and .sass and .scss file compilation
26
- sassPlugin,
27
-
28
- // Enables TwigJS engine .twig file compilation
29
- twigPlugin,
30
- ];
31
-
32
-
33
- /*
34
- * Path configuration
35
- * All options will be merged with defaults, but not replaces whole configuration object
36
- *
37
- * Default configuration can be seen here https://github.com/videinfra/static-website-builder/tree/master/tasks
38
- * in each tasks config.js file
39
- */
40
-
41
- export const paths = {
42
- src: './src',
43
- dest: './public',
44
- };
1
+ /*
2
+ * Task configuration
3
+ * All options will be merged with defaults, but not replaces whole configuration object
4
+ *
5
+ * Default configuration can be seen here https://github.com/videinfra/static-website-builder/tree/master/tasks
6
+ * in each tasks config.js file
7
+ */
8
+
9
+ import * as sassPlugin from '@videinfra/static-website-builder/plugins/sass';
10
+ import * as twigPlugin from '@videinfra/static-website-builder/plugins/twig';
11
+
12
+ export const clean = {};
13
+ export const staticFiles = {};
14
+ export const html = {};
15
+ export const data = {};
16
+ export const fonts = {};
17
+ export const icons = {};
18
+ export const images = {};
19
+ export const javascripts = {};
20
+ export const stylesheets = {};
21
+ export const browserSync = {};
22
+ export const sizereport = {};
23
+
24
+ export const plugins = [
25
+ // Enables SASS engine and .sass and .scss file compilation
26
+ sassPlugin,
27
+
28
+ // Enables TwigJS engine .twig file compilation
29
+ twigPlugin,
30
+ ];
31
+
32
+
33
+ /*
34
+ * Path configuration
35
+ * All options will be merged with defaults, but not replaces whole configuration object
36
+ *
37
+ * Default configuration can be seen here https://github.com/videinfra/static-website-builder/tree/master/tasks
38
+ * in each tasks config.js file
39
+ */
40
+
41
+ export const paths = {
42
+ src: './src',
43
+ dest: './public',
44
+ };
@@ -1,9 +1,9 @@
1
- /**
2
- * Content exported from this file is avaiable in the templates as variables
3
- *
4
- * @example
5
- * <div>{{ name }}</div>
6
- */
7
- export default {
8
- 'name': 'World',
9
- };
1
+ /**
2
+ * Content exported from this file is avaiable in the templates as variables
3
+ *
4
+ * @example
5
+ * <div>{{ name }}</div>
6
+ */
7
+ export default {
8
+ 'name': 'World',
9
+ };
@@ -1,14 +1,14 @@
1
- /*
2
- * All files listed in here are created / compiled and additionally
3
- * shared.js is automatically created, which contains all common JS (chunks / modules imported from more than 1 entry files).
4
- */
5
- export default {
6
- 'main': [
7
- './common',
8
- './main'
9
- ],
10
- 'dark': [
11
- './common',
12
- './dark'
13
- ]
14
- };
1
+ /*
2
+ * All files listed in here are created / compiled and additionally
3
+ * shared.js is automatically created, which contains all common JS (chunks / modules imported from more than 1 entry files).
4
+ */
5
+ export default {
6
+ 'main': [
7
+ './common',
8
+ './main'
9
+ ],
10
+ 'dark': [
11
+ './common',
12
+ './dark'
13
+ ]
14
+ };
package/init/index.js CHANGED
@@ -1,63 +1,63 @@
1
- import { getBuilderPath, getProjectPath } from '../lib/get-path.js';
2
- import copyFolder from '../lib/init/copy-folder.js';
3
- import readPackage from '../lib/init/read-package.js';
4
- import mergePackage from '../lib/init/merge-package.js';
5
- import folderExists from '../lib/init/folder-exists.js';
6
- import getFolderList from '../lib/init/get-folder-list.js';
7
-
8
- import chalk from 'chalk';
9
- import { exec } from 'child_process';
10
-
11
- export default function init(template = 'default') {
12
- let templateName = template || 'default';
13
- let copyFrom = getBuilderPath('init', templateName);
14
- const copyTo = getProjectPath();
15
-
16
- if (template === 'test' || !folderExists(copyFrom)) {
17
- console.log(chalk.red(`Template "${templateName}" doesn't exist`));
18
-
19
- getFolderList(getBuilderPath('init')).then((templates) => {
20
- console.log('Available templates:');
21
- console.log(chalk.cyan(` ${templates.join('\n ')}`));
22
- });
23
- return;
24
- }
25
-
26
- console.log(chalk.magenta(`Generating project files using template "${templateName}"`));
27
-
28
- // Copy files
29
- const filesCopied = copyFolder(copyFrom, copyTo);
30
-
31
- // Merge template package.json into projects package.json
32
- const packageMerged = readPackage(getBuilderPath('init', templateName, 'package.json'), {}).then((packageJSON) => {
33
- return mergePackage(getProjectPath('package.json'), packageJSON)
34
- .then(() => {
35
- if (packageJSON.dependencies || packageJSON.devDependencies) {
36
- console.log(chalk.magenta('Installing npm dependencies'));
37
-
38
- return new Promise((resolve, _reject) => {
39
- exec('npm install', function (_error, _stdout, _stderr) {
40
- resolve();
41
- });
42
- });
43
- }
44
- })
45
- .catch((_err) => {
46
- // Skip errors
47
- return Promise.resolve();
48
- });
49
- });
50
-
51
- Promise.all([filesCopied, packageMerged]).then(
52
- () => {
53
- console.log(chalk.green('All done\n'));
54
-
55
- console.log('To start the dev server:\n' + chalk.cyan(' npm run start'));
56
-
57
- console.log('To build the project:\n' + chalk.cyan(' npm run build'));
58
- },
59
- (err) => {
60
- throw err;
61
- },
62
- );
63
- }
1
+ import { getBuilderPath, getProjectPath } from '../lib/get-path.js';
2
+ import copyFolder from '../lib/init/copy-folder.js';
3
+ import readPackage from '../lib/init/read-package.js';
4
+ import mergePackage from '../lib/init/merge-package.js';
5
+ import folderExists from '../lib/init/folder-exists.js';
6
+ import getFolderList from '../lib/init/get-folder-list.js';
7
+
8
+ import chalk from 'chalk';
9
+ import { exec } from 'child_process';
10
+
11
+ export default function init(template = 'default') {
12
+ let templateName = template || 'default';
13
+ let copyFrom = getBuilderPath('init', templateName);
14
+ const copyTo = getProjectPath();
15
+
16
+ if (template === 'test' || !folderExists(copyFrom)) {
17
+ console.log(chalk.red(`Template "${templateName}" doesn't exist`));
18
+
19
+ getFolderList(getBuilderPath('init')).then((templates) => {
20
+ console.log('Available templates:');
21
+ console.log(chalk.cyan(` ${templates.join('\n ')}`));
22
+ });
23
+ return;
24
+ }
25
+
26
+ console.log(chalk.magenta(`Generating project files using template "${templateName}"`));
27
+
28
+ // Copy files
29
+ const filesCopied = copyFolder(copyFrom, copyTo);
30
+
31
+ // Merge template package.json into projects package.json
32
+ const packageMerged = readPackage(getBuilderPath('init', templateName, 'package.json'), {}).then((packageJSON) => {
33
+ return mergePackage(getProjectPath('package.json'), packageJSON)
34
+ .then(() => {
35
+ if (packageJSON.dependencies || packageJSON.devDependencies) {
36
+ console.log(chalk.magenta('Installing npm dependencies'));
37
+
38
+ return new Promise((resolve, _reject) => {
39
+ exec('npm install', function (_error, _stdout, _stderr) {
40
+ resolve();
41
+ });
42
+ });
43
+ }
44
+ })
45
+ .catch((_err) => {
46
+ // Skip errors
47
+ return Promise.resolve();
48
+ });
49
+ });
50
+
51
+ Promise.all([filesCopied, packageMerged]).then(
52
+ () => {
53
+ console.log(chalk.green('All done\n'));
54
+
55
+ console.log('To start the dev server:\n' + chalk.cyan(' npm run start'));
56
+
57
+ console.log('To build the project:\n' + chalk.cyan(' npm run build'));
58
+ },
59
+ (err) => {
60
+ throw err;
61
+ },
62
+ );
63
+ }
package/init/test/.env CHANGED
@@ -1,6 +1,6 @@
1
- HOST=https://test-global.tld
2
- FOO=foo-global
3
- TYPE_BOOL_TRUE=true
4
- TYPE_BOOL_FALSE=false
5
- TYPE_NUMBER=123.456
6
- TYPE_EMPTY=
1
+ HOST=https://test-global.tld
2
+ FOO=foo-global
3
+ TYPE_BOOL_TRUE=true
4
+ TYPE_BOOL_FALSE=false
5
+ TYPE_NUMBER=123.456
6
+ TYPE_EMPTY=
@@ -1,2 +1,3 @@
1
- HOST=https://test-local.tld
2
- BAR=bar-local
1
+ HOST=https://test-local.tld
2
+ BAR=bar-local
3
+ ASSETS_VERSION=12345678