@spinnaker/scripts 0.1.0 → 0.2.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,55 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.2.4](https://github.com/spinnaker/deck/compare/@spinnaker/scripts@0.2.3...@spinnaker/scripts@0.2.4) (2021-12-01)
7
+
8
+ **Note:** Version bump only for package @spinnaker/scripts
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.2.3](https://github.com/spinnaker/deck/compare/@spinnaker/scripts@0.2.2...@spinnaker/scripts@0.2.3) (2021-11-03)
15
+
16
+ **Note:** Version bump only for package @spinnaker/scripts
17
+
18
+
19
+
20
+
21
+
22
+ ## [0.2.2](https://github.com/spinnaker/deck/compare/@spinnaker/scripts@0.2.0...@spinnaker/scripts@0.2.2) (2021-09-30)
23
+
24
+ **Note:** Version bump only for package @spinnaker/scripts
25
+
26
+
27
+
28
+
29
+
30
+ ## [0.2.1](https://github.com/spinnaker/deck/compare/@spinnaker/scripts@0.2.0...@spinnaker/scripts@0.2.1) (2021-09-30)
31
+
32
+ **Note:** Version bump only for package @spinnaker/scripts
33
+
34
+
35
+
36
+
37
+
38
+ # [0.2.0](https://github.com/spinnaker/deck/compare/@spinnaker/scripts@0.1.0...@spinnaker/scripts@0.2.0) (2021-09-24)
39
+
40
+
41
+ ### Bug Fixes
42
+
43
+ * **scripts/read-write-json:** use comment-json package instead of hjson ([9311e37](https://github.com/spinnaker/deck/commit/9311e37fcdbfa85c02554a42e5f10f17a1fd810d))
44
+
45
+
46
+ ### Features
47
+
48
+ * **packages/scripts:** Add read-write-json helper script ([681b4f8](https://github.com/spinnaker/deck/commit/681b4f8545910ea6f2a06cd33aee7b0f9b9eb469))
49
+ * **scripts/read-write-json:** support boolean and number types ([e713ac4](https://github.com/spinnaker/deck/commit/e713ac4d8e3567c7814ba64089edc58b502c69b5))
50
+
51
+
52
+
53
+
54
+
6
55
  # [0.1.0](https://github.com/spinnaker/deck/compare/@spinnaker/scripts@0.0.23...@spinnaker/scripts@0.1.0) (2021-08-20)
7
56
 
8
57
 
@@ -12,7 +12,7 @@ module.exports = function angularJsTemplateLoader(options = {}) {
12
12
  return {
13
13
  name: 'angularJSTemplateLoader',
14
14
  transform(originalCode, id) {
15
- let code = originalCode;
15
+ const code = originalCode;
16
16
  const templateRegex = /require\(['"]([^'"]+\.html)['"]\)/g;
17
17
 
18
18
  // look for things like require('./template.html')
@@ -38,7 +38,7 @@ module.exports = function angularJsTemplateLoader(options = {}) {
38
38
  return;
39
39
  }
40
40
 
41
- let magicString = new MagicString(code);
41
+ const magicString = new MagicString(code);
42
42
 
43
43
  while (match) {
44
44
  // i.e., './template.html'
package/index.js CHANGED
@@ -127,7 +127,7 @@ const startHandler = async ({ file, push }) => {
127
127
  };
128
128
 
129
129
  const printBundleStart = (option) => {
130
- let message = option.output.map((output) => `${option.input} -> ${output.dir}...`).join('\n');
130
+ const message = option.output.map((output) => `${option.input} -> ${output.dir}...`).join('\n');
131
131
  console.log(chalk.blue.bold(message));
132
132
  };
133
133
  const printBundleComplete = (option, completedTimeInMS) => {
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@spinnaker/scripts",
3
- "version": "0.1.0",
3
+ "version": "0.2.4",
4
4
  "description": "Spinnaker scripts",
5
5
  "main": "index.js",
6
6
  "bin": {
7
- "spinnaker-scripts": "./index.js"
7
+ "spinnaker-scripts": "./index.js",
8
+ "read-write-json": "./read-write-json.js"
8
9
  },
9
10
  "scripts": {},
10
11
  "keywords": [],
@@ -17,11 +18,12 @@
17
18
  "@rollup/plugin-replace": "2.4.2",
18
19
  "@rollup/plugin-typescript": "^8.1.0",
19
20
  "@rollup/plugin-url": "^6.0.0",
20
- "@spinnaker/eslint-plugin": "^1.1.1",
21
- "@spinnaker/styleguide": "^1.0.24",
21
+ "@spinnaker/eslint-plugin": "^3.0.1",
22
+ "@spinnaker/styleguide": "^2.0.0",
22
23
  "@svgr/rollup": "^5.5.0",
23
24
  "autoprefixer": "^7.1.2",
24
25
  "chalk": "^4.1.1",
26
+ "comment-json": "^4.1.1",
25
27
  "esbuild": "^0.12.14",
26
28
  "ora": "^5.4.0",
27
29
  "postcss-colorfix": "0.0.5",
@@ -34,7 +36,10 @@
34
36
  "rollup-plugin-terser": "7.0.2",
35
37
  "rollup-plugin-visualizer": "5.4.1",
36
38
  "yalc": "^1.0.0-pre.53",
37
- "yargs": "^17.0.1"
39
+ "yargs": "^17.1.1"
38
40
  },
39
- "gitHead": "1bf4a0f5763b5e20c1c3fbeb5736a6260a081df8"
41
+ "devDependencies": {
42
+ "@types/yargs": "^17.0.3"
43
+ },
44
+ "gitHead": "59026ea6af7b81ffb8e8c59e18f43396906ddafb"
40
45
  }
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+ const fs = require('fs');
3
+ // JSON parse/stringify with support for comments (tsconfig.json can have comments)
4
+ const commentJson = require('comment-json');
5
+ const { get, set, unset } = require('lodash');
6
+ const yargs = require('yargs');
7
+
8
+ const configureCli = () => {
9
+ const yargs = require('yargs');
10
+
11
+ const addDefaultPositionalArgs = (_yargs) => {
12
+ _yargs.positional('filename', { description: 'The JSON file' });
13
+ _yargs.positional('jsonpath', { description: 'A lodash-style JSON Path' });
14
+ };
15
+
16
+ yargs.command(
17
+ 'read <filename> <jsonpath>',
18
+ 'Outputs a value from a JSON file at the given path',
19
+ addDefaultPositionalArgs,
20
+ ({ filename, jsonpath }) => {
21
+ console.log(readJsonField(filename, jsonpath));
22
+ },
23
+ );
24
+
25
+ yargs.command(
26
+ 'write <filename> <jsonpath> <value>',
27
+ 'Writes a value to a JSON file at the given path',
28
+ (_yargs) => {
29
+ addDefaultPositionalArgs(_yargs);
30
+ _yargs.positional('value', {
31
+ type: 'string',
32
+ description: 'The new value to write',
33
+ });
34
+ _yargs.option('type', {
35
+ description: 'writes the value as a JSON boolean/number/string',
36
+ type: 'string',
37
+ choices: ['boolean', 'number', 'string'],
38
+ default: 'string',
39
+ });
40
+ },
41
+ ({ filename, jsonpath, value, type }) => {
42
+ let newvalue = value;
43
+ if (type === 'boolean') {
44
+ newvalue = newvalue === 'true' ? true : newvalue === 'false' ? false : newvalue;
45
+ if (typeof newvalue !== 'boolean') {
46
+ throw new Error(`Cannot parse ${value} as a boolean`);
47
+ }
48
+ } else if (type === 'number') {
49
+ const newvalue = Number(value);
50
+ if (isNaN(newvalue)) {
51
+ throw new Error(`Cannot parse ${value} as a number`);
52
+ }
53
+ }
54
+ writeJsonField(filename, jsonpath, newvalue);
55
+ },
56
+ );
57
+
58
+ yargs.command(
59
+ 'delete <filename> <jsonpath>',
60
+ 'Deletes a property from a JSON file at the given path',
61
+ addDefaultPositionalArgs,
62
+ ({ filename, jsonpath }) => {
63
+ deleteJsonField(filename, jsonpath);
64
+ },
65
+ );
66
+
67
+ yargs.demandCommand(1);
68
+ yargs.strictCommands();
69
+ yargs.wrap(null);
70
+
71
+ yargs.example('read-write-json.js read package.json version', 'Outputs the version property from package.json');
72
+ yargs.example(
73
+ 'read-write-json.js write package.json devDependencies.husky 6.0.0',
74
+ 'Writes "husky": "6.0.0" to the "devDependencies" property of package.json',
75
+ );
76
+ yargs.example(
77
+ 'read-write-json.js delete package.json devDependencies.husky',
78
+ 'Deletes the "husky" key from the "devDependencies" property of package.json',
79
+ );
80
+ yargs.parse();
81
+ };
82
+
83
+ if (require.main === module) {
84
+ configureCli();
85
+ }
86
+
87
+ function readJson(filename) {
88
+ const string = fs.readFileSync(filename, 'utf-8');
89
+ return commentJson.parse(string);
90
+ }
91
+
92
+ function writeJson(filename, json) {
93
+ const data = commentJson.stringify(json, null, 2);
94
+ fs.writeFileSync(filename, data, 'utf-8');
95
+ }
96
+
97
+ function readJsonField(filename, path) {
98
+ const json = readJson(filename);
99
+ return get(json, path);
100
+ }
101
+
102
+ function deleteJsonField(filename, field) {
103
+ const json = readJson(filename);
104
+ unset(json, field);
105
+ writeJson(filename, json);
106
+ }
107
+
108
+ function writeJsonField(filename, field, val) {
109
+ const json = readJson(filename);
110
+ set(json, field, val);
111
+ writeJson(filename, json);
112
+ }
113
+
114
+ module.exports.readJson = readJson;
115
+ module.exports.writeJson = writeJson;
116
+ module.exports.readJsonField = readJsonField;
117
+ module.exports.writeJsonField = writeJsonField;
118
+ module.exports.deleteJsonField = deleteJsonField;