Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: support rc file from npm package#252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
donaldshen wants to merge1 commit intogithub-tools:master
base:master
Choose a base branch
Loading
fromdonaldshen:feat-gren-package
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletionslib/src/_utils.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,7 @@ const Path = require('path');
const { js_beautify: beautify } = require('js-beautify');
const requireFromUrl = require('require-from-url/sync');
require('require-yaml');
const { spawnSync } = require('child_process');

/**
* Sort an object by its keys
Expand DownExpand Up@@ -307,7 +308,17 @@ function cleanConfig(confirm, path = process.cwd()) {
function getRemoteUrl(path) {
const pkgPath = Path.join(path, 'package.json');
const pkgExist = fs.existsSync(pkgPath);
const { gren = '' } = pkgExist ? require(pkgPath) : {};
if (!pkgExist) return '';
let {gren} = require(pkgPath);
if (!gren) return '';
if (!gren.startsWith('http')) {
const { stdout } = spawnSync('node', ['get-package-latest-version.js', gren], {
cwd: __dirname
});
const [errMsg, version] = JSON.parse(stdout.toString());
if (errMsg) throw new Error(errMsg);
gren = `https://cdn.jsdelivr.net/npm/${gren}@${version}/index.js`;
}
return gren;
}

Expand All@@ -316,7 +327,7 @@ function getRemoteUrl(path) {
* @since 0.18.0
* @private
*
* @param {string}path Pathwhere tolook for configfiles
* @param {string}urlwhere tofind the configfile
* @return {Object} The configuration from the first found file or empty object
*/
function getConfigFromRemote(url) {
Expand Down
19 changes: 19 additions & 0 deletionslib/src/get-package-latest-version.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
const https = require('https');

const packageName = process.argv[2];
const url = `https://registry.npmjs.org/-/package/${packageName}/dist-tags`;
https.get(url, res => {
const buffers = [];
res.on('data', (data) => {
buffers.push(data);
}).on('end', () => {
const result = [];
if (res.statusCode !== 200) {
result.push(`url: ${url}; statusCode: ${res.statusCode}`);
} else {
const { latest } = JSON.parse(Buffer.concat(buffers).toString());
result.push(null, latest);
}
process.stdout.write(JSON.stringify(result));
});
});
10 changes: 4 additions & 6 deletionstest/_utils.spec.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,16 +177,15 @@ describe('_utils.js', () => {
describe('getRemoteUrl', () => {
const filename = process.cwd() + '/test/.temp/package.json';
const fileContent = {
gren: 'testUri'
gren: '@femessage/grenrc'
};

beforeEach(() => {
fs.writeFileSync(filename, JSON.stringify(fileContent));
});

it('Shouldalwaysreturn a String', () => {
it('Should return a String', () => {
assert.isOk(typeof utils.getRemoteUrl(process.cwd() + '/test/.temp') === 'string', 'The type is a string');
assert.deepEqual(utils.getRemoteUrl(process.cwd() + '/test/.temp'), fileContent.gren, 'Given the right package path');
assert.deepEqual(utils.getRemoteUrl(process.cwd() + '/test'), '', 'Given a path with no package.json');
});

Expand All@@ -196,11 +195,10 @@ describe('_utils.js', () => {
});

describe('getConfigFromRemote', () => {
const grenRemote = 'https://raw.githubusercontent.com/FEMessage/github-release-notes/master/.grenrc.js';
const grenrc = require(process.cwd() + '/.grenrc.js');
const grenRemote = 'https://cdn.jsdelivr.net/npm/@femessage/grenrc@1.0.1/index.js';

it('Should fetch config from remote url', () => {
assert.deepEqual(utils.getConfigFromRemote(grenRemote), grenrc, 'Given a remote gren config');
assert.isOk(typeofutils.getConfigFromRemote(grenRemote) === 'object', 'Given a remote gren config');
});
});

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp