Skip to content

Commit be4c4f8

Browse files
committed
build: add packages
1 parent bc6beb0 commit be4c4f8

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto
2+
*.js text eol=lf

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
coverage
2+
dist
3+
.opt-*
4+
node_modules
5+
6+
# Package Locks
7+
yarn.lock
8+
9+
# Private
10+
.dev
11+
.env

obs.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable @typescript-eslint/no-var-requires */
3+
4+
/*
5+
build obs by running
6+
npm run build
7+
8+
guid and uuid will be automatically generated and placed
9+
inside .env file which will then be read by the github workflow
10+
build script.
11+
*/
12+
13+
/*
14+
This script handles the following:
15+
- read package.json
16+
- create .env file
17+
- return uuid, guid, version
18+
19+
can be called with the following external commands:
20+
- node obs.js returns version of obs
21+
- node obs.js generate generates uuid / guid and shows all env vars in console
22+
- node obs.js uuid returns obs uuid
23+
- node obs.js guid returns obs guid
24+
- node obs.js versiom returns version of obs
25+
26+
can be called with the following obs commands:
27+
- npm run obs
28+
- npm run obs:generate
29+
- npm run env-obs
30+
- npm run env-uuid
31+
- npm run env-guid
32+
- npm run env-version
33+
*/
34+
35+
const fs = require('fs');
36+
const { v5: uuid } = require('uuid');
37+
38+
/*
39+
* declrations > package.json
40+
*/
41+
42+
const { version, repository } = JSON.parse(fs.readFileSync('package.json'));
43+
const args = process.argv.slice(2, process.argv.length);
44+
const action = args[0];
45+
// const a = args[ 1 ];
46+
// const b = args[ 2 ];
47+
48+
if (action === 'guid') {
49+
console.log(`${process.env.GUID}`);
50+
} else if (action === 'setup') {
51+
fs.writeFileSync('.env', '', (err) => {
52+
if (err) {
53+
console.error(err);
54+
} else {
55+
console.log(`Wrote to .env successfully`);
56+
}
57+
});
58+
} else if (action === 'generate') {
59+
const buildGuid = uuid(`${repository.url}`, uuid.URL);
60+
const buildUuid = uuid(version, buildGuid);
61+
62+
const ids = `
63+
VERSION=${version}
64+
GUID=${buildGuid}
65+
UUID=${buildUuid}
66+
`;
67+
68+
console.log(version);
69+
console.log(buildGuid);
70+
console.log(buildUuid);
71+
72+
fs.writeFileSync('.env', ids, (err) => {
73+
if (err) {
74+
console.error(`Could not write env vars: ${err}`);
75+
} else {
76+
console.log(`Wrote env vars to .env`);
77+
}
78+
});
79+
} else if (action === 'uuid') {
80+
console.log(`${process.env.UUID}`);
81+
} else {
82+
console.log(version);
83+
}
84+
85+
process.exit(0);

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,21 @@
3939
"env-uuid": "npx --quiet env-cmd --no-override node obs.js uuid",
4040
"env-guid": "npx --quiet env-cmd --no-override node obs.js guid",
4141
"env-version": "node -p require('./package.json').version;"
42+
},
43+
"devDependencies": {
44+
"@rollup/plugin-commonjs": "^25.0.7",
45+
"@rollup/plugin-image": "^3.0.3",
46+
"@rollup/plugin-node-resolve": "^15.2.3",
47+
"@rollup/plugin-replace": "^5.0.5",
48+
"@rollup/plugin-terser": "^0.4.4",
49+
"@rollup/plugin-typescript": "^11.1.6",
50+
"@types/semver": "^7.5.8",
51+
"@types/uuid": "^9.0.8",
52+
"obsidian": "^1.0.0",
53+
"rollup": "^4.16.4",
54+
"semver": "^7.6.0",
55+
"uuid": "^9.0.1",
56+
"rollup-plugin-license": "^3.3.1",
57+
"all-contributors-cli": "^6.26.1"
4258
}
4359
}

0 commit comments

Comments
 (0)