juisy 2.0.0-beta.16 → 2.0.0-beta.18

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.
@@ -3,13 +3,11 @@ import docs from './private/docs/index.js'
3
3
  // import test from './private/test.js'
4
4
  // Public commands
5
5
  import printGlobals from './public/print-globals.js'
6
- import squeeze from './public/squeeze.js'
7
6
 
8
7
  export const commands = [
9
8
  // Private
10
9
  docs,
11
10
  // test,
12
11
  // Public
13
- printGlobals,
14
- squeeze
12
+ printGlobals
15
13
  ]
package/bin/cli/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  'use strict'
4
4
 
@@ -46,7 +46,7 @@ export declare class Command implements CommandObject {
46
46
  /**
47
47
  * Command handler
48
48
  */
49
- handler(this: this, argv: CommandHandlerArgs): void | Promise<void>;
49
+ handler(this: Command, argv: CommandHandlerArgs): void | Promise<void>;
50
50
  /**
51
51
  * Command middlewares
52
52
  */
@@ -73,7 +73,7 @@ export declare class Command implements CommandObject {
73
73
  deprecated: string | boolean | undefined;
74
74
  meta: Partial<import('./types').CommandMeta> | undefined;
75
75
  builder: (cli: CLIEngine) => CLIEngine | PromiseLike<CLIEngine>;
76
- handler: OmitThisParameter<(this: this, argv: CommandHandlerArgs) => void | Promise<void>>;
76
+ handler: (argv: CommandHandlerArgs) => void | Promise<void>;
77
77
  middlewares: import('yargs').MiddlewareFunction[] | undefined;
78
78
  };
79
79
  /**
package/dist/cli/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * juisy v2.0.0-beta.16
2
+ * juisy v2.0.0-beta.18
3
3
  * Copyright © 2022-Present Hervé Perchec
4
4
  */
5
5
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * juisy v2.0.0-beta.16
2
+ * juisy v2.0.0-beta.18
3
3
  * Copyright © 2022-Present Hervé Perchec
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * juisy v2.0.0-beta.16
2
+ * juisy v2.0.0-beta.18
3
3
  * Copyright © 2022-Present Hervé Perchec
4
4
  */
5
5
 
@@ -5,7 +5,8 @@ export type Options = {
5
5
  */
6
6
  moduleId: string;
7
7
  /**
8
- * The CSS selector. Default is `:root`
8
+ * The CSS selector.
9
+ * @default ':root'
9
10
  */
10
11
  selector?: string;
11
12
  /**
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * juisy v2.0.0-beta.16
2
+ * juisy v2.0.0-beta.18
3
3
  * Copyright © 2022-Present Hervé Perchec
4
4
  */
5
5
 
@@ -2,10 +2,11 @@ import { Plugin } from 'vite';
2
2
  export type Options = {
3
3
  /**
4
4
  * The virtual module ID
5
+ * @default 'virtual:project.globals.js'
5
6
  */
6
7
  moduleId?: string;
7
8
  /**
8
- * The project globals path (relative form root folder)
9
+ * The project globals path (relative from root folder)
9
10
  */
10
11
  filePath?: string;
11
12
  };
@@ -1,11 +1,14 @@
1
1
  /*!
2
- * juisy v2.0.0-beta.16
2
+ * juisy v2.0.0-beta.18
3
3
  * Copyright © 2022-Present Hervé Perchec
4
4
  */
5
5
 
6
6
  import { getProjectGlobals } from 'juisy';
7
+ import { OutputUtils } from 'juisy/cli';
7
8
 
8
9
  function injectProjectGlobals(options = {}) {
10
+ const { $style } = OutputUtils;
11
+ let config;
9
12
  let moduleId = "virtual:project.globals.js";
10
13
  if (options.moduleId) {
11
14
  if (options.moduleId.trim().length === 0) {
@@ -16,6 +19,9 @@ function injectProjectGlobals(options = {}) {
16
19
  return {
17
20
  name: "vite-plugin-inject-project-globals",
18
21
  enforce: "pre",
22
+ configResolved(resolvedConfig) {
23
+ config = resolvedConfig;
24
+ },
19
25
  resolveId(id) {
20
26
  if (id !== moduleId) {
21
27
  return;
@@ -23,12 +29,28 @@ function injectProjectGlobals(options = {}) {
23
29
  return "\0" + moduleId;
24
30
  }
25
31
  },
32
+ /**
33
+ * Vite plugin `load` hook
34
+ * @param id - The requested module ID
35
+ * @returns The module content as a string
36
+ * @description
37
+ * Load the virtual module and return its content.
38
+ * If the module ID is not the one defined by the plugin, simply return null.
39
+ * Otherwise, call `getProjectGlobals` and build a js string.
40
+ */
26
41
  async load(id) {
27
42
  if (!id.startsWith("\0") || id.slice(1) !== moduleId) {
28
43
  return;
29
44
  }
30
- const PROJECT_GLOBALS = await getProjectGlobals(options.filePath);
31
- return "export default " + JSON.stringify(PROJECT_GLOBALS);
45
+ const PROJECT_GLOBALS = {
46
+ ...await getProjectGlobals(options.filePath)
47
+ };
48
+ if (PROJECT_GLOBALS.ENV) {
49
+ config.logger.warn("\n[vite-plugin-inject-project-globals] " + $style.yellow("The following ENV variables are exposed:"));
50
+ config.logger.warn(JSON.stringify(PROJECT_GLOBALS.ENV));
51
+ config.logger.warn("\n");
52
+ }
53
+ return "const PROJECT_GLOBALS = " + JSON.stringify(PROJECT_GLOBALS) + "\nconst isBrowser = import.meta.env.SSR === false\nif (isBrowser) {\n if (PROJECT_GLOBALS.ENV) {\n console.warn('[vite-plugin-inject-project-globals] WARNING: some ENV variables are exposed! Be careful, do not expose sensitive data!')\n }\n}\nexport default PROJECT_GLOBALS\n";
32
54
  }
33
55
  };
34
56
  }
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "juisy",
3
- "version": "2.0.0-beta.16",
3
+ "version": "2.0.0-beta.18",
4
4
  "description": "Make you JavaScript (and/or TypeScript) project juicy!",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "bin",
8
- "dist"
8
+ "dist",
9
+ "LICENSE",
10
+ "README.md"
9
11
  ],
10
12
  "engines": {
11
13
  "node": "^18.0.0 || ^20.0.0 || >=22.0.0"
@@ -118,6 +120,9 @@
118
120
  },
119
121
  "@release-it/conventional-changelog": {
120
122
  "optional": true
123
+ },
124
+ "simple-git-hooks": {
125
+ "optional": true
121
126
  }
122
127
  },
123
128
  "devDependencies": {
@@ -1,269 +0,0 @@
1
- import path, { dirname } from 'node:path'
2
- import { fileURLToPath } from 'node:url'
3
-
4
- import { getPackageInfo, eject } from '#juisy'
5
-
6
- const __filename = fileURLToPath(import.meta.url)
7
- const __dirname = dirname(__filename)
8
-
9
- const isDef = value => value !== undefined
10
-
11
- /** @type {import('#juisy/cli').Command} */
12
- export default new CLI.Command({
13
- command: 'squeeze',
14
- describe: 'Initialize project folder',
15
- builder (yargs) {
16
- yargs.option('f', {
17
- alias: 'force',
18
- type: 'boolean',
19
- default: false,
20
- describe: 'Overwrites existing files / scripts / ...'
21
- })
22
- return yargs
23
- },
24
- async handler (argv) {
25
- const {
26
- rootDir: targetProjectRootDir, // rootDir is parent project
27
- prompts,
28
- run
29
- } = CLI.InterfaceUtils
30
- const {
31
- $style,
32
- log,
33
- step,
34
- substep
35
- } = CLI.OutputUtils
36
-
37
- const templateDir = 'template'
38
- const getTemplatePath = target => path.resolve(__dirname, '../../../', templateDir, target)
39
-
40
- /**
41
- * Eject files from template
42
- */
43
- step('Copying files')
44
-
45
- await eject('**/*', {
46
- force: argv.force,
47
- logLevel: 'warn'
48
- })
49
-
50
- substep($style.green(`✔ Successfuly copied`), { last: true })
51
- log() // Blank line
52
-
53
- // substep($style.yellow('Target directory "bin" already exists. Skipped... Use --force option to overwrite'), { last: true })
54
-
55
- /**
56
- * Update package.json file
57
- */
58
- // const scripts = {
59
- // 'docs:api': 'node ./bin/cli docs generate -c ./docs/docs.config.js',
60
- // 'docs:readme': 'node ./bin/cli docs generate:readme',
61
- // 'docs:lint': 'node ./bin/cli docs lint',
62
- // 'docs:lint:fix': 'npm run docs:lint -- --fix',
63
- // 'docs': 'npm run docs:readme && npm run docs:api && npm run docs:lint',
64
- // 'lint': 'npx eslint . --ext .js',
65
- // 'lint:fix': 'npm run lint -- --fix',
66
- // 'lint:markdown': 'npm run docs:lint',
67
- // 'lint:markdown:fix': 'npm run docs:lint:fix',
68
- // 'release': 'node ./bin/cli release',
69
- // 'changelog': 'node ./bin/cli changelog',
70
- // 'git-hooks:reset': 'node ./bin/cli git-hooks reset',
71
- // 'git-hooks:sync': 'node ./bin/cli git-hooks sync',
72
- // 'test': 'node ./bin/cli test',
73
- // 'postinstall': 'npm run git-hooks:sync'
74
- // }
75
-
76
- const targetCliCommand = 'node ./bin/cli'
77
-
78
- step('Adding scripts to package.json')
79
- const packageJson = getPackageInfo()
80
- packageJson.scripts = packageJson.scripts || {}
81
-
82
- // "docs:api": "node ./bin/cli docs generate:api"
83
- let setScript = isDef(packageJson.scripts['docs:api'])
84
- ? argv.force
85
- : true
86
- if (setScript) {
87
- await run('npm', [ 'set-script', 'docs:api', `${targetCliCommand} docs generate:api` ], { stdio: 'pipe', cwd: targetProjectRootDir })
88
- substep($style.green('✔ Script "docs:api" successfuly added'))
89
- } else {
90
- substep($style.yellow('Script "docs:api" already set. Use --force option to overwrite'))
91
- }
92
-
93
- // "docs:readme": "node ./bin/cli docs generate:readme -c ./docs/readme/config.js"
94
- setScript = isDef(packageJson.scripts['docs:readme'])
95
- ? argv.force
96
- : true
97
- if (setScript) {
98
- await run('npm', [
99
- 'set-script',
100
- 'docs:readme',
101
- `${targetCliCommand} docs generate:readme -c ./docs/readme/config.js`
102
- ], { stdio: 'pipe', cwd: targetProjectRootDir })
103
- substep($style.green('✔ Script "docs:readme" successfuly added'))
104
- } else {
105
- substep($style.yellow('Script "docs:readme" already set. Use --force option to overwrite'))
106
- }
107
-
108
- // "docs": "npm run docs:readme && npm run docs:api"
109
- setScript = isDef(packageJson.scripts.docs)
110
- ? argv.force
111
- : true
112
- if (setScript) {
113
- await run('npm', [ 'set-script', 'docs', 'npm run docs:readme && npm run docs:api' ], { stdio: 'pipe', cwd: targetProjectRootDir })
114
- substep($style.green('✔ Script "docs" successfuly added'))
115
- } else {
116
- substep($style.yellow('Script "docs" already set. Use --force option to overwrite'))
117
- }
118
-
119
- // "release": "node ./bin/cli release"
120
- setScript = isDef(packageJson.scripts.release)
121
- ? argv.force
122
- : true
123
- if (setScript) {
124
- await run('npm', [ 'set-script', 'release', `${targetCliCommand} release` ], { stdio: 'pipe', cwd: targetProjectRootDir })
125
- substep($style.green('✔ Script "release" successfuly added'))
126
- } else {
127
- substep($style.yellow('Script "release" already set. Use --force option to overwrite'))
128
- }
129
-
130
- // "changelog": "node ./bin/cli changelog"
131
- setScript = isDef(packageJson.scripts.changelog)
132
- ? argv.force
133
- : true
134
- if (setScript) {
135
- await run('npm', [ 'set-script', 'changelog', `${targetCliCommand} changelog` ], { stdio: 'pipe', cwd: targetProjectRootDir })
136
- substep($style.green('✔ Script "changelog" successfuly added'))
137
- } else {
138
- substep($style.yellow('Script "changelog" already set. Use --force option to overwrite'))
139
- }
140
-
141
- // "git-hooks:reset": "node ./bin/cli git-hooks reset"
142
- setScript = isDef(packageJson.scripts['git-hooks:reset'])
143
- ? argv.force
144
- : true
145
- if (setScript) {
146
- await run('npm', [ 'set-script', 'git-hooks:reset', `${targetCliCommand} git-hooks reset` ], { stdio: 'pipe', cwd: targetProjectRootDir })
147
- substep($style.green('✔ Script "git-hooks:reset" successfuly added'))
148
- } else {
149
- substep($style.yellow('Script "git-hooks:reset" already set. Use --force option to overwrite'))
150
- }
151
-
152
- // "git-hooks:sync": "node ./bin/cli git-hooks sync"
153
- setScript = isDef(packageJson.scripts['git-hooks:sync'])
154
- ? argv.force
155
- : true
156
- if (setScript) {
157
- await run('npm', [ 'set-script', 'git-hooks:sync', `${targetCliCommand} git-hooks sync` ], { stdio: 'pipe', cwd: targetProjectRootDir })
158
- substep($style.green('✔ Script "git-hooks:sync" successfuly added'))
159
- } else {
160
- substep($style.yellow('Script "git-hooks:sync" already set. Use --force option to overwrite'))
161
- }
162
-
163
- // "postinstall": "npm run git-hooks:sync"
164
- setScript = isDef(packageJson.scripts.postinstall)
165
- ? argv.force
166
- : true
167
- if (setScript) {
168
- await run('npm', [ 'set-script', 'postinstall', 'npm run git-hooks:sync' ], { stdio: 'pipe', cwd: targetProjectRootDir })
169
- substep($style.green('✔ Script "postinstall" successfuly added'))
170
- } else {
171
- substep($style.yellow('Script "postinstall" already set. Use --force option to overwrite'))
172
- }
173
- substep($style.green('✔ package.json updated'), { last: true })
174
- log() // Blank line
175
-
176
- // Adding repository info
177
- step('Adding repository config to package.json')
178
- // set repository config
179
- const setRepository = isDef(packageJson.repository)
180
- ? argv.force
181
- : true
182
- if (setRepository) {
183
- const repositoryConfig = {
184
- type: 'git',
185
- url: 'https://gitlab.com/hperchec/juisy'
186
- }
187
- await run('npm', [
188
- 'pkg',
189
- 'set',
190
- `repository=${JSON.stringify(repositoryConfig)}`,
191
- '--json'
192
- ], { stdio: 'pipe', cwd: targetProjectRootDir })
193
- substep($style.green('✔ Repository config successfuly added'), { last: true })
194
- } else {
195
- substep($style.yellow('Repository config already set. Use --force option to overwrite'), { last: true })
196
- }
197
- log() // Blank line
198
-
199
- // Adding issues URL info
200
- step('Adding issues/bugs config to package.json')
201
- // set bugs config
202
- const setBugs = isDef(packageJson.bugs)
203
- ? argv.force
204
- : true
205
- if (setBugs) {
206
- const bugsConfig = {
207
- url: 'https://gitlab.com/hperchec/juisy/issues'
208
- }
209
- await run('npm', [
210
- 'pkg',
211
- 'set',
212
- `bugs=${JSON.stringify(bugsConfig)}`,
213
- '--json'
214
- ], { stdio: 'pipe', cwd: targetProjectRootDir })
215
- substep($style.green('✔ Issues/bugs config successfuly added'), { last: true })
216
- } else {
217
- substep($style.yellow('Issues/bugs config already set. Use --force option to overwrite'), { last: true })
218
- }
219
- log() // Blank line
220
-
221
- // Adding git hooks
222
- step('Adding git hooks config to package.json')
223
- // set simple-git-hook config
224
- const setSimpleGitHook = isDef(packageJson['simple-git-hooks'])
225
- ? argv.force
226
- : true
227
- if (setSimpleGitHook) {
228
- const simpleGitHookConfig = {
229
- 'pre-commit': 'node ./bin/scripts/pre-commit.js',
230
- 'commit-msg': 'node ./bin/scripts/commit-msg.js ${1}'
231
- }
232
- await run('npm', [
233
- 'pkg',
234
- 'set',
235
- `simple-git-hooks=${JSON.stringify(simpleGitHookConfig)}`,
236
- '--json'
237
- ], { stdio: 'pipe', cwd: targetProjectRootDir })
238
- substep($style.green('✔ Git hooks successfuly added'), { last: true })
239
- } else {
240
- substep($style.yellow('Git hooks already set. Use --force option to overwrite'), { last: true })
241
- }
242
- log() // Blank line
243
-
244
- // Adding lint-staged configured
245
- step('Adding lint-staged config to package.json')
246
- // set lint-staged config
247
- const setLintStaged = isDef(packageJson['lint-staged'])
248
- ? argv.force
249
- : true
250
- if (setLintStaged) {
251
- const lintStagedConfig = {
252
- '*.js': [
253
- 'eslint --fix',
254
- 'git add'
255
- ]
256
- }
257
- await run('npm', [
258
- 'pkg',
259
- 'set',
260
- `lint-staged=${JSON.stringify(lintStagedConfig)}`,
261
- '--json'
262
- ], { stdio: 'pipe', cwd: targetProjectRootDir })
263
- substep($style.green('✔ lint-staged successfuly configured'), { last: true })
264
- } else {
265
- substep($style.yellow('lint-staged already configured. Use --force option to overwrite'), { last: true })
266
- }
267
- log() // Blank line
268
- }
269
- })